예제 #1
0
 def GenSubjectNav(self):
     subjectService = __spring__.getBean("subjectService")      
     mGradeId = subjectService.getGradeIdList()
     MetaGrade = ArrayList()
     metaSubject = ArrayList()
     for grade in mGradeId:
         mGrade = subjectService.getGrade(int(grade))
         MetaGrade.add(mGrade)
         subj = subjectService.getSubjectByGradeId(int(grade))
         m = ArrayList()
         if subj != None:
             for sj in range(0, subj.size()):
                 m.add(subj[sj].metaSubject)
             metaSubject.add({"gradeName" : mGrade.gradeName, "gradeId" : grade, "metaSubject" : m })
     map = HashMap()
     map.put("metaGrade", MetaGrade)
     map.put("meta_Grade", MetaGrade)
     map.put("SubjectNav", metaSubject)
     map.put("SiteUrl", CommonUtil.getContextUrl(request))
     
     templateProcessor = __spring__.getBean("templateProcessor")
     str = templateProcessor.processTemplate(map, "/WEB-INF/ftl/site_subject_nav.ftl", "utf-8")
     rootPath = JitarRequestContext.getRequestContext().getServletContext().getRealPath("/")
     fileIndex = rootPath + "html" + File.separator + "subject_nav.html"
     try:
         file = File(fileIndex)
         fw = OutputStreamWriter(FileOutputStream(file), "utf-8")
         # fw = FileWriter(file, False)
         fw.flush()
         fw.write(str)
         fw.close()
     finally:
         file = None
         fw = None
예제 #2
0
    def __createFromSelected(self):
        self.vc("log").debug("Creating package from selected...")
        packageType, jsonConfigFile = self.__getPackageTypeAndJsonConfigFile()
        #self.vc("log").debug("packageType = '{}'", packageType)
        #self.vc("log").debug("jsonConfigFile = '{}'", jsonConfigFile)

        # if modifying existing manifest, we already have an identifier,
        # otherwise create a new one
        manifestId = self.__getActiveManifestId()
        if manifestId is None:
            manifestHash = "%s.tfpackage" % uuid.uuid4()
        else:
            manifestHash = self.__getActiveManifestPid()

        # store the manifest file for harvesting
        packageDir = FascinatorHome.getPathFile("packages")
        packageDir.mkdirs()
        manifestFile = File(packageDir, manifestHash)
        outStream = FileOutputStream(manifestFile)
        outWriter = OutputStreamWriter(outStream, "UTF-8")
        manifest = self.__getActiveManifest()
        oldType = manifest.getType()
        if oldType is None:
            manifest.setType(packageType)
        else:
            manifest.setType(oldType)

        #self.vc("log").debug("Manifest: {}", manifest)
        outWriter.write(manifest.toString(True))
        outWriter.close()

        try:
            if manifestId is None:
                # harvest the package as an object
                username = self.vc("sessionState").get("username")
                if username is None:
                    username = "******" # necessary?
                harvester = None
                # set up config files, and make sure they are both deployed
                workflowsDir = FascinatorHome.getPathFile("harvest/workflows")
                configFile = self.__getFile(workflowsDir, jsonConfigFile)
                rulesFile = self.__getFile(workflowsDir, "packaging-rules.py")
                # run the harvest client with our packaging workflow config
                harvester = HarvestClient(configFile, manifestFile, username)
                harvester.start()
                manifestId = harvester.getUploadOid()
                harvester.shutdown()
            else:
                # update existing object
                object = StorageUtils.getDigitalObject(Services.getStorage(), manifestId)
                manifestStream = FileUtils.openInputStream(manifestFile)
                StorageUtils.createOrUpdatePayload(object, manifestHash, manifestStream)
                manifestStream.close()
                object.close()
        except Exception, ex:
            error = "Packager workflow failed: %s" % str(ex)
            log.error(error, ex)
            if harvester is not None:
                harvester.shutdown()
            return '{ "status": "failed" }'
