Java Code Examples for com.orientechnologies.orient.core.metadata.schema.OProperty#getType()

The following examples show how to use com.orientechnologies.orient.core.metadata.schema.OProperty#getType() . 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: OArchitectOProperty.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
public static OArchitectOProperty toArchitectOProperty(OClass oClass, OProperty property) {
    OArchitectOProperty architectProperty = new OArchitectOProperty(property.getName(), property.getType());
    if (property.getLinkedClass() != null) {
        architectProperty.setLinkedClass(property.getLinkedClass().getName());
        OProperty inverse = CustomAttribute.PROP_INVERSE.getValue(property);
        if (inverse != null) {
            OArchitectOProperty prop = new OArchitectOProperty(inverse.getName(), inverse.getType());
            prop.setExistsInDb(true);
            architectProperty.setInversePropertyEnable(true);
            architectProperty.setInverseProperty(prop);
        }
    }
    int order = CustomAttribute.ORDER.getValue(property);
    architectProperty.setOrder(order);
    architectProperty.setPageUrl("/property/" + oClass.getName() + "/" + property.getName());
    architectProperty.setExistsInDb(true);
    return architectProperty;
}
 
Example 2
Source File: ApplyEditorChangesBehavior.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
private void addPropertiesToOClass(OSchema schema, OClass oClass, List<OArchitectOProperty> properties) {
    for (OArchitectOProperty property : properties) {
        if (!property.isSubClassProperty()) {
            OProperty oProperty = oClass.getProperty(property.getName());
            if (oProperty == null && !property.isExistsInDb()) {
                oProperty = oClass.createProperty(property.getName(), property.getType());
            } else if (oProperty != null && !property.isExistsInDb() && oProperty.getType() != property.getType()) {
                oProperty.setType(property.getType());
            }
            if (!Strings.isNullOrEmpty(property.getLinkedClass())) {
                setLinkedClassForProperty(property, oProperty, schema);
            }
            CustomAttribute.ORDER.setValue(oProperty, property.getOrder());
        }
    }
}
 
Example 3
Source File: ODocumentMetaPanel.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected Component resolveComponent(String id, DisplayMode mode,
		OProperty property) {
	OType oType = property.getType();
	UIVisualizersRegistry registry = OrienteerWebApplication.get().getUIVisualizersRegistry();
	
	Function<String, Component> createComp = (String vis) -> {
		if(vis==null) return null;
		IVisualizer visualizer = registry.getComponentFactory(oType, vis);
		return visualizer!=null?visualizer.createComponent(id, mode, getEntityModel(), getPropertyModel(), getModel()):null;
	};
	
	Component ret = null; 
	if(this.visualization!=null) ret = createComp.apply(this.visualization);
	if(ret==null) {
		String visualizationComponent = CustomAttribute.VISUALIZATION_TYPE.getValue(property);
		ret = createComp.apply(visualizationComponent);
	}
	return ret!=null?ret:createComp.apply(IVisualizer.DEFAULT_VISUALIZER);
}
 
Example 4
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 5
Source File: OClassIntrospector.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
public ODocument getParent(ODocument doc) {
	if(doc==null || doc.getSchemaClass()==null) return null;
	OClass oClass = doc.getSchemaClass();
	OProperty parent = CustomAttribute.PROP_PARENT.getValue(oClass);
	if(parent!=null) {
		OType type = parent.getType();
		Object value = doc.field(parent.getName());
		if(value!=null) {
			switch (type) {
				case LINK:
					return ((OIdentifiable)value).getRecord();
				case LINKLIST:
				case LINKBAG:
				case LINKSET:
					Collection<OIdentifiable> collection =  (Collection<OIdentifiable>)value;
					return !collection.isEmpty()?(ODocument)collection.iterator().next().getRecord():null;
				case LINKMAP:
					Map<?, ?> map = (Map<?, ?>)value;
					value = map.isEmpty()?null:map.values().iterator().next();
					return value instanceof OIdentifiable ? (ODocument)((OIdentifiable)value).getRecord():null;
			default:
				return null;
			}
		}
	}
	return null;
}
 
