Java Code Examples for com.orientechnologies.orient.core.db.record.OIdentifiable#getRecord()

The following examples show how to use com.orientechnologies.orient.core.db.record.OIdentifiable#getRecord() . 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: OLuceneTextOperator.java    From orientdb-lucene with Apache License 2.0 6 votes vote down vote up
protected OLuceneFullTextIndex involvedIndex(OIdentifiable iRecord, ODocument iCurrentResult, OSQLFilterCondition iCondition,
    Object iLeft, Object iRight) {

  ODocument doc = iRecord.getRecord();
  Set<OIndex<?>> classInvolvedIndexes = getDatabase().getMetadata().getIndexManager()
      .getClassInvolvedIndexes(doc.getClassName(), fields(iCondition));

  OLuceneFullTextIndex idx = null;
  for (OIndex<?> classInvolvedIndex : classInvolvedIndexes) {

    if (classInvolvedIndex.getInternal() instanceof OLuceneFullTextIndex) {
      idx = (OLuceneFullTextIndex) classInvolvedIndex.getInternal();
      break;
    }
  }
  return idx;
}
 
Example 2
Source File: EntityAdapter.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Read entity from document.
 */
public T readEntity(final OIdentifiable identifiable) {
  ODocument document = identifiable.getRecord(); // no-op if it's already a document
  checkNotNull(document);

  T entity = newEntity();
  if (!partialLoading) {
    document.deserializeFields();
  }
  try {
    readFields(document, entity);
  }
  catch (Exception e) {
    Throwables.throwIfUnchecked(e);
    throw new RuntimeException(e);
  }
  attachMetadata(entity, document);

  return entity;
}
 
Example 3
Source File: ODocumentNameModel.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
protected String load() {
	OIdentifiable id = documentModel!=null?documentModel.getObject():null;
	ORecord doc = id!=null?id.getRecord():null;
	return doc!=null && doc instanceof ODocument
			?OrienteerWebApplication.get().getOClassIntrospector()
					.getDocumentName((ODocument)doc, namePropertyModel!=null?namePropertyModel.getObject():null)
			:null;
}
 
Example 4
Source File: AbstractEntityHandler.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
public ODocument readAsDocument(String id, OPersistenceSession session) {
	String oid = (String) convertValueFromEntity("id", id);
	OIdentifiable oIdentifiable = session.lookupOIdentifiableForIdInCache(oid);
	if(oIdentifiable!=null) return oIdentifiable.getRecord();
	else {
		ODatabaseDocument db = session.getDatabase();
		List<ODocument> ret = db.query(new OSQLSynchQuery<>("select from "+getSchemaClass()+" where "+getPkField()+" = ?", 1), oid);
		return ret==null || ret.isEmpty()? null : ret.get(0);
	}
}
 
Example 5
Source File: OMail.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
public OMailSettings getMailSettings() {
    OIdentifiable identifiable = document.field(OPROPERTY_SETTINGS);
    ODocument doc = identifiable != null ? identifiable.getRecord() : null;
    return doc != null ? new OMailSettings(doc) : null;
}
 
Example 6
Source File: PerspectivesModule.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
public ODocument getPerspectiveItemAsDocument() {
	OIdentifiable perspectiveItem = document.field(PROP_PERSPECTIVE_ITEM);
	return perspectiveItem != null ? perspectiveItem.getRecord() : null;
}
 
Example 7
Source File: PerspectivesModule.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
public ODocument getPerspectiveAsDocument() {
	OIdentifiable perspective = document.field(PROP_PERSPECTIVE);
	return perspective != null ? perspective.getRecord() : null;
}
 
Example 8
Source File: OContentShareResource.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
protected byte[] getContent(OIdentifiable rid, String field) {
	ODocument doc = rid.getRecord();
	if(doc==null) return null;
	return doc.field(field, byte[].class);
}
 
Example 9
Source File: OClassIntrospector.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
@Override
public OProperty virtualizeField(ODocument doc, String field) {
	OProperty property = OPropertyPrototyper.newPrototype(doc.getClassName());
	property.setName(field);
	OType oType = doc.fieldType(field);
	if(oType==null) oType=OType.ANY;
	property.setType(oType);
	switch (oType) {
		case LINK:
			OIdentifiable link = doc.field(field);
			if(link!=null && link instanceof ODocument) property.setLinkedClass(((ODocument)link).getSchemaClass());
			break;
		case LINKBAG:
			OCollection<OIdentifiable> bag = doc.field(field);
			if(bag!=null && bag.size()>0) {
				OIdentifiable linkIdentifiable = bag.iterator().next();
				ORecord record = linkIdentifiable!=null?linkIdentifiable.getRecord():null;
				if(record!=null && record instanceof ODocument) property.setLinkedClass(((ODocument)record).getSchemaClass());
			}
			break;
		case LINKLIST:
		case LINKSET:
			Collection<ODocument> collection = doc.field(field);
			if(collection!=null && !collection.isEmpty()) {
				link = collection.iterator().next();
				if(link!=null && link instanceof ODocument) property.setLinkedClass(((ODocument)link).getSchemaClass());
			}
			break;
		case LINKMAP:
			Map<String, ODocument> map = doc.field(field);
			if(map!=null && !map.isEmpty()) {
				link = map.values().iterator().next();
				if(link!=null && link instanceof ODocument) property.setLinkedClass(((ODocument)link).getSchemaClass());
			}
			break;
		case EMBEDDED:
			Object value = doc.field(field);
			OType linkedType = OType.getTypeByValue(value);
			if(OType.EMBEDDED.equals(linkedType)) property.setLinkedClass(((ODocument)value).getSchemaClass());
			else property.setLinkedType(linkedType);
			break;
		case EMBEDDEDSET:
		case EMBEDDEDLIST:
			Collection<Object> objectCollection = doc.field(field);
			if(objectCollection!=null && !objectCollection.isEmpty()) {
				value = objectCollection.iterator().next();
				property.setLinkedType(OType.getTypeByValue(value));
			}
			break;
		case EMBEDDEDMAP:
			Map<String, Object> objectMap = doc.field(field);
			if(objectMap!=null && !objectMap.isEmpty()) {
				value = objectMap.values().iterator().next();
				property.setLinkedType(OType.getTypeByValue(value));
			}
			break;
		default:
			break;
	}
	return property;
}
 