예제 #3
0
 def process(self, inputStream, outputStream):
     try:
         self.total = 0
         reader = InputStreamReader(inputStream, "UTF-8")
         bufferedReader = BufferedReader(reader)
         writer = OutputStreamWriter(outputStream, "UTF-8")
         line = bufferedReader.readLine()
         while line != None:
             ChangedRec = line.upper()
             writer.write(ChangedRec)
             writer.write('\n')
             a = line.split(",")
             for valu in a:
                 b = valu.strip()
                 self.total += int(b)
             line = bufferedReader.readLine()
         print("Summation of Records are %s ", self.total)
         writer.flush()
         writer.close()
         reader.close()
         bufferedReader.close()
     except:
         print "Exception in Reader:"
         print '-' * 60
         traceback.print_exc(file=sys.stdout)
         print '-' * 60
         raise
         session.transfer(flowFile, ExecuteScript.REL_FAILURE)
     finally:
         if bufferedReader is not None:
             bufferedReader.close()
         if reader is not None:
             reader.close()
예제 #4
0
    def process(self, input_stream, output_stream):

        try:
            writer = OutputStreamWriter(output_stream, "UTF-8")
            reader = BufferedReader(InputStreamReader(input_stream, "UTF-8"))
            line = reader.readLine()

            found_quote_flag = False
            while line != None:

                # Write the line always
                writer.write(line)

                # If there is an odd number of double quotes (free text field)
                # then there is a newline somewhere in one of the column fields.
                # Raise the flag to not add any newlines until we've found the matching
                # line that contains an odd number of quotes
                if line.count('"') % 2 != 0:
                    found_quote_flag = not found_quote_flag

                if not found_quote_flag:
                    writer.write('\n')

                line = reader.readLine()

            writer.flush()
            writer.close()
            reader.close()

        except:
            traceback.print_exc(file=sys.stdout)
            raise
예제 #5
0
    def __createNew(self):
        self.vc("log").debug("Creating a new package...")
        packageType, jsonConfigFile = self.__getPackageTypeAndJsonConfigFile()
        self.vc("log").debug("packageType = '{}'", packageType)
        self.vc("log").debug("jsonConfigFile = '{}'", jsonConfigFile)

        manifestHash = "%s.tfpackage" % uuid.uuid4()
        # store the manifest file for harvesting
        packageDir = FascinatorHome.getPathFile("packages")
        packageDir.mkdirs()
        manifestFile = File(packageDir, manifestHash)
        outStream = FileOutputStream(manifestFile)
        outWriter = OutputStreamWriter(outStream, "UTF-8")

        self.vc("sessionState").set("package/active", None)
        manifest = self.__getActiveManifest()
        manifest.setType(packageType)
        metaList = list(self.vc("formData").getValues("metaList"))
        jsonObj = manifest.getJsonObject()
        for metaName in metaList:
            value = self.vc("formData").get(metaName)
            jsonObj.put(metaName, value)
        if self.vc("formData").getValues("sequencesMetaList") != None:    
            sequenceService = ApplicationContextProvider.getApplicationContext().getBean("sequenceService")
            sequencesMetaList = list(self.vc("formData").getValues("sequencesMetaList"))
            for sequenceInfo in sequencesMetaList:   
                sequenceInfoJson = JsonSimple(sequenceInfo)
                sequenceIndex = sequenceService.getSequence(sequenceInfoJson.getString(None,"sequenceName"))
                jsonObj.put(sequenceInfoJson.getString(None,"metadataName"), String.format(sequenceInfoJson.getString(None,"stringFormat"),sequenceIndex))
        self.vc("log").debug("json object created is: %r" % jsonObj)
        outWriter.write(manifest.toString(True))
        outWriter.close()
        # adding ability to set access plugin
        accessPlugin = self.vc("formData").get("access_plugin", "derby")
        if accessPlugin is not None:
            self.vc("page").authentication.set_access_plugin(accessPlugin)
        try:
            # harvest the package as an object
            username = self.vc("sessionState").get("username")
            if username is None:
                username = "******" # necessary?
            harvester = None
            # set up config files, creating if necessary
            workflowsDir = FascinatorHome.getPathFile("harvest/workflows")
            configFile = self.__getFile(workflowsDir, jsonConfigFile)
            self.__getFile(workflowsDir, "packaging-rules.py")
            # run the harvest client with our packaging workflow config
            harvester = HarvestClient(configFile, manifestFile, username)
            harvester.start()
            manifestId = harvester.getUploadOid()
            harvester.shutdown()
        except Exception, ex:
            error = "Packager workflow failed: %s" % str(ex)
            self.vc("log").error(error, ex)
            if harvester is not None:
                harvester.shutdown()
            return '{ "status": "failed" }'
