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

The following examples show how to use com.orientechnologies.orient.core.metadata.schema.OProperty#getLinkedType() . 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: EmbeddedCollectionContainsFilterPanel.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public FormComponent<?> createFilterComponent(IModel<?> model) {
    OProperty property = getEntityModel().getObject();
    FormComponent<?> component;
    switch (property.getLinkedType()) {
        case BOOLEAN:
            component = new BooleanFilterPanel(getFilterId(), (IModel<Boolean>) model);
            break;
        case DATE:
            component = new BooleanFilterPanel(getFilterId(), (IModel<Boolean>) model);
            break;
        case DATETIME:
            component = new ODateField(getFilterId(), (IModel<Date>) model);
            break;
        default:
            component = new TextField<>(getFilterId(), model);
    }
    return component;
}
 
Example 2
Source File: OLuceneIndexManagerAbstract.java    From orientdb-lucene with Apache License 2.0 5 votes vote down vote up
private void checkCollectionIndex(OIndexDefinition indexDefinition) {

    List<String> fields = indexDefinition.getFields();

    OClass aClass = getDatabase().getMetadata().getSchema().getClass(indexDefinition.getClassName());
    for (String field : fields) {
      OProperty property = aClass.getProperty(field);

      if (property.getType().isEmbedded() && property.getLinkedType() != null) {
        collectionFields.put(field, true);
      } else {
        collectionFields.put(field, false);
      }
    }
  }
 
Example 3
Source File: EmbeddedCollectionViewPanel.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
public EmbeddedCollectionViewPanel(String id, final IModel<ODocument> documentModel, final IModel<OProperty> propertyModel) {
	super(id, new DynamicPropertyValueModel<M>(documentModel, propertyModel));
	final DefaultVisualizer visualizer = DefaultVisualizer.INSTANCE;
	OProperty property = propertyModel.getObject();
	final OType oType = property.getLinkedType()!=null?property.getLinkedType():OType.EMBEDDED;
	ListView<T> listView = new ListView<T>("items", new CollectionAdapterModel<T, M>(getModel())) {

		@Override
		protected void populateItem(ListItem<T> item) {
			item.add(visualizer.createComponent("item", DisplayMode.VIEW, documentModel, propertyModel, oType, item.getModel()));
		}
		
		@Override
		protected ListItem<T> newItem(int index, IModel<T> itemModel) {
			return new ListItem<T>(index, itemModel)
					{
						@Override
						public IMarkupFragment getMarkup(Component child) {
							if(child==null || !child.getId().equals("item")) return super.getMarkup(child);
							IMarkupFragment ret = markupProvider.provideMarkup(child);
							return ret!=null?ret:super.getMarkup(child);
						}
					};
		}
	};
	add(listView);
}
 
Example 4
Source File: EmbeddedMapViewPanel.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
public EmbeddedMapViewPanel(String id, final IModel<ODocument> documentModel, final IModel<OProperty> propertyModel) {
	super(id, new DynamicPropertyValueModel<Map<String, V>>(documentModel, propertyModel));
	OProperty property = propertyModel.getObject();
	final DefaultVisualizer visualizer = DefaultVisualizer.INSTANCE;
	final OType linkedType = property.getLinkedType();
	final OType oType = linkedType != null ? linkedType : (OType.LINKMAP.equals(property.getType()) ? OType.LINK :OType.ANY);
	IModel<Set<Map.Entry<String, V>>> entriesModel = new PropertyModel<>(getModel(), "entrySet()");
	ListView<Map.Entry<String, V>> listView = 
			new ListView<Map.Entry<String, V>>("items", new CollectionAdapterModel<>(entriesModel)) {

		@Override
		protected void populateItem(ListItem<Map.Entry<String, V>> item) {
			item.add(new Label("key", new PropertyModel<String>(item.getModel(), "key")));
			item.add(visualizer.createComponent("item", DisplayMode.VIEW, documentModel, propertyModel, oType, new PropertyModel<V>(item.getModel(), "value")));
		}
		
		@Override
		protected ListItem<Map.Entry<String, V>> newItem(int index, IModel<Map.Entry<String, V>> itemModel) {
			return new ListItem<Map.Entry<String, V>>(index, itemModel)
					{
						@Override
						public IMarkupFragment getMarkup(Component child) {
							if(child==null || !child.getId().equals("item")) return super.getMarkup(child);
							IMarkupFragment ret = markupProvider.provideMarkup(child);
							return ret!=null?ret:super.getMarkup(child);
						}
					};
		}
	};
	add(listView);
}
 
