Java Code Examples for com.orientechnologies.orient.core.metadata.schema.OClass#isSubClassOf()

The following examples show how to use com.orientechnologies.orient.core.metadata.schema.OClass#isSubClassOf() . 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: SchemeUtils.java    From guice-persist-orient with MIT License 6 votes vote down vote up
/**
 * Assigns base class in scheme for provided model type (for example, to make class vertex type
 * it must extend V).
 *
 * @param db        database object
 * @param modelType model class
 * @param target    target super class to assign
 * @param logger    caller specific logger
 */
public static void assignSuperclass(final ODatabaseObject db, final Class<?> modelType, final String target,
                                    final Logger logger) {
    // searching for first existing scheme class to check hierarchy and avoid duplicates
    final OClass existing = findFirstExisting(db, modelType);
    final String modelName = modelType.getSimpleName();
    if (existing != null) {
        if (existing.isSubClassOf(target)) {
            return;
        }
        validateGraphTypes(modelName, existing, target);
    }
    if (existing != null && modelName.equals(existing.getName())) {
        logger.debug("Assigning superclass {} to {}", target, modelName);
        // adding superclass, not overriding!
        command(db, "alter class %s superclass +%s", modelName, target);
    } else {
        logger.debug("Creating model class scheme {} as extension to {}", modelName, target);
        command(db, "create class %s extends %s", modelName, target);
    }
}
 
Example 2
Source File: BpmnHook.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
@Override
public RESULT onTrigger(TYPE iType, ORecord iRecord) {
    if (database.getStatus() != STATUS.OPEN)
        return RESULT.RECORD_NOT_CHANGED;

      if (!(iRecord instanceof ODocument))
        return RESULT.RECORD_NOT_CHANGED;

      final ODocument doc = (ODocument) iRecord;
      OClass oClass = doc.getSchemaClass();
      RESULT res = RESULT.RECORD_NOT_CHANGED;
      if(oClass!=null && oClass.isSubClassOf(IEntityHandler.BPM_ENTITY_CLASS)) {
    	  if(iType.equals(TYPE.BEFORE_CREATE)) {
    		  if(doc.field("id")==null) {
    			  doc.field("id", getNextId());
    			  res = RESULT.RECORD_CHANGED;
    		  }
    	  }
    	  RESULT handlerRes = HandlersManager.get().onTrigger(database, doc, iType);
    	  res = (handlerRes == RESULT.RECORD_NOT_CHANGED || handlerRes==null)?res:handlerRes;
      }
      return res;
}
 
Example 3
Source File: OClassMetaPanel.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
@Override
protected void onConfigure() {
	super.onConfigure();
	String critery = getPropertyObject();
	if(OClassPrototyper.SUPER_CLASSES.equals(critery))
	{
		Collection<OClass> superClasses = (Collection<OClass>)getEnteredValue();
		AbstractMetaPanel<OClass, String, ?> onCreateFieldsPanel = getMetaComponent(CustomAttribute.ON_CREATE_FIELDS.getName());
		AbstractMetaPanel<OClass, String, ?> onCreateIdentityTypePanel = getMetaComponent(CustomAttribute.ON_CREATE_IDENTITY_TYPE.getName());
		if(onCreateFieldsPanel!=null || onCreateIdentityTypePanel!=null) {
			boolean visibility = false;
			for(OClass superClass : superClasses) {
				if(visibility = superClass.isSubClassOf(OSecurityShared.RESTRICTED_CLASSNAME)) break;
			}
			if(onCreateFieldsPanel!=null) onCreateFieldsPanel.setVisibilityAllowed(visibility);
			if(onCreateIdentityTypePanel!=null) onCreateIdentityTypePanel.setVisibilityAllowed(visibility);
		}
	}
}
 
Example 4
Source File: OSchemaUtils.java    From wicket-orientdb with Apache License 2.0 5 votes vote down vote up
/**
 * Find the most deep {@link OClass} in a collection of classes
 * @param classes {@link Iterable} with {@link OClass}es to handle
 * @return deepest {@link OClass} or null
 */
public static OClass getDeepestOClass(Iterable<OClass> classes) {
	if(classes==null) return null;
	OClass ret=null;
	for(OClass oClass: classes) {
		if(ret==null) ret = oClass;
		else {
			if(!ret.equals(oClass) && oClass.isSubClassOf(ret)) ret = oClass;
		}
	}
	return ret;
}
 
Example 5
Source File: OUsersCommonUtils.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
public static void setRestricted(ODatabaseDocument db, OClass oClass) {
    OClass restricted = db.getMetadata().getSchema().getClass("ORestricted");
    if (!oClass.isSubClassOf(restricted)) {
        oClass.addSuperClass(restricted);
        Collection<OProperty> properties = restricted.properties();
        oClass.properties().stream()
                .filter(p -> !properties.contains(p))
                .filter(p -> !(boolean) CustomAttribute.HIDDEN.getValue(p))
                .forEach(p -> CustomAttribute.DISPLAYABLE.setValue(p, true));
    }
}
 
Example 6
Source File: OEntityFilter.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isSupportedMethod(IMethodContext dataObject) {
	OClass oclass = getOClass(dataObject);
	if (oclass!=null){
		for (OClass oClass : getOClasses()) {
			if (oclass.isSubClassOf(oClass)){
				return true;
			}
		}
	}
	return false;
}
 
Example 7
Source File: ByOClassWidgetFilter.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean apply(IWidgetType<T> input) {
	String selector = input.getSelector();
	if(Strings.isEmpty(selector)) return true;
	else {
		OClass oClass = getOClass(); 
		return oClass!=null? oClass.isSubClassOf(selector) : false;
	}
}
 
Example 8
Source File: DefaultDashboardManager.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
public ODocument createWidgetDocument(IWidgetType<?> widgetType) {
	String oClassName = widgetType.getOClassName();
	if(oClassName==null) oClassName = OCLASS_WIDGET;
	OClass oClass = getDatabase().getMetadata().getSchema().getClass(oClassName);
	if(oClass==null || !oClass.isSubClassOf(OCLASS_WIDGET)) throw new WicketRuntimeException("Wrong OClass specified for widget settings: "+oClassName);
	ODocument widgetDoc = new ODocument(oClass);
	widgetDoc.field(OPROPERTY_TYPE_ID, widgetType.getId());
	return widgetDoc;
}