Java Code Examples for com.orientechnologies.orient.core.record.impl.ODocument#field()

The following examples show how to use com.orientechnologies.orient.core.record.impl.ODocument#field() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OrientConfigurationEntityAdapter.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Nullable
@Override
public EntityEvent newEvent(final ODocument document, final EventKind eventKind) {
  final EntityMetadata metadata = new AttachedEntityMetadata(this, document);
  final String repositoryName = document.field(P_REPOSITORY_NAME);

  log.trace("newEvent: eventKind: {}, repositoryName: {}, metadata: {}", eventKind, repositoryName, metadata);
  switch (eventKind) {
    case CREATE:
      return new OrientConfigurationCreatedEvent(metadata, repositoryName);
    case UPDATE:
      return new OrientConfigurationUpdatedEvent(metadata, repositoryName);
    case DELETE:
      return new OrientConfigurationDeletedEvent(metadata, repositoryName);
    default:
      return null;
  }
}
 
Example 2
Source File: ReleaseODocumentCommand.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
@Override
	protected void performMultiAction(AjaxRequestTarget target, List<ODocument> objects) {
		if(objects==null || objects.isEmpty()) return;
		ODocument doc = documentModel.getObject();
		if(doc!=null)
		{
			OProperty property = propertyModel.getObject();
			if(property!=null)
			{
				Collection<ODocument> collection = doc.field(property.getName());
				if(collection!=null) {
					for (ODocument oDocument : objects)
					{
						collection.remove(oDocument);
					}
//					collection.removeAll(objects);
//					doc.field(property.getName(), collection);
					doc.save();
				}
			}
		}
	}
 
Example 3
Source File: AssetEntityAdapter.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public EntityEvent newEvent(final ODocument document, final EventKind eventKind) {
  EntityMetadata metadata = new AttachedEntityMetadata(this, document);

  String repositoryName = ((ODocument) document.field(P_BUCKET)).field(P_REPOSITORY_NAME);

  ORID rid = document.field(P_COMPONENT, ORID.class);
  EntityId componentId = rid != null ? new AttachedEntityId(componentEntityAdapter, rid) : null;

  switch (eventKind) {
    case CREATE:
      return new AssetCreatedEvent(metadata, repositoryName, componentId);
    case UPDATE:
      return new AssetUpdatedEvent(metadata, repositoryName, componentId);
    case DELETE:
      return new AssetDeletedEvent(metadata, repositoryName, componentId);
    default:
      return null;
  }
}
 
Example 4
Source File: LuceneInsertReadMultithreadTest.java    From orientdb-lucene with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {

  db = new ODatabaseDocumentTx(url);
  db.open("admin", "admin");
  db.declareIntent(new OIntentMassiveInsert());
  db.begin();
  for (int i = 0; i < cycle; i++) {
    ODocument doc = new ODocument("City");

    doc.field("name", "Rome");

    db.save(doc);
    if (i % commitBuf == 0) {
      db.commit();
      db.begin();
    }

  }

  db.close();
}
 
Example 5
Source File: OrientDBDocumentAPILiveTest.java    From tutorials with MIT License 6 votes vote down vote up
public void givenDB_whenSavingAuthors_thenWeGetOnesWithLevelSeven() {
    for (ODocument author : db.browseClass("Author")) author.delete();

    ODocument authorOne = new ODocument("Author");
    authorOne.field("firstName", "Leo");
    authorOne.field("level", 7);
    authorOne.save();

    ODocument authorTwo = new ODocument("Author");
    authorTwo.field("firstName", "Lucien");
    authorTwo.field("level", 9);
    authorTwo.save();

    List<ODocument> result = db.query(
        new OSQLSynchQuery<ODocument>("select * from Author where level = 7"));

    assertEquals(1, result.size());
}
 