Example 5
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 6
Source File: EmbeddedMapEditPanel.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
public EmbeddedMapEditPanel(String id, final IModel<ODocument> documentModel, final IModel<OProperty> propertyModel)
{
	super(id, new DynamicPropertyValueModel<Map<String, V>>(documentModel, propertyModel));
	setOutputMarkupId(true);
	OProperty property = propertyModel.getObject();
	final DefaultVisualizer visualizer = DefaultVisualizer.INSTANCE;
	final OType linkedType = property.getLinkedType();
	final OType oType = linkedType != null ? linkedType : (OType.LINKMAP.equals(property.getType()) ? OType.LINK :OType.ANY);
	listView = new ListView<Pair<V>>("items", new PropertyModel<List<Pair<V>>>(this, "data")) {

		@Override
		protected void populateItem(final ListItem<Pair<V>> item) {
			item.add(getKeyEditComponent(item));
			item.add(visualizer.createComponent("item", DisplayMode.EDIT, documentModel, propertyModel, oType, new PropertyModel<V>(item.getModel(), "value")));
			item.add(new AjaxFormCommand<Object>("remove", "command.remove")
					{
						@Override
						public void onClick(Optional<AjaxRequestTarget> targetOptional) {
							convertToData();
							getData().remove(item.getIndex());
							targetOptional.ifPresent(target -> target.add(EmbeddedMapEditPanel.this));
							listView.removeAll();
						}
					}.setDefaultFormProcessing(false)
					 .setAutoNotify(false)
					 .setBootstrapSize(BootstrapSize.EXTRA_SMALL)
					 .setBootstrapType(BootstrapType.DANGER)
					 .setIcon((String)null));
		}
		
		@Override
		protected ListItem<Pair<V>> newItem(int index, IModel<Pair<V>> itemModel) {
			return new ListItem<Pair<V>>(index, itemModel)
					{
						@Override
						public IMarkupFragment getMarkup(Component child) {
							if(child==null || !child.getId().equals("item")) return super.getMarkup(child);
							IMarkupFragment ret = markupProvider.provideMarkup(child);
							return ret!=null?ret:super.getMarkup(child);
						}
					};
		}

	};
	listView.setReuseItems(true);
	add(listView);
	add(new AjaxFormCommand<Pair<V>>("add", "command.add")
	{
		@Override
		public void onClick(Optional<AjaxRequestTarget> targetOptional) {
			convertToData();
			getData().add(new Pair<V>());
			targetOptional.ifPresent(target -> target.add(EmbeddedMapEditPanel.this));
			listView.removeAll();
		}
		
	}.setDefaultFormProcessing(false)
	 .setAutoNotify(false)
	 .setBootstrapSize(BootstrapSize.EXTRA_SMALL)
	 .setBootstrapType(BootstrapType.PRIMARY)
	 .setIcon((String)null));
}
 
Example 7
Source File: EmbeddedCollectionEditPanel.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
public EmbeddedCollectionEditPanel(String id, final IModel<ODocument> documentModel, final IModel<OProperty> propertyModel, Class<?> finalType)
{
	super(id, new DynamicPropertyValueModel<M>(documentModel, propertyModel));
	setOutputMarkupId(true);
	this.finalType = finalType;
	final DefaultVisualizer visualizer = DefaultVisualizer.INSTANCE;
	OProperty property = propertyModel.getObject();
	final OType oType = property.getLinkedType()!=null?property.getLinkedType():OType.EMBEDDED;
	listView = new ListView<T>("items", new PropertyModel<List<T>>(this, "data")) {

		@Override
		@SuppressWarnings("unchecked")
		protected void populateItem(final ListItem<T> item) {
			Component component = visualizer.createComponent("item", DisplayMode.EDIT, documentModel, propertyModel, oType, item.getModel());
			if (embeddedView == null && component != null) embeddedView = (Class<FormComponent>) component.getClass();
			item.add(component);
			item.add(new AjaxFormCommand<T>("remove", "command.remove")
					{
						@Override
						public void onClick(Optional<AjaxRequestTarget> targetOptional) {
							convertToData();
							getData().remove(item.getIndex());
							targetOptional.ifPresent(target ->target.add(EmbeddedCollectionEditPanel.this));
							listView.removeAll();
						}
					}.setDefaultFormProcessing(false)
					 .setAutoNotify(false)
					 .setBootstrapSize(BootstrapSize.EXTRA_SMALL)
					 .setBootstrapType(BootstrapType.DANGER)
					 .setIcon((String)null));
		}

		@Override
		protected ListItem<T> newItem(int index, IModel<T> itemModel) {
			return new ListItem<T>(index, itemModel)
					{
						@Override
						public IMarkupFragment getMarkup(Component child) {
							if(child==null || !child.getId().equals("item")) return super.getMarkup(child);
							IMarkupFragment ret = markupProvider.provideMarkup(child);
							return ret!=null?ret:super.getMarkup(child);
						}
					};
		}

	};
	listView.setReuseItems(true);
	add(listView);
	add(new AjaxFormCommand<T>("add", "command.add")
	{
		@Override
		public void onClick(Optional<AjaxRequestTarget> targetOptional) {
			convertToData();
			getData().add(null);
			targetOptional.ifPresent(target -> target.add(EmbeddedCollectionEditPanel.this));
			listView.removeAll();
		}
		
	}.setDefaultFormProcessing(false)
	 .setAutoNotify(false)
	 .setBootstrapSize(BootstrapSize.EXTRA_SMALL)
	 .setBootstrapType(BootstrapType.PRIMARY)
	 .setIcon((String)null));
}
 
Example 8
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);
}