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

The following examples show how to use com.orientechnologies.orient.core.metadata.schema.OClass#properties() . 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: ListOPropertiesModel.java    From wicket-orientdb with Apache License 2.0 6 votes vote down vote up
@Override
public Collection<OProperty> getData() {
	OClass oClass = oClassModel.getObject();
	if(oClass==null)
	{
		return null;
	}
	else if(allPropertiesModel==null||Boolean.TRUE.equals(allPropertiesModel.getObject()))
	{
		return oClass.properties();
	}
	else
	{
		return oClass.declaredProperties();
	}
}
 
Example 2
Source File: TestModels.java    From wicket-orientdb with Apache License 2.0 6 votes vote down vote up
@Test
public void testOPropertiesDataProvider()
{
	OSchema schema = wicket.getTester().getSchema();
	OClass oClass = schema.getClass("ClassA");
	OPropertiesDataProvider provider = new OPropertiesDataProvider(oClass, true);
	provider.setSort("name", SortOrder.ASCENDING);
	Iterator<? extends OProperty> it = provider.iterator(0, -1);
	List<OProperty> allProperties = new ArrayList<OProperty>(oClass.properties());
	while(it.hasNext())
	{
		OProperty oProperty = it.next();
		assertTrue(allProperties.remove(provider.model(oProperty).getObject()));
	}
	assertTrue(allProperties.size()==0);
	provider.detach();
}
 
Example 3
Source File: AbstractEntityHandler.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
protected void initMapping(OPersistenceSession session) {
mappingFromDocToEntity = new HashMap<>();
mappingFromEntityToDoc = new HashMap<>();

OClass oClass = session.getClass(getSchemaClass());
Class<T> entityClass = getEntityClass();
	
for(OProperty property : oClass.properties()) {
	String propertyName = property.getName();
	String beanPropertyName = propertyName;
	boolean isLink = property.getType().isLink();
	if(isLink) beanPropertyName+="Id";
	IGetAndSet getAndSet = getGetAndSetter(entityClass, beanPropertyName);
	if(getAndSet!=null) {
		if(isLink) {
			IEntityHandler<?> targetHandler = HandlersManager.get().getHandlerBySchemaClass(property.getLinkedClass().getName());
			if(targetHandler==null || targetHandler.getPkField()==null) continue;
			propertyName+="."+targetHandler.getPkField();
		}
		if(getAndSet.getSetter()!=null) mappingFromDocToEntity.put(propertyName, beanPropertyName);
		if(getAndSet.getGetter()!=null) mappingFromEntityToDoc.put(beanPropertyName, propertyName);
	}
}
}
 
Example 4
Source File: ODocumentPivotTableWidget.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
@Override
protected String getDefaultSql() {
	ODocument doc = getModelObject();
	OClass oClass = doc.getSchemaClass();
	OProperty multiProperty = null;
	for(OProperty property : oClass.properties()) {
		if(property.getType().isLink() && property.getType().isMultiValue()) {
			multiProperty = property;
			break;
		}
	}
	if(multiProperty!=null) {
		return "select expand("+multiProperty.getName()+") from :doc";
	} else {
		return "select from :doc";
	}
	
}
 
Example 5
Source File: OClassIntrospector.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
@Override
public OProperty getNameProperty(OClass oClass) {
	if(oClass==null) return null;
	OProperty ret = CustomAttribute.PROP_NAME.getValue(oClass);
	if(ret!=null) return ret;
	ret = oClass.getProperty("name");
	if(ret!=null) return ret;
	for(OProperty p: oClass.properties())
	{
		if(!p.getType().isMultiValue())
		{
			ret = p;
			if(OType.STRING.equals(p.getType())) break;
		}
	}
	return ret;
}
 
Example 6
Source File: TestPrototypers.java    From wicket-orientdb with Apache License 2.0 5 votes vote down vote up
@Test
public void testOClassPrototyper() throws Exception
{
	OClass newClass = OClassPrototyper.newPrototype();
	assertNull(wicket.getTester().getSchema().getClass("NewClass"));
	newClass.setName("NewClass");
	assertEquals("NewClass", newClass.getName());
	newClass.setClusterSelection(ORoundRobinClusterSelectionStrategy.NAME);
	assertEquals(ORoundRobinClusterSelectionStrategy.NAME, newClass.getClusterSelection().getName());
	Collection<OProperty> properties = newClass.properties();
	assertNotNull(properties);
	assertTrue(properties.size()==0);
	properties = newClass.declaredProperties();
	assertNotNull(properties);
	assertTrue(properties.size()==0);
	assertFalse(newClass.hasSuperClasses());
	OClass oRoleClass = wicket.getTester().getSchema().getClass("ORole");
	newClass.addSuperClass(oRoleClass);
	assertTrue(newClass.hasSuperClasses());
	assertTrue(newClass.getSuperClassesNames().contains("ORole"));
	assertTrue(newClass.getSuperClasses().contains(oRoleClass));
	assertTrue(newClass.isSubClassOf(oRoleClass));
	newClass.removeSuperClass(oRoleClass);
	assertFalse(newClass.hasSuperClasses());
	assertFalse(newClass.isSubClassOf(oRoleClass));
	//Realization
	assertTrue(newClass instanceof IPrototype); 
	OClass realizedNewClass = ((IPrototype<OClass>)newClass).realizePrototype();
	assertEquals(wicket.getTester().getSchema().getClass("NewClass"), realizedNewClass);
	assertFalse(realizedNewClass instanceof IPrototype);
	assertEquals("NewClass", realizedNewClass.getName());
	assertEquals(ORoundRobinClusterSelectionStrategy.NAME, realizedNewClass.getClusterSelection().getName());
	wicket.getTester().getSchema().dropClass(realizedNewClass.getName());
}
 