Example 6
Source File: LegacyKeyStoreUpgradeService.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
public void importKeyStoreFiles() throws Exception {
  log.debug("Importing legacy trust store from {}", keyStoreBasedir);
  try (ODatabaseDocumentTx db = databaseInstance.get().connect()) {
    for (String filename : Arrays.asList(TRUSTED_KEYS_FILENAME, PRIVATE_KEYS_FILENAME)) {
      String keyStoreName = "ssl/" + filename;
      String query = "SELECT FROM " + DB_CLASS + " WHERE " + P_NAME + " = ?";
      List<ODocument> results = db.command(new OSQLSynchQuery<>(query)).execute(keyStoreName);
      if (!results.isEmpty()) {
        log.debug("Skipped import of existing legacy key store {}", results.get(0));
        // NOTE: Upgrade steps run on each node but within a cluster, another node might already have upgraded the db
        continue;
      }
      Path keyStorePath = keyStoreBasedir.resolve(filename);
      if (!Files.isRegularFile(keyStorePath)) {
        continue;
      }
      ODocument doc = db.newInstance(DB_CLASS);
      doc.field(P_NAME, keyStoreName);
      doc.field(P_BYTES, Files.readAllBytes(keyStorePath));
      doc.save();
      log.debug("Imported legacy key store {}", doc);
    }
  }
}
 
Example 7
Source File: OrienteerUsersModule.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
private void updateOrienteerUserRoleDoc(ODatabaseDocument db, ODocument perspective) {
    OSecurity security = db.getMetadata().getSecurity();
    ORole role = security.getRole(ORIENTEER_USER_ROLE);
    if (role == null) {
        ORole reader = security.getRole("reader");
        role = security.createRole(ORIENTEER_USER_ROLE, reader, OSecurityRole.ALLOW_MODES.DENY_ALL_BUT);
    }

    role.grant(ResourceGeneric.CLASS, OWidgetsModule.OCLASS_WIDGET, READ.getPermissionFlag());
    role.grant(ResourceGeneric.CLASS, OWidgetsModule.OCLASS_DASHBOARD, READ.getPermissionFlag());

    // TODO: remove this after release with fix for roles in OrientDB: https://github.com/orientechnologies/orientdb/issues/8338
    role.grant(ResourceGeneric.CLASS, PerspectivesModule.OPerspectiveItem.CLASS_NAME, READ.getPermissionFlag());
    role.grant(ResourceGeneric.CLASS, PerspectivesModule.OPerspective.CLASS_NAME, READ.getPermissionFlag());
    role.grant(ResourceGeneric.CLASS, ORole.CLASS_NAME, READ.getPermissionFlag());
    role.grant(ResourceGeneric.SCHEMA, null, READ.getPermissionFlag());
    role.grant(ResourceGeneric.CLUSTER, "internal", READ.getPermissionFlag());
    role.grant(ResourceGeneric.RECORD_HOOK, "", READ.getPermissionFlag());
    role.grant(ResourceGeneric.DATABASE, null, READ.getPermissionFlag());
    role.grant(ResourceGeneric.DATABASE, "systemclusters", READ.getPermissionFlag());
    role.grant(ResourceGeneric.DATABASE, "function", READ.getPermissionFlag());
    role.grant(ResourceGeneric.DATABASE, "command", READ.getPermissionFlag());

    role.grant(OSecurityHelper.FEATURE_RESOURCE, SearchPage.SEARCH_FEATURE, READ.getPermissionFlag());

    role.grant(ResourceGeneric.CLASS, OrienteerUser.CLASS_NAME, OrientPermission.combinedPermission(READ, UPDATE));
    role.grant(ResourceGeneric.CLASS, OUserSocialNetwork.CLASS_NAME, 11);
    role.grant(ResourceGeneric.DATABASE, "cluster", OrientPermission.combinedPermission(READ, UPDATE));

    role.getDocument().field(ORestrictedOperation.ALLOW_READ.getFieldName(), Collections.singletonList(role.getDocument()));
    role.getDocument().field(PerspectivesModule.PROP_PERSPECTIVE, perspective);
    role.save();

    perspective.field(ORestrictedOperation.ALLOW_READ.getFieldName(), Collections.singletonList(role.getDocument()));
    perspective.save();
}
 
Example 8
Source File: OUsersCommonUtils.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
public static void createWidgetIfNotExists(ODatabaseDocument db, String typeId, String className, String domain, String tab) {
    ODocument dashboard = getOrCreateDashboard(db, className, domain, tab);
    if (!isWidgetExists(dashboard, typeId)) {
        ODocument doc = new ODocument(OCLASS_WIDGET);
        doc.field(OPROPERTY_TYPE_ID, typeId);
        doc.field(OPROPERTY_DASHBOARD, dashboard);
        doc.save();
    }
}
 
Example 9
Source File: MavenIndexPublisher.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Converts orient SQL query result into Maven Indexer Reader {@link Record}. Should be invoked only with documents
 * belonging to components, but not checksums or signatures.
 */