예제 #6
0
 def saveItem(self, projectdir, itemfile):
     content = self.model.getItemContent(projectdir, itemfile)
     storagepath = itemfile.getPath()
     print storagepath
     try:
         fos = FileOutputStream(storagepath)
         osw = OutputStreamWriter(fos)
         osw.write(content, 0, len(content))
         osw.close()
         self.view.status(storagepath + " Saved")
     except FileNotFoundException, e:
         self.view.status(storagepath + " could not be opened for writing")
예제 #7
0
    def execute(self):
        if self.loginUser == None:
            return ActionResult.LOGIN

        accessControlService = __spring__.getBean("accessControlService")
        if accessControlService.isSystemAdmin(self.loginUser) == False:
            self.addActionError(u"没有管理站点配置的权限,只有超级管理员才能进行管理。")
            return ActionResult.ERROR

        strFile = request.getServletContext().getRealPath("/")
        strFile = strFile + "html" + File.separator
        strFile = URLDecoder.decode(strFile, "utf-8")
        file = File(strFile)
        if file.exists() == False:
            file.mkdirs()
        #创建学科导航
        strFile = strFile + "updateinfo.htm"
        file = File(strFile)
        if request.getMethod() == "POST":
            params = ParamUtil(request)
            html = params.safeGetStringParam("updateInfo")
            fw = OutputStreamWriter(FileOutputStream(file), "utf-8")
            fw.flush()
            fw.write(html)
            fw.close()
            siteIndexPartService = __spring__.getBean("siteIndexPartService")
            if html == "":
                siteIndexPart = siteIndexPartService.getSiteIndexPartByModuleName(
                    u"系统维护通知")
                if siteIndexPart != None:
                    siteIndexPartService.deleteSiteIndexPart(siteIndexPart)
            else:
                siteIndexPart = siteIndexPartService.getSiteIndexPartByModuleName(
                    u"系统维护通知")
                if siteIndexPart == None:
                    siteIndexPart = SiteIndexPart()
                siteIndexPart.setModuleName(u"系统维护通知")
                siteIndexPart.setModuleZone(1)
                siteIndexPart.setModuleOrder(0)
                siteIndexPart.setModuleDisplay(1)
                siteIndexPart.setModuleHeight(0)
                siteIndexPart.setContent(html)
                siteIndexPart.setPartType(100)
                siteIndexPart.setShowType(0)
                siteIndexPart.setShowBorder(0)
                siteIndexPartService.saveOrUpdateSiteIndexPart(siteIndexPart)
            request.setAttribute("deleteCache", "1")
        else:
            html = CommonUtil.readFile(file.getCanonicalPath(), "UTF-8")
            request.setAttribute("deleteCache", "0")

        request.setAttribute("updateInfo", html)
        return "/WEB-INF/ftl/admin/admin_site_update.ftl"
예제 #8
0
 def saveItem(self, projectdir, itemfile):
     content = self.model.getItemContent(projectdir,itemfile)
     storagepath = itemfile.getPath()
     print storagepath
     try:
         fos = FileOutputStream(storagepath)
         osw = OutputStreamWriter( fos )
         osw.write( content, 0, len(content) )
         osw.close()
         self.view.status(storagepath +" Saved")
     except FileNotFoundException, e:
         self.view.status(storagepath +" could not be opened for writing")