Example 6
Source File: PlantUmlService.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
public void describe(Writer writer, OProperty oProperty)
{
	PrintWriter out = toPrintWriter(writer);
	OType type = oProperty.getType();
	String min = oProperty.getMin();
	String max = oProperty.getMax();
	String range = null;
	
	if(min!=null || max!=null)
	{
		range = Objects.equal(min, max)?min:(min!=null?min:"0")+".."+(max!=null?max:"*");
	}
	else if(type.isMultiValue())
	{
		range = "*";
	}
	
	boolean isEmbedded = type.equals(OType.EMBEDDED) || type.equals(OType.EMBEDDEDLIST) 
			|| type.equals(OType.EMBEDDEDMAP) || type.equals(OType.EMBEDDEDSET);
	
	if(oProperty.getLinkedClass()!=null
			&& (isEmbedded || type.isLink()))
	{
		out.append(oProperty.getOwnerClass().getName());
		if(isEmbedded) out.append("\"1\" *-- ");
		else out.append(" -> ");
		if(range!=null) out.append('"').append(range).append("\" ");
		out.append(oProperty.getLinkedClass().getName());
		out.append(" : ").append(oProperty.getName());
	}
	else
	{
		out.append(oProperty.getOwnerClass().getName())
			.append(" : ")
			.append(oProperty.getName()).append(" : ").append(type.name());
	}
	out.println();
}
 
Example 7
Source File: CollectionLinkFilterPanel.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
public FilterCriteriaType getFilterCriteriaType() {
    OProperty property = getEntityModel().getObject();
    if (property != null) {
        OType type = property.getType();
        return type.equals(OType.LINKSET) ? FilterCriteriaType.LINKSET : FilterCriteriaType.LINKLIST;
    }
    return FilterCriteriaType.LINKLIST;
}
 
Example 8
Source File: OPropertyValueColumn.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
private static String resolveSortExpression(OProperty property)
{
	if(property==null || property.getType()==null) return null;
	Class<?> javaType = property.getType().getDefaultJavaType();
	if(javaType!=null && Comparable.class.isAssignableFrom(javaType)) {
		return property.getName();
	} else if (LocalizationVisualizer.NAME.equals(CustomAttribute.VISUALIZATION_TYPE.getValue(property))) {
		return String.format("%s['%s']", property.getName(),
						OrienteerWebSession.get().getLocale().getLanguage());
	} else {
		return null;
	}
}
 
Example 9
Source File: LinksAsEmbeddedVisualizer.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
public <V> Component createComponent(String id, DisplayMode mode, IModel<ODocument> documentModel,
		IModel<OProperty> propertyModel, IModel<V> valueModel) {
	OProperty property = propertyModel.getObject();
	OType oType = property.getType();
	if(DisplayMode.VIEW.equals(mode))
	{
		switch(oType)
		{
			case LINK:
				return new EmbeddedDocumentPanel(id, (IModel<ODocument>)valueModel, new PropertyModel<OClass>(propertyModel, "linkedClass"), mode.asModel());
			case LINKLIST:
			case LINKSET:
				return new EmbeddedCollectionViewPanel<>(id, documentModel, propertyModel);
               case LINKMAP:
               	return new EmbeddedMapViewPanel<V>(id, documentModel, propertyModel);
               default:
               	return null;
		}
	}
	else if(DisplayMode.EDIT.equals(mode))
	{
		switch(oType)
		{
			case LINK:
				return new EmbeddedDocumentPanel(id, (IModel<ODocument>)valueModel, new PropertyModel<OClass>(propertyModel, "linkedClass"), mode.asModel());
			case LINKLIST:
				return new EmbeddedCollectionEditPanel<Object, List<Object>>(id, documentModel, propertyModel, ArrayList.class);
			case LINKSET:
				return new EmbeddedCollectionEditPanel<Object, Set<Object>>(id, documentModel, propertyModel, HashSet.class);
               case LINKMAP:
               	return new EmbeddedMapEditPanel<V>(id, documentModel, propertyModel);
               default:
               	return null;
		}
	}
	else return null;
}
 