private static Record toRecord(final MavenFacet mavenFacet, final ODocument document) {
  checkNotNull(document); // sanity
  final String path = document.field("path", String.class);
  MavenPath mavenPath = mavenFacet.getMavenPathParser().parsePath(path);
  checkArgument(mavenPath.getCoordinates() != null && !mavenPath.isSubordinate()); // otherwise query is wrong

  Record record = new Record(Type.ARTIFACT_ADD, new HashMap<>());
  record.put(Record.REC_MODIFIED, document.field("lastModified", Long.class));
  record.put(Record.GROUP_ID, document.field("groupId", String.class));
  record.put(Record.ARTIFACT_ID, document.field("artifactId", String.class));
  record.put(Record.VERSION, document.field("version", String.class));
  record.put(Record.CLASSIFIER, document.field("classifier", String.class));

  String packaging = document.field("packaging", String.class);
  if (packaging != null) {
    record.put(Record.PACKAGING, packaging);
  }
  else {
    record.put(Record.PACKAGING, pathExtension(mavenPath.getFileName()));
  }
  record.put(Record.NAME, defStr(document.field("pom_name", String.class), ""));
  record.put(Record.DESCRIPTION, defStr(document.field("pom_description", String.class), ""));

  checkExistence(record, Record.HAS_SOURCES, mavenPath.locate("jar", "sources"), mavenFacet);
  checkExistence(record, Record.HAS_JAVADOC, mavenPath.locate("jar", "javadoc"), mavenFacet);
  checkExistence(record, Record.HAS_SIGNATURE, mavenPath.signature(SignatureType.GPG), mavenFacet);

  record.put(Record.FILE_EXTENSION, pathExtension(mavenPath.getFileName()));
  record.put(Record.FILE_MODIFIED, document.field("contentLastModified", Long.class));
  record.put(Record.FILE_SIZE, document.field("contentSize", Long.class));
  record.put(Record.SHA1, document.field("sha1", String.class));
  return record;
}
 
Example 10
Source File: HooksTest.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Test
@Sudo
public void testCallbackHook() throws Exception {
	ODatabaseDocument db = OrientDbWebSession.get().getDatabase();
	OSchema schema = db.getMetadata().getSchema();
	OClass oClass = schema.createClass(TEST_CLASS_CALLBACK);
	oClass.createProperty("name", OType.STRING);
	try {
		ODocument doc = new ODocument(oClass);
		doc.field("name", "testname");
		TestCallback callback = new TestCallback();
		CallbackHook.registerCallback(doc, TYPE.AFTER_CREATE, callback);
		CallbackHook.registerCallback(doc, TYPE.BEFORE_CREATE, callback);
		doc.save();
		assertEquals("executed", doc.field("callback"+TYPE.AFTER_CREATE));
		assertEquals("executed", doc.field("callback"+TYPE.BEFORE_CREATE));
		assertFalse(doc.containsField("__callbacks__"));
		doc.reload();
		assertFalse(doc.containsField("__callbacks__"));
		assertFalse(doc.containsField("callback"+TYPE.AFTER_READ)); 
		CallbackHook.registerCallback(doc, TYPE.AFTER_READ, callback);
		doc.reload();
		assertEquals("executed", doc.field("callback"+TYPE.AFTER_READ));
	} finally {
		schema.dropClass(TEST_CLASS_CALLBACK);
	}
}
 
Example 11
Source File: OrienteerUserHook.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
private void updateAllowPermissions(String field, ODocument user) {
    List<ODocument> allows = user.field(field, List.class);
    if (allows == null) {
        allows = new LinkedList<>();
    } else allows = new LinkedList<>(allows);

    allows.add(user);
    user.field(field, allows);
}
 