예제 #9
0
    def __createNew(self):
        print "Creating a new package..."
        packageType, jsonConfigFile = self.__getPackageTypeAndJsonConfigFile()
        print "packageType='%s'" % packageType
        print "jsonConfigFile='%s'" % jsonConfigFile

        manifestHash = "%s.tfpackage" % uuid.uuid4()
        # store the manifest file for harvesting
        packageDir = FascinatorHome.getPathFile("packages")
        packageDir.mkdirs()
        manifestFile = File(packageDir, manifestHash)
        outStream = FileOutputStream(manifestFile)
        outWriter = OutputStreamWriter(outStream, "UTF-8")

        self.vc("sessionState").set("package/active", None)
        manifest = self.__getActiveManifest()
        manifest.set("packageType", packageType)
        metaList = list(self.vc("formData").getValues("metaList"))
        for metaName in metaList:
            value = self.vc("formData").get(metaName)
            manifest.set(metaName, value)
        #
        print "------"
        print manifest
        print "------"
        manifest.store(outWriter, True)
        outWriter.close()

        try:
            # harvest the package as an object
            username = self.vc("sessionState").get("username")
            if username is None:
                username = "******" # necessary?
            harvester = None
            # set up config files, creating if necessary
            workflowsDir = FascinatorHome.getPathFile("harvest/workflows")
            configFile = self.__getFile(workflowsDir, jsonConfigFile)
            self.__getFile(workflowsDir, "packaging-rules.py")
            # run the harvest client with our packaging workflow config
            harvester = HarvestClient(configFile, manifestFile, username)
            harvester.start()
            manifestId = harvester.getUploadOid()
            harvester.shutdown()
        except Exception, ex:
            error = "Packager workflow failed: %s" % str(ex)
            log.error(error, ex)
            if harvester is not None:
                harvester.shutdown()
            return '{ status: "failed" }'
예제 #10
0
    def _setSettings(self, path, value):

        newFilePath = self._getUserSettingsFilePath(uuid.uuid1())
        stringWriter = OutputStreamWriter(FileOutputStream(newFilePath), "UTF8")
        xmlWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(stringWriter)

        result = self._createReader(path, value, xmlWriter)

        xmlWriter.close()
        stringWriter.close()

        os.rename(self._getUserSettingsFilePath(), self._getUserSettingsFilePath('_old'))
        os.rename(newFilePath, self._getUserSettingsFilePath())
        os.remove(self._getUserSettingsFilePath('_old'))

        return result
예제 #11
0
    def test_calc_blob(self):
        cursor = tBlobCursor(self.context)
        cursor.deleteAll()

        cursor.insert()
        cursor.get(1)

        self.assertEquals(1, cursor.id)
        self.assertEquals(None, cursor.dat)

        cursor.calcdat()

        self.assertTrue(cursor.dat and cursor.dat.isNull())

        os = cursor.dat.getOutStream()
        osw = OutputStreamWriter(os, 'utf-8')
        try:
            osw.append('blob field')
        finally:
            osw.close()

        cursor.update()
        cursor.clear()
        cursor.get(1)
        cursor.calcdat()
        bf = BufferedReader(
            InputStreamReader(cursor.dat.getInStream(), 'utf-8'))
        self.assertEquals('blob field', bf.readLine())
        bf.close()

        cursor.clear()
        cursor.calcdat()
        os = cursor.dat.getOutStream()
        osw = OutputStreamWriter(os, 'utf-8')
        try:
            osw.append('blob field 2!')
        finally:
            osw.close()
        cursor.insert()

        cursor.clear()
        cursor.get(2)
        cursor.calcdat()
        bf = BufferedReader(
            InputStreamReader(cursor.dat.getInStream(), 'utf-8'))
        self.assertEquals('blob field 2!', bf.readLine())
        bf.close()
