@BeforeClass public static void setUpBeforeClass() throws Exception { setEnv(); // read configuration Configuration configuration = Configuration.getInstance(); // and initialize the db connections NdexDatabase db = NdexDatabase.createNdexDatabase( configuration.getHostURI(), configuration.getDBURL(), configuration.getDBUser(), configuration.getDBPasswd(), 10); String user = "******"; XgmmlParser parser = new XgmmlParser( "/home/chenjing/Dropbox/Network_test_files/pdmap130712.xgmml", user, db, "pdmap13", ""); parser.parseFile(); // XbelParser // parser = new XbelParser("/home/chenjing/working/ndex/networks/selventa_full.xbel", user); // parser.parseFile(); db.close(); }
/* * private method to invoke the xbel network exporter */ private void exportNetwork() throws Exception { this.taskStatus = Status.PROCESSING; this.startTask(); String exportFilename = this.resolveFilename( Configuration.getInstance().getNdexRoot() + "/exported-networks/", this.XBEL_FILE_EXTENSION); ODatabaseDocumentTx db = null; try { db = NdexDatabase.getInstance().getAConnection(); NdexTaskModelService modelService = new NdexJVMDataModelService(db); XbelNetworkExporter exporter = new XbelNetworkExporter( this.getTask().getTaskOwnerId().toString(), this.networkId, modelService, exportFilename); exporter.exportNetwork(); this.taskStatus = Status.COMPLETED; this.updateTaskStatus(this.taskStatus); } finally { if (db != null) db.close(); } }
private void createNetworkCache() throws NdexException { String networkIdStr = this.getTask().getResource(); try (NetworkDAO dao = new NetworkDAO(NdexDatabase.getInstance().getAConnection())) { Long taskCommitId = (Long) getTask().getAttribute(TaskAttribute.readOnlyCommitId); String fullpath = Configuration.getInstance().getNdexNetworkCachePath() + taskCommitId + ".gz"; ODocument d = dao.getNetworkDocByUUIDString(networkIdStr); d.reload(); Long actId = d.field(NdexClasses.Network_P_readOnlyCommitId); if (!actId.equals(taskCommitId)) { // stop task getTask() .setMessage( "Network cache not created. readOnlyCommitId=" + actId + " in db, but in task we have commitId=" + taskCommitId); return; } // create cache. Network n = dao.getNetworkById(UUID.fromString(networkIdStr)); try (GZIPOutputStream w = new GZIPOutputStream(new FileOutputStream(fullpath), 16384)) { // String s = mapper.writeValueAsString( original); ObjectMapper mapper = new ObjectMapper(); mapper.writeValue(w, n); } catch (FileNotFoundException e) { throw new NdexException("Can't create network cache file in server: " + fullpath); } catch (IOException e) { throw new NdexException( "IO Error when writing cache file: " + fullpath + ". Cause: " + e.getMessage()); } // check again. d.reload(); actId = d.field(NdexClasses.Network_P_readOnlyCommitId); if (!actId.equals(taskCommitId)) { // stop task getTask() .setMessage( "Network cache not created. Second check found network readOnlyCommitId is" + actId + ", task has commitId " + taskCommitId); return; } d.field(NdexClasses.Network_P_cacheId, taskCommitId).save(); logger.info("Cache " + actId + " created."); dao.commit(); } }