Example 12
Source File: OTasksTest.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Test
@Ignore
public void consoleTaskTest() throws Exception{
	assertTrue(OrientDbWebSession.get().signIn("admin", "admin"));
	ODatabaseDocument db = OrientDbWebSession.get().getDatabase();
	assertFalse(db.isClosed());
	db.commit();
	try
	{
		ODocument taskDocument = new ODocument(OConsoleTask.TASK_CLASS);
		taskDocument.field(OTask.Field.AUTODELETE_SESSIONS.fieldName(),false);
		taskDocument.field(OConsoleTask.Field.INPUT.fieldName(),CONSOLE_TEST_COMMAND);
		taskDocument.save();
		db.commit();
		OTask task = OTask.makeFromODocument(taskDocument);

		ODocument taskDocumentAD = new ODocument(OConsoleTask.TASK_CLASS);
		taskDocumentAD.field(OTask.Field.AUTODELETE_SESSIONS.fieldName(),true);
		taskDocumentAD.field(OConsoleTask.Field.INPUT.fieldName(),CONSOLE_TEST_COMMAND);
		taskDocumentAD.save();
		db.commit();
		OTask taskAD = OTask.makeFromODocument(taskDocumentAD);
		
		OTaskSessionRuntime taskSession = task.startNewSession();
		OTaskSessionRuntime taskSessionAD = taskAD.startNewSession();
		Thread.sleep(CONSOLE_TASK_DELAY);
		db.commit();
		ODocument taskSessionDoc = taskSession.getOTaskSessionPersisted().getDocument();
		taskSessionDoc.load();
		assertNull(taskSessionDoc.field(ITaskSession.Field.ERROR.fieldName()));
		assertNotNull(taskSessionDoc.field(ITaskSession.Field.FINISH_TIMESTAMP.fieldName()));
		assertEquals(12L, (Object) taskSessionDoc.field(ITaskSession.Field.PROGRESS_CURRENT.fieldName()));
		assertEquals(ITaskSession.Status.INTERRUPTED,taskSession.getStatus());
	} finally
	{
		OrientDbWebSession.get().signOut();
	}
}
 
Example 13
Source File: AbstractPivotTableWidget.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
public void loadSettings() {
	super.loadSettings();
	ODocument doc = getWidgetDocument();
	if(doc==null) return;
	config = doc.field(PivotTableModule.OPROPERTY_PIVOT_TABLE_CONFIG);
	customSQL = doc.field(PivotTableModule.OPROPERTY_PIVOT_CUSTOM_SQL);
}
 
Example 14
Source File: RandomExtractor.java    From orientdb-etl with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(OETLProcessor iProcessor, ODocument iConfiguration, OCommandContext iContext) {
  super.configure(iProcessor, iConfiguration, iContext);

  if (iConfiguration.containsField("items"))
    items = ((Number) iConfiguration.field("items")).longValue();
  if (iConfiguration.containsField("fields"))
    fields = iConfiguration.field("fields");
  if (iConfiguration.containsField("delay"))
    delay = iConfiguration.field("delay");
}
 
Example 15
Source File: BisonProjectMapping.java    From rtc2jira with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void afterWorkItem(ODocument doc) {
  if (value != null && !value.isEmpty()) {
    doc.field(FieldNames.BISON_PROJECT_NAME, value);
  }
}
 
Example 16
Source File: SeverityMapping.java    From rtc2jira with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void afterWorkItem(ODocument doc) {
  if (value != null) {
    doc.field(FieldNames.SEVERITY, value);
  }
}
 
Example 17
Source File: SubscriptionsMapping.java    From rtc2jira with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void afterWorkItem(ODocument doc) {
  if (subscriptions != null && !subscriptions.isEmpty()) {
    doc.field(FieldNames.SUBSCRIPTIONS, subscriptions);
  }
}
 
Example 18
Source File: CategoryMapping.java    From rtc2jira with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void afterWorkItem(ODocument doc) {
  doc.field(FieldNames.CATEGORY, value);
}
 
Example 19
Source File: BpmnPanel.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
@Override
public void setObject(String object) {
	super.setObject(object);
	ODocument resource = BpmnPanel.this.getModelObject();
	if(resource!=null) resource.field("bytes", object.getBytes());
}
 
Example 20
Source File: LuceneCreateIndexRemote.java    From orientdb-lucene with Apache License 2.0 3 votes vote down vote up
@Override
public void loadAndTest() {
  InputStream stream = ClassLoader.getSystemResourceAsStream("testLuceneIndex.sql");

  databaseDocumentTx.command(new OCommandScript("sql", getScriptFromStream(stream))).execute();

  databaseDocumentTx.command(new OCommandSQL("create index Song.title on Song (title) FULLTEXT ENGINE LUCENE")).execute();
  databaseDocumentTx.command(new OCommandSQL("create index Song.author on Song (author) FULLTEXT ENGINE LUCENE")).execute();

  assertQuery();

  restart();

  assertQuery();

  ODocument doc = new ODocument("Song");

  doc.field("title", "Test");
  doc.field("author", "Author");

  databaseDocumentTx.save(doc);

  assertNewQuery();

  restart();

  assertNewQuery();

}