예제 #12
0
 def __createFromSelected(self):
     print "Creating package from selected..."
     
     # if modifying existing manifest, we already have an identifier,
     # otherwise create a new one
     manifestId = self.__getActiveManifestId()
     if manifestId is None:
         manifestHash = "%s.tfpackage" % uuid.uuid4()
     else:
         manifestHash = self.__getActiveManifestPid()
     
     # store the manifest file for harvesting
     packageDir = FascinatorHome.getPathFile("packages")
     packageDir.mkdirs()
     manifestFile = File(packageDir, manifestHash)
     outStream = FileOutputStream(manifestFile)
     outWriter = OutputStreamWriter(outStream, "UTF-8")
     manifest = self.__getActiveManifest()
     manifest.store(outWriter, True)
     outWriter.close()
     
     try:
         if manifestId is None:
             # harvest the package as an object
             username = sessionState.get("username")
             if username is None:
                 username = "******" # necessary?
             harvester = None
             # set up config files if necessary
             workflowsDir = FascinatorHome.getPathFile("harvest/workflows")
             configFile = self.__getFile(workflowsDir, "packaging-config.json")
             rulesFile = self.__getFile(workflowsDir, "packaging-rules.py")
             # run the harvest client with our packaging workflow config
             harvester = HarvestClient(configFile, manifestFile, username)
             harvester.start()
             manifestId = harvester.getUploadOid()
             harvester.shutdown()
         else:
             # update existing object
             object = StorageUtils.storeFile(Services.getStorage(), manifestFile)
             object.close()
     except Exception, ex:
         error = "Packager workflow failed: %s" % str(ex)
         log.error(error, ex)
         if harvester is not None:
             harvester.shutdown()
         return '{ status: "failed" }'
예제 #13
0
 def GenSubjectNav(self):
     strFile = request.getServletContext().getRealPath("/")
     strFile = URLDecoder.decode(strFile, "utf-8")
     strSubjectFile = strFile + "html" + File.separator
     file = File(strSubjectFile)
     if file.exists() == False:
         file.mkdirs()
     #创建学科导航
     strSubjectFile = strSubjectFile + "subject_nav.html"
     file = File(strSubjectFile)
     #先得到年级
     subjectService = __spring__.getBean("subjectService")
     qry = Command(
         " SELECT DISTINCT metaGrade.gradeId FROM Subject Order By metaGrade.gradeId ASC"
     )
     mGradeId = qry.open()
     MetaGrade = ArrayList()
     metaSubject = ArrayList()
     for grade in mGradeId:
         mGrade = subjectService.getGrade(int(grade))
         MetaGrade.add(mGrade)
         subj = subjectService.getSubjectByGradeId(int(grade))
         m = ArrayList()
         if subj != None:
             for sj in range(0, subj.size()):
                 m.add(subj[sj].metaSubject)
             metaSubject.add({
                 "gradeName": mGrade.gradeName,
                 "gradeId": grade,
                 "metaSubject": m
             })
     map = HashMap()
     map.put("metaGrade", MetaGrade)
     map.put("meta_Grade", MetaGrade)
     map.put("SubjectNav", metaSubject)
     templateProcessor = __spring__.getBean("templateProcessor")
     str = templateProcessor.processTemplate(
         map, "/WEB-INF/ftl/site_subject_nav.ftl", "utf-8")
     try:
         fw = OutputStreamWriter(FileOutputStream(file), "utf-8")
         fw.flush()
         fw.write(str)
         fw.close()
     finally:
         file = None
         fw = None
예제 #14
0
 def save(self, parent, format):
     chooser = JFileChooser()
     # filter = FileNameExtensionFilter(
     #     format + " files",
     #     array([format, format.lower()], String))
     # chooser.setFileFilter(filter);
     returnVal = chooser.showSaveDialog(parent)
     if returnVal == JFileChooser.APPROVE_OPTION:
         fileName = chooser.getSelectedFile().getPath()
         if not fileName.upper().endswith('.' + format):
             fileName += '.' + format.lower()
         file = File(fileName)
     else:
         return
     if format == 'PNG':
         ChartUtils.saveChartAsPNG(file, self.chart, self.exportX,
                                   self.exportY)
     elif format == 'SVG':
         domImpl = GenericDOMImplementation.getDOMImplementation()
         doc = domImpl.createDocument(None, "svg", None)
         svgGen = SVGGraphics2D(doc)
         svgGen.getGeneratorContext().setPrecision(6)
         self.chart.draw(
             svgGen, Rectangle2D.Double(0, 0, self.exportX, self.exportY),
             None)
         out = OutputStreamWriter(FileOutputStream(file), "UTF-8")
         svgGen.stream(out, True)  #True is for useCSS
         out.close()
     elif format == 'PDF':
         mapper = DefaultFontMapper()
         pageSize = Rectangle(self.exportX, self.exportY)
         doc = TextDocument(pageSize, 50, 50, 50, 50)
         out = BufferedOutputStream(FileOutputStream(file))
         writer = PdfWriter.getInstance(doc, out)
         doc.open()
         cb = writer.getDirectContent()
         tp = cb.createTemplate(self.exportX, self.exportY)
         g2 = tp.createGraphics(self.exportX, self.exportY, mapper)
         r2D = Rectangle2D.Double(0, 0, self.exportX, self.exportY)
         self.chart.draw(g2, r2D)
         g2.dispose()
         cb.addTemplate(tp, 0, 0)
         doc.close()