Example 10
Source File: CalculablePropertiesHook.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
@Override
public void onRecordAfterRead(ODocument iDocument) {
	super.onRecordAfterRead(iDocument);
	OClass oClass = iDocument.getSchemaClass();
	if(oClass!=null)
	{
		List<String> calcProperties = getCalcProperties(iDocument);
		
		if(calcProperties!=null && calcProperties.size()>0)
		{
			for (String calcProperty :calcProperties) {
				//Force calculation. Required for work around issue in OrientDB
				//if(iDocument.field(calcProperty)!=null) continue;
				final OProperty property = oClass.getProperty(calcProperty);
				String script = CustomAttribute.CALC_SCRIPT.getValue(property);
				if(!Strings.isEmpty(script))
				{
					try {
						List<ODocument> calculated;
						if(FULL_QUERY_PATTERN.matcher(script).find())
						{
							calculated = iDocument.getDatabase().query(new OSQLSynchQuery<Object>(script), iDocument);
						}
						else
						{
							script = "select "+script+" as value from "+iDocument.getIdentity();
							calculated = iDocument.getDatabase().query(new OSQLSynchQuery<Object>(script));
						}
						if(calculated!=null && calculated.size()>0)
						{
							OType type = property.getType();
							Object value;
							if(type.isMultiValue())
							{
								final OType linkedType = property.getLinkedType();
								value = linkedType==null
										?calculated
										:Lists.transform(calculated, new Function<ODocument, Object>() {
											
											@Override
											public Object apply(ODocument input) {
												return OType.convert(input.field("value"), linkedType.getDefaultJavaType());
											}
										});
							}
							else
							{
								value = calculated.get(0).field("value");
							}
							value = OType.convert(value, type.getDefaultJavaType());
							Object oldValue = iDocument.field(calcProperty); 
							if (oldValue!=value && (oldValue==null || !oldValue.equals(value))){
								iDocument.field(calcProperty, value);
							}
						}
					} catch (OCommandSQLParsingException e) { //TODO: Refactor because one exception prevent calculation for others
						LOG.warn("Can't parse SQL for calculable property", e);
						iDocument.field(calcProperty, e.getLocalizedMessage());
					}
				}
			}
			
		}
	}
}
 
Example 11
Source File: OClassIntrospector.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
@Override
public String getDocumentName(ODocument doc, OProperty nameProp) {
	if(doc==null) return Application.get().getResourceSettings().getLocalizer().getString("nodoc", null);
	else
	{
		String ret = null;
		if(nameProp==null) nameProp = getNameProperty(doc.getSchemaClass());
		if(nameProp!=null)
		{
			Object value = doc.field(nameProp.getName());
			if(value!=null) {
				OType type = nameProp.getType();
				Locale locale = OrienteerWebSession.get().getLocale();
				switch (type)
				{
					case DATE:
						ret = OrienteerWebApplication.DATE_CONVERTER.convertToString((Date)value, locale);
						break;
					case DATETIME:
						ret = OrienteerWebApplication.DATE_TIME_CONVERTER.convertToString((Date)value, locale);
						break;
					case LINK:
						ret =  value instanceof ODocument?getDocumentName((ODocument)value):null;
						break;
					case EMBEDDEDMAP:
						Map<String, Object> localizations = (Map<String, Object>)value;
						Object localized = CommonUtils.localizeByMap(localizations, true, locale.getLanguage(), Locale.getDefault().getLanguage());
						ret = CommonUtils.toString(localized!=null ? localized : value);
						break;
					default:
						ret =  CommonUtils.toString(value);
						break;
				}
			}
		}
		else
		{
			ret = doc.toString();
		}
		return !Strings.isEmpty(ret) ? ret : Application.get().getResourceSettings().getLocalizer().getString("noname", null);
	}
}
 
