private MongoCollection<Document> getMetadataCollection(DBKey dbKey) throws StorageException { final String dbName = MongoDBClient.getDbName(dbKey.getCompany(), dbKey.getProject()); final MongoDatabase database = client.getDatabase(dbName, true); if (database == null) { throw new StorageException( String.format("Database %s does not exist! Contact AET administrators.", dbName)); } return database.getCollection(METADATA_COLLECTION_NAME); } }
private MongoCollection<Document> getMetadataCollection(DBKey dbKey) throws StorageException { final String dbName = MongoDBClient.getDbName(dbKey.getCompany(), dbKey.getProject()); final MongoDatabase database = client.getDatabase(dbName, true); if (database == null) { throw new StorageException( String.format("Database %s does not exist! Contact AET administrators.", dbName)); } return database.getCollection(METADATA_COLLECTION_NAME); } }
/** * Updates suite in .metadata collection only if older version exist. Also updates version and * timestamp of a suite. * * @param suite new suite version to save * @return updated suite. */ @Override public Suite updateSuite(Suite suite) throws StorageException, ValidatorException { MongoCollection<Document> metadata = getMetadataCollection(new SimpleDBKey(suite)); LOGGER.debug("Updating suite {} in metadata collection.", suite); if (isNewestSuite(suite)) { suite.incrementVersion(); suite.setRunTimestamp(new Suite.Timestamp(System.currentTimeMillis())); suite.validate(null); metadata.insertOne(Document.parse(suite.toJson())); } else { throw new StorageException("Trying to update old version or not existing suite."); } return getSuite(new SimpleDBKey(suite), suite.getCorrelationId()); }
/** * Updates suite in .metadata collection only if older version exist. Also updates version and * timestamp of a suite. * * @param suite new suite version to save * @return updated suite. */ @Override public Suite updateSuite(Suite suite) throws StorageException, ValidatorException { MongoCollection<Document> metadata = getMetadataCollection(new SimpleDBKey(suite)); LOGGER.debug("Updating suite {} in metadata collection.", suite); if (isNewestSuite(suite)) { suite.incrementVersion(); suite.setRunTimestamp(new Suite.Timestamp(System.currentTimeMillis())); suite.validate(null); metadata.insertOne(Document.parse(suite.toJson())); } else { throw new StorageException("Trying to update old version or not existing suite."); } return getSuite(new SimpleDBKey(suite), suite.getCorrelationId()); }