예제 #15
0
파일: Chart.py 프로젝트: samitha/lositan
 def save(self, parent, format):
     chooser = JFileChooser()
     #filter = FileNameExtensionFilter(
     #    format + " files",
     #    array([format, format.lower()], String))
     #chooser.setFileFilter(filter);
     returnVal = chooser.showSaveDialog(parent)
     if returnVal == JFileChooser.APPROVE_OPTION:
         fileName = chooser.getSelectedFile().getPath()
         if not fileName.upper().endswith('.' + format):
             fileName += '.' + format.lower()
         file = File(fileName)
     else:
         return
     if format == 'PNG':
         ChartUtilities.saveChartAsPNG(file, self.chart, self.exportX, self.exportY)
     elif format == 'SVG':
         domImpl = GenericDOMImplementation.getDOMImplementation()
         doc = domImpl.createDocument(None, "svg", None)
         svgGen = SVGGraphics2D(doc)
         svgGen.getGeneratorContext().setPrecision(6)
         self.chart.draw(svgGen,
            Rectangle2D.Double(0, 0, self.exportX, self.exportY), None)
         out = OutputStreamWriter(FileOutputStream(file), "UTF-8")
         svgGen.stream(out, True) #True is for useCSS
         out.close()
     elif format == 'PDF':
         mapper = DefaultFontMapper()
         pageSize = Rectangle(self.exportX, self.exportY)
         doc = TextDocument(pageSize, 50, 50, 50, 50)
         out = BufferedOutputStream(FileOutputStream(file))
         writer = PdfWriter.getInstance(doc, out)
         doc.open()
         cb = writer.getDirectContent()
         tp = cb.createTemplate(self.exportX, self.exportY)
         g2 = tp.createGraphics(self.exportX, self.exportY, mapper)
         r2D = Rectangle2D.Double(0, 0, self.exportX, self.exportY)
         self.chart.draw(g2, r2D)
         g2.dispose()
         cb.addTemplate(tp, 0, 0)
         doc.close()
예제 #16
0
 def create_subject_nav(self):
     subjectService = __spring__.getBean("subjectService")
     qry = Command(" SELECT DISTINCT metaGrade.gradeId FROM Subject Order By metaGrade.gradeId ASC") 
     mGradeId = qry.open()
     MetaGrade = ArrayList()
     metaSubject = ArrayList()
     for grade in mGradeId:
         mGrade = subjectService.getGrade(int(grade))
         MetaGrade.add(mGrade)
         subj = subjectService.getSubjectByGradeId(int(grade))
         m = ArrayList()
         if subj != None:
             for sj in range(0, subj.size()):
                 m.add(subj[sj].metaSubject)
             metaSubject.add({"gradeName" : mGrade.gradeName, "gradeId" : grade, "metaSubject" : m })
     map = HashMap()
     map.put("metaGrade", MetaGrade)
     map.put("meta_Grade", MetaGrade)
     map.put("SubjectNav", metaSubject)
     map.put("SiteUrl", request.getContextPath() + "/")
     
     templateProcessor = __spring__.getBean("templateProcessor")
     str = templateProcessor.processTemplate(map, "/WEB-INF/ftl/site_subject_nav.ftl", "utf-8")
     rootPath = JitarRequestContext.getRequestContext().getServletContext().getRealPath("/")
     fileIndex = rootPath + "html" + File.separator + "subject_nav.html"
     try:
         file = File(fileIndex)
         fw = OutputStreamWriter(FileOutputStream(file), "utf-8")
         #fw = FileWriter(file, False)
         fw.flush()
         fw.write(str)
         fw.close()
     finally:
         file = None
         fw = None
     request.setAttribute("errorMessage", u"生成学科导航缓存文件完毕!")
예제 #17
0
파일: index.py 프로젝트: yxxcrtd/jitar2.0
 def GenSubjectNav(self, strPath):
     # 先得到年级
     subjectService = __spring__.getBean("subjectService")
     mGradeId = subjectService.getGradeIdList()
     MetaGrade = ArrayList()
     metaSubject = ArrayList()
     for grade in mGradeId:
         mGrade = subjectService.getGrade(int(grade))
         MetaGrade.add(mGrade)
         subj = subjectService.getSubjectByGradeId(int(grade))
         m = ArrayList()
         if subj != None:
             for sj in range(0, subj.size()):
                 m.add(subj[sj].metaSubject)
             metaSubject.add({
                 "gradeName": mGrade.gradeName,
                 "gradeId": grade,
                 "metaSubject": m
             })
     map = HashMap()
     map.put("metaGrade", MetaGrade)
     map.put("meta_Grade", MetaGrade)
     map.put("SubjectNav", metaSubject)
     map.put("SiteUrl", self.get_context_url())
     templateProcessor = __spring__.getBean("templateProcessor")
     str = templateProcessor.processTemplate(
         map, "/WEB-INF/ftl/site_subject_nav.ftl", "utf-8")
     try:
         file = File(strPath)
         fw = OutputStreamWriter(FileOutputStream(file), "utf-8")
         fw.flush()
         fw.write(str)
         fw.close()
     finally:
         file = None
         fw = None
예제 #18
0
파일: test.py 프로젝트: anukat2015/ontopia
from net.ontopia.persistence.rdbms import DatabaseProjectReader, GenericSQLProducer
from java.lang import System
from java.io import OutputStreamWriter

dbreader = DatabaseProjectReader()
project = dbreader.loadProject("file:/ontopia/src/java/net/ontopia/topicmaps/impl/proxy/schema/TopicMaps.xml")

producer = GenericSQLProducer(project)
writer = OutputStreamWriter(System.out)
producer.produceCreate(writer);
producer.produceDrop(writer);
writer.close()

예제 #19
0
from net.ontopia.persistence.rdbms import DatabaseProjectReader, GenericSQLProducer
from java.lang import System
from java.io import OutputStreamWriter

dbreader = DatabaseProjectReader()
project = dbreader.loadProject(
    "file:/ontopia/src/java/net/ontopia/topicmaps/impl/proxy/schema/TopicMaps.xml"
)

producer = GenericSQLProducer(project)
writer = OutputStreamWriter(System.out)
producer.produceCreate(writer)
producer.produceDrop(writer)
writer.close()
예제 #20
0
    def __createFromSelected(self):
        self.vc("log").debug("Creating package from selected...")
        packageType, jsonConfigFile = self.__getPackageTypeAndJsonConfigFile()
        #self.vc("log").debug("packageType = '{}'", packageType)
        #self.vc("log").debug("jsonConfigFile = '{}'", jsonConfigFile)

        # if modifying existing manifest, we already have an identifier,
        # otherwise create a new one
        manifestId = self.__getActiveManifestId()
        if manifestId is None:
            manifestHash = "%s.tfpackage" % uuid.uuid4()
        else:
            manifestHash = self.__getActiveManifestPid()

        # store the manifest file for harvesting
        packageDir = FascinatorHome.getPathFile("packages")
        packageDir.mkdirs()
        manifestFile = File(packageDir, manifestHash)
        outStream = FileOutputStream(manifestFile)
        outWriter = OutputStreamWriter(outStream, "UTF-8")
        manifest = self.__getActiveManifest()
        oldType = manifest.getType()
        if oldType is None:
            manifest.setType(packageType)
        else:
            manifest.setType(oldType)

        self.vc("log").debug("Manifest: %s" % manifest)
        outWriter.write(manifest.toString(True))
        outWriter.close()

        try:
            if manifestId is None:
                # harvest the package as an object
                username = self.vc("sessionState").get("username")
                if username is None:
                    username = "******"  # necessary?
                harvester = None
                # set up config files, and make sure they are both deployed
                workflowsDir = FascinatorHome.getPathFile("harvest/workflows")
                configFile = self.__getFile(workflowsDir, jsonConfigFile)
                rulesFile = self.__getFile(workflowsDir, "packaging-rules.py")
                # run the harvest client with our packaging workflow config
                harvester = HarvestClient(configFile, manifestFile, username)
                harvester.start()
                manifestId = harvester.getUploadOid()
                harvester.shutdown()
            else:
                # update existing object
                object = StorageUtils.getDigitalObject(Services.getStorage(),
                                                       manifestId)
                manifestStream = FileUtils.openInputStream(manifestFile)
                StorageUtils.createOrUpdatePayload(object, manifestHash,
                                                   manifestStream)
                manifestStream.close()
                object.close()
        except Exception, ex:
            error = "Packager workflow failed: %s" % str(ex)
            self.vc("log").error(error, ex)
            if harvester is not None:
                harvester.shutdown()
            return '{ "status": "failed" }'