Example 12
Source File: DefaultVisualizer.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <V> Component getFilterComponent(final String id, final IModel<OProperty> propertyModel,
										final FilterForm<OQueryModel<?>> filterForm) {
	IFilterCriteriaManager manager = getManager(propertyModel, filterForm);
	OProperty property = propertyModel.getObject();
	OType type = property.getType();
	List<AbstractFilterPanel<?, ?>> filters = new LinkedList<>();

	switch (type) {
		case LINKBAG:
		case TRANSIENT:
		case BINARY:
		case ANY:
			return null;
		case EMBEDDED:
			filters.add(new EmbeddedContainsValuePanel(FilterPanel.PANEL_ID, Model.of(),
					id, propertyModel, DefaultVisualizer.this, manager));
			filters.add(new EmbeddedContainsKeyPanel(FilterPanel.PANEL_ID, Model.of(),
					id, propertyModel, DefaultVisualizer.this, manager));
			break;
		case LINK:
			filters.add(new LinkEqualsFilterPanel(FilterPanel.PANEL_ID, Model.of(),
					id, propertyModel, DefaultVisualizer.this, manager));
			filters.add(new CollectionLinkFilterPanel(FilterPanel.PANEL_ID, new CollectionModel<>(),
					id, propertyModel, DefaultVisualizer.this, manager));
			break;
		case EMBEDDEDLIST:
		case EMBEDDEDSET:
			OProperty prop = propertyModel.getObject();
			if (prop != null) {
				if (prop.getLinkedType() != null) {
					filters.add(new EmbeddedCollectionContainsFilterPanel(FilterPanel.PANEL_ID, Model.of(),
							id, propertyModel, DefaultVisualizer.this, manager));
				} else {
					filters.add(new EmbeddedCollectionFilterPanel(FilterPanel.PANEL_ID, new CollectionModel<>(),
							id, propertyModel, DefaultVisualizer.this, manager, true));
				}
			}
			break;
		case LINKLIST:
		case LINKSET:
			filters.add(new CollectionLinkFilterPanel(FilterPanel.PANEL_ID, new CollectionModel<>(),
					id, propertyModel, DefaultVisualizer.this, manager));
			break;
		case EMBEDDEDMAP:
		case LINKMAP:
			filters.add(new MapContainsKeyFilterPanel(FilterPanel.PANEL_ID, Model.<String>of(),
					id, propertyModel, DefaultVisualizer.this, manager));
			if (type == OType.EMBEDDEDMAP) {
				filters.add(new EmbeddedMapContainsValueFilterPanel(FilterPanel.PANEL_ID, Model.of(),
						id, propertyModel, DefaultVisualizer.this, manager));
			} else {
				filters.add(new LinkMapContainsValueFilterPanel(FilterPanel.PANEL_ID, Model.<ODocument>of(),
						id, propertyModel, DefaultVisualizer.this, manager));
			}
			break;
		case STRING:

			filters.add(new ContainsStringFilterPanel(FilterPanel.PANEL_ID, Model.<String>of(),
					id, propertyModel, DefaultVisualizer.this, manager));
			filters.add(new EqualsFilterPanel(FilterPanel.PANEL_ID, Model.<String>of(),
					id, propertyModel, DefaultVisualizer.this, manager));
			filters.add(new CollectionFilterPanel(FilterPanel.PANEL_ID, new CollectionModel<String>(),
					id, propertyModel, DefaultVisualizer.this, manager));
			break;
		case BOOLEAN:
			filters.add(new EqualsFilterPanel(FilterPanel.PANEL_ID, Model.<Boolean>of(),
					id, propertyModel, DefaultVisualizer.this, manager));
			break;
		default:
			filters.add(new EqualsFilterPanel(FilterPanel.PANEL_ID, Model.of(),
					id, propertyModel, DefaultVisualizer.this, manager));
			filters.add(new CollectionFilterPanel(FilterPanel.PANEL_ID, new CollectionModel<>(),
					id, propertyModel, DefaultVisualizer.this, manager));
			filters.add(new RangeFilterPanel(FilterPanel.PANEL_ID, new CollectionModel<>(),
					id, propertyModel, DefaultVisualizer.this, manager));
	}

	return new FilterPanel(id, new OPropertyNamingModel(propertyModel), filterForm, filters);
}