Example 10
Source File: OUserSocialNetwork.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
public ODocument getUserAsDocument() {
    OIdentifiable user = document.field(PROP_USER);
    return user != null ? user.getRecord() : null;
}
 
Example 11
Source File: OUserSocialNetwork.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
public ODocument getServiceAsDocument() {
    OIdentifiable service = document.field(PROP_SERVICE);
    return service != null ? service.getRecord() : null;
}
 
Example 12
Source File: OSMS.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
public ODocument getSettingsAsDocument() {
  OIdentifiable settings = document.field(PROP_SETTINGS);
  return settings != null ? settings.getRecord() : null;
}
 
Example 13
Source File: OPreparedSMS.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
public ODocument getSMSAsDocument() {
  OIdentifiable sms = document.field(PROP_SMS);
  return sms != null ? sms.getRecord() : null;
}
 
Example 14
Source File: OLoggerEventMailDispatcherModel.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
public ODocument getMailAsDocument() {
    OIdentifiable mail = document.field(PROP_MAIL);
    return mail != null ? mail.getRecord() : null;
}
 
Example 15
Source File: OLoggerModule.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
public ODocument getCorrelationIdGeneratorAsDocument() {
	OIdentifiable generator = document.field(PROP_CORRELATION_ID_GENERATOR);
	return generator != null ? generator.getRecord() : null;
}
 
Example 16
Source File: OLoggerModule.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
public ODocument getLoggerEventDispatcherAsDocument() {
	OIdentifiable dispatcher = document.field(PROP_LOGGER_EVENT_DISPATCHER);
	return dispatcher != null ? dispatcher.getRecord() : null;
}
 
Example 17
Source File: ODocumentModel.java    From wicket-orientdb with Apache License 2.0 4 votes vote down vote up
public ODocumentModel(OIdentifiable identifiable) {
	super(identifiable!=null?(ODocument)identifiable.getRecord():null);
	if(identifiable!=null) this.orid = identifiable.getIdentity();
}
 
Example 18
Source File: ContentExpressionFunction.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Nullable
private String getAssetRepository(ODocument asset) {
  OIdentifiable bucketId = asset.field(AssetEntityAdapter.P_BUCKET, OIdentifiable.class);
  ODocument bucket = bucketId.getRecord();
  return bucket.field(BucketEntityAdapter.P_REPOSITORY_NAME, String.class);
}
 
Example 19
Source File: ContentExpressionFunction.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public Object execute(final Object iThis,
                      final OIdentifiable iCurrentRecord,
                      final Object iCurrentResult,
                      final Object[] iParams,
                      final OCommandContext iContext)
{
  OIdentifiable identifiable = (OIdentifiable) iParams[0];
  ODocument asset = identifiable.getRecord();
  RepositorySelector repositorySelector = RepositorySelector.fromSelector((String) iParams[2]);
  String jexlExpression = (String) iParams[1];
  List<String> membersForAuth;

  //if a single repo was selected, we want to auth against that member
  if (!repositorySelector.isAllRepositories()) {
    membersForAuth = Arrays.asList(repositorySelector.getName());
  }
  //if all repos (or all of format) was selected, use the repository the asset was in, as well as any groups
  //that may contain that repository
  else {
    @SuppressWarnings("unchecked")
    Map<String, List<String>> repoToContainedGroupMap = (Map<String, List<String>>) iParams[3];

    //find the repository that matches the asset
    String assetRepository = getAssetRepository(asset);

    //if can't find it, just back out, nothing more to see here
    if (assetRepository == null) {
      log.error("Asset {} references no repository", getAssetName(asset));
      return false;
    }

    membersForAuth = repoToContainedGroupMap.get(assetRepository);

    if (membersForAuth == null) {
      log.error("Asset {} references an invalid repository: {}", getAssetName(asset), assetRepository);
      return false;
    }
  }

  return contentAuthHelper.checkPathPermissions(asset.field(P_NAME), asset.field(P_FORMAT),
      membersForAuth.toArray(new String[membersForAuth.size()])) && checkJexlExpression(asset, jexlExpression,
      asset.field(AssetEntityAdapter.P_FORMAT, String.class));
}
 
Example 20
Source File: CommonUtils.java    From Orienteer with Apache License 2.0 3 votes vote down vote up
/**
 * Map record from identifiable, using map function
 * If can't load record and cast it to {@link ODocument} from identifiable, so returns null
 * @param identifiable {@link OIdentifiable} identifiable for map
 * @param mapFunc map function which will be apply for record loaded from identifiable
 * @param <T> type of return value by mapFunc
 * @return optional mapped record or {@link Optional#empty()} if identifiable is null, or can't load record
 */
public static <T> Optional<T> getFromIdentifiable(OIdentifiable identifiable, Function<ODocument, T> mapFunc) {
	if (identifiable != null) {
		ODocument doc = identifiable.getRecord();
		return doc != null ? ofNullable(mapFunc.apply(doc)) : empty();
	}
	return empty();
}