예제 #21
0
    def __createNew(self):
        self.vc("log").debug("Creating a new package...")
        packageType, jsonConfigFile = self.__getPackageTypeAndJsonConfigFile()
        self.vc("log").debug("packageType = '{}'", packageType)
        self.vc("log").debug("jsonConfigFile = '{}'", jsonConfigFile)

        manifestHash = "%s.tfpackage" % uuid.uuid4()
        # store the manifest file for harvesting
        packageDir = FascinatorHome.getPathFile("packages")
        packageDir.mkdirs()
        manifestFile = File(packageDir, manifestHash)
        outStream = FileOutputStream(manifestFile)
        outWriter = OutputStreamWriter(outStream, "UTF-8")

        self.vc("sessionState").set("package/active", None)
        manifest = self.__getActiveManifest()
        manifest.setType(packageType)
        metaList = list(self.vc("formData").getValues("metaList"))
        jsonObj = manifest.getJsonObject()
        for metaName in metaList:
            value = self.vc("formData").get(metaName)
            jsonObj.put(metaName, value)
        if self.vc("formData").getValues("sequencesMetaList") != None:
            sequenceService = ApplicationContextProvider.getApplicationContext(
            ).getBean("sequenceService")
            sequencesMetaList = list(
                self.vc("formData").getValues("sequencesMetaList"))
            for sequenceInfo in sequencesMetaList:
                sequenceInfoJson = JsonSimple(sequenceInfo)
                sequenceIndex = sequenceService.getSequence(
                    sequenceInfoJson.getString(None, "sequenceName"))
                jsonObj.put(
                    sequenceInfoJson.getString(None, "metadataName"),
                    String.format(
                        sequenceInfoJson.getString(None, "stringFormat"),
                        sequenceIndex))
        self.vc("log").debug("json object created is: %r" % jsonObj)
        outWriter.write(manifest.toString(True))
        outWriter.close()
        # adding ability to set access plugin
        accessPlugin = self.vc("formData").get("access_plugin", "derby")
        if accessPlugin is not None:
            self.vc("page").authentication.set_access_plugin(accessPlugin)
        try:
            # harvest the package as an object
            username = self.vc("sessionState").get("username")
            if username is None:
                username = "******"  # necessary?
            harvester = None
            # set up config files, creating if necessary
            workflowsDir = FascinatorHome.getPathFile("harvest/workflows")
            configFile = self.__getFile(workflowsDir, jsonConfigFile)
            self.__getFile(workflowsDir, "packaging-rules.py")
            # run the harvest client with our packaging workflow config
            harvester = HarvestClient(configFile, manifestFile, username)
            harvester.start()
            manifestId = harvester.getUploadOid()
            harvester.shutdown()
        except Exception, ex:
            error = "Packager workflow failed: %s" % str(ex)
            self.vc("log").error(error, ex)
            if harvester is not None:
                harvester.shutdown()
            return '{ "status": "failed" }'