Example 7
Source File: BrowsePivotTableWidget.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
public String getDefaultSql() {
	String thisLang = getLocale().getLanguage();
	String systemLang = Locale.getDefault().getLanguage();
	OClass oClass = getModelObject();
	StringBuilder sb = new StringBuilder();
	Collection<OProperty> properties = oClass.properties();
	for(OProperty property: properties) {
		OType type = property.getType();
		if(OType.LINK.equals(type)) {
			OClass linkedClass = property.getLinkedClass();
			OProperty nameProperty = oClassIntrospector.getNameProperty(linkedClass);
			if(nameProperty!=null) {
				OType linkedClassType = nameProperty.getType();
				String map = property.getName()+'.'+nameProperty.getName();
				if (OType.EMBEDDEDMAP.equals(linkedClassType)) {
					sb.append("coalesce(").append(map).append('[').append(thisLang).append("], ");
					if(!thisLang.equals(systemLang)) {
						sb.append(map).append('[').append(systemLang).append("], ");
					}
					sb.append("first(").append(map).append(")) as ").append(property.getName()).append(", ");
				}else if(Comparable.class.isAssignableFrom(linkedClassType.getDefaultJavaType())) {
					sb.append(map).append(", ");
				}
			}
		}else if(Comparable.class.isAssignableFrom(type.getDefaultJavaType())) {
			sb.append(property.getName()).append(", ");
		} 
	}
	if(sb.length()>0) sb.setLength(sb.length()-2);
	sb.insert(0, "SELECT ");
	sb.append(" FROM ").append(oClass.getName());
	return sb.toString();
}
 
Example 8
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 9
Source File: OArchitectClassesUtils.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
private static List<OArchitectOProperty> toOArchitectProperties(OClass oClass, List<OClass> superClasses) {
    Collection<OProperty> properties = oClass.properties();
    List<OArchitectOProperty> architectProperties = new ArrayList<>(properties.size());
    ExtendedOPropertiesDataProvider provider = new ExtendedOPropertiesDataProvider(new CollectionModel<>(properties));
    provider.setSort(CustomAttribute.ORDER.getName(), SortOrder.ASCENDING);
    Iterator<? extends OProperty> iterator = provider.iterator(0, provider.size());
    while (iterator.hasNext()){
        OProperty property = iterator.next();
        OArchitectOProperty architectOProperty = OArchitectOProperty.toArchitectOProperty(oClass, property);
        architectOProperty.setSubClassProperty(isSubClassProperty(property, superClasses));
        architectProperties.add(architectOProperty);
    }
    return architectProperties;
}
 
Example 10
Source File: OClassIntrospector.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
public List<OProperty> getDisplayableProperties(OClass oClass) {
	Collection<OProperty> properties =  oClass.properties();
	IFilterPredicateFactory factory = OrienteerWebApplication.get().getServiceInstance(IFilterPredicateFactory.class);
	Collection<OProperty> filteredProperties = Collections2.filter(properties, factory.getGuicePredicateForTableProperties());
	if(filteredProperties==null || filteredProperties.isEmpty()) filteredProperties = properties;
	return ORDER_PROPERTIES_BY_ORDER.sortedCopy(filteredProperties);
}
 
Example 11
Source File: OClassIntrospector.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> listTabs(OClass oClass) {
	IFilterPredicateFactory factory = OrienteerWebApplication.get().getServiceInstance(IFilterPredicateFactory.class);
	SerializablePredicate<OProperty> predicate = factory.getPredicateForListProperties();
	List<String> tabs = new ArrayList<String>();
	for (OProperty prop : oClass.properties()) {
		String tab = CustomAttribute.TAB.getValue(prop, DEFAULT_TAB);
		if(!tabs.contains(tab) && predicate.test(prop)) tabs.add(tab); 
	}
	return new ArrayList<>(tabs);
}
 
Example 12
Source File: OClassIntrospector.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
public List<OProperty> listProperties(OClass oClass,
		Predicate<OProperty>... predicates) {
	if(oClass==null) return Collections.EMPTY_LIST;
	Collection<OProperty> properties =  oClass.properties();
	Predicate<OProperty> predicate = predicates==null || predicates.length==0?
											 null
											:(predicates.length==1?
														predicates[0]
														:Predicates.and(predicates));
	Collection<OProperty> filteredProperties = predicate!=null?Collections2.filter(properties, predicate):properties;
	return ORDER_PROPERTIES_BY_ORDER.sortedCopy(filteredProperties);
	
}
 
Example 13
Source File: SaveODocumentCommand.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
public static void realizeMandatory(ODocument doc) {
	OClass oClass = doc.getSchemaClass();
	if(oClass!=null) {
		for(OProperty property : oClass.properties()) {
			if(property.isMandatory() 
					&& Strings.isEmpty(property.getDefaultValue()) 
					&& !doc.containsField(property.getName())) {
				doc.field(property.getName(), (Object) null);
			}
		}
	}
}
 
Example 14
Source File: CreateOPropertyCommand.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
public int findMaxOrder(OClass oClass)
{
	int ret = 0;
	for(OProperty property: oClass.properties())
	{
		Integer order = CustomAttribute.ORDER.getValue(property);
		if(order!=null && order > ret) ret = order;
	}
	return ret;
}