Package org.geomajas.configuration

Examples of org.geomajas.configuration.AssociationAttributeInfo


      }
    }

    List<?> values = null;
    if (attributeInfo instanceof AssociationAttributeInfo) {
      AssociationAttributeInfo associationInfo = (AssociationAttributeInfo) attributeInfo;
      if (associationInfo.getType().equals(AssociationType.MANY_TO_ONE)) {
        values = ManyToOneAttributeBean.manyToOneValues();
      }
    }

    List<Attribute<?>> attributes = new ArrayList<Attribute<?>>();
View Full Code Here


            break;
          default:
            throw new IllegalStateException("Unknown primitive attribute type " + prim.getType());
        }
      } else if (attrInfo instanceof AssociationAttributeInfo) {
        AssociationAttributeInfo ass = (AssociationAttributeInfo) attrInfo;
        switch (ass.getType()) {
          case MANY_TO_ONE:
            builder.add(ass.getName(), Object.class);
            break;
          case ONE_TO_MANY:
            builder.add(ass.getName(), Collection.class);
            break;
          default:
            throw new IllegalStateException("Unknown association attribute type " + ass.getType());
        }
      }
    }
    // add the extra style index attribute
    builder.add(STYLE_INDEX_ATTRIBUTE_NAME, Integer.class);
View Full Code Here

  }

  private Attribute<?> getRecursiveAttribute(Entity entity, FeatureInfo featureInfo, String[] path)
      throws LayerException {
    String name = path[0];
    AssociationAttributeInfo associationAttributeInfo = null;
    // check attribute type
    Set<String> names = new HashSet<String>();
    // check for id (support for backwards compatibility)
    if (featureInfo.getIdentifier().getName().equals(name)) {
      try {
        return dtoConverterService.toDto(entity == null ? null : entity.getAttribute(name),
            featureInfo.getIdentifier());
      } catch (GeomajasException e) {
        throw new LayerException(e, ExceptionCode.CONVERSION_PROBLEM);
      }
    }
    for (AttributeInfo attributeInfo : featureInfo.getAttributes()) {
      names.add(attributeInfo.getName());
      if (attributeInfo.getName().equals(name)) {
        if (attributeInfo instanceof AssociationAttributeInfo) {
          associationAttributeInfo = (AssociationAttributeInfo) attributeInfo;
        } else if (attributeInfo instanceof PrimitiveAttributeInfo) {
          // primitive, return the attribute
          PrimitiveAttributeInfo primitiveAttributeInfo = (PrimitiveAttributeInfo) attributeInfo;
          try {
            return dtoConverterService.toDto(entity == null ? null : entity.getAttribute(name),
                primitiveAttributeInfo);
          } catch (GeomajasException e) {
            throw new LayerException(e, ExceptionCode.CONVERSION_PROBLEM);
          }
        }
      }
    }
    // association attribute
    if (associationAttributeInfo == null) {
      throw new LayerException(ExceptionCode.ATTRIBUTE_UNKNOWN, name, names);
    } else if (path.length > 1) {
      // go deeper
      return getRecursiveAttribute(entity == null ? null : entity.getChild(name),
          associationAttributeInfo.getFeature(), Arrays.copyOfRange(path, 1, path.length));
    } else {
      switch (associationAttributeInfo.getType()) {
        case MANY_TO_ONE:
          ManyToOneAttribute manyToOne = new ManyToOneAttribute();
          if (entity != null) {
            Entity oneEntity = entity.getChild(associationAttributeInfo.getName());
            AssociationValue value = getAssociationValue(oneEntity, associationAttributeInfo);
            manyToOne.setValue(value);
          }
          return manyToOne;
        case ONE_TO_MANY:
          OneToManyAttribute oneToMany = new OneToManyAttribute();
          if (entity != null) {
            EntityCollection children = entity.getChildCollection(associationAttributeInfo.getName());
            List<AssociationValue> values = new ArrayList<AssociationValue>();
            for (Entity manyEntity : children) {
              values.add(getAssociationValue(manyEntity, associationAttributeInfo));
            }
            oneToMany.setValue(values);
View Full Code Here

        Attribute<?> attribute = entry.getValue();
        if (primitiveMap.containsKey(entry.getKey())) {
          addPrimitive(entry.getKey(), (PrimitiveAttribute<?>) attribute);
        } else if (associationMap.containsKey(entry.getKey())) {
          AssociationAttribute<?> association = (AssociationAttribute<?>) attribute;
          AssociationAttributeInfo associationAttributeInfo = associationMap.get(entry.getKey());
          switch (associationAttributeInfo.getType()) {
            case MANY_TO_ONE:
              association = (association == null ? new ManyToOneAttribute() : association);
              addManyToOne(entry.getKey(), associationMap.get(entry.getKey()),
                  (ManyToOneAttribute) association);
              break;
View Full Code Here

    Assert.assertFalse(((BooleanAttribute) converter.toDto(Boolean.FALSE, attributeInfo)).getValue());
  }

  @Test
  public void testAssociation() throws GeomajasException {
    AssociationAttributeInfo many = new AssociationAttributeInfo();
    many.setType(AssociationType.ONE_TO_MANY);
    many.setEditable(true);
    many.setLabel("manyInMany");
    many.setName("manyInMany");

    PrimitiveAttributeInfo textAttr = new PrimitiveAttributeInfo("text", "text", PrimitiveType.STRING);
    FeatureInfo featureInfo = new FeatureInfo();
    featureInfo.setIdentifier(new PrimitiveAttributeInfo("id", "id", PrimitiveType.LONG));
    featureInfo.setAttributes(Collections.singletonList((AttributeInfo) textAttr));
    many.setFeature(featureInfo);
    Attribute<?> attr = converter.toDto(new Bean[] { new Bean("t1",1L), new Bean("t2",2L) }, many);
    Assert.assertTrue(attr instanceof AssociationAttribute);
    AssociationAttribute assoc = (AssociationAttribute)attr;
    List<AssociationValue> value = (List<AssociationValue>)assoc.getValue();
    value.get(0).getAttributes();
View Full Code Here

  public List<Attribute<?>> getAttributes(String attributeName, Filter filter) throws LayerException {
    if (attributeName == null) {
      throw new HibernateLayerException(ExceptionCode.ATTRIBUTE_UNKNOWN, (Object) null);
    }
    AssociationAttributeInfo attributeInfo = getRecursiveAttributeInfo(attributeName, getFeatureInfo()
        .getAttributes());
    Session session = getSessionFactory().getCurrentSession();
    Criteria criteria = session.createCriteria(attributeInfo.getFeature().getDataSourceName());
    CriteriaVisitor visitor = new CriteriaVisitor((HibernateFeatureModel) getFeatureModel(), dateFormat);
    if (filter != null) {
      Criterion c = (Criterion) filter.accept(visitor, null);
      if (c != null) {
        criteria.add(c);
View Full Code Here

 
 
  private AssociationAttributeInfo getRecursiveAttributeInfo(String name, List<AttributeInfo> infos) {
    for (AttributeInfo attributeInfo : infos) {
      if (attributeInfo instanceof AssociationAttributeInfo) {
        AssociationAttributeInfo associationAttributeInfo = (AssociationAttributeInfo) attributeInfo;
        if (name.equals(attributeInfo.getName())) {
          return associationAttributeInfo;
        } else if (name.startsWith(attributeInfo.getName())) {
          String childName = name.substring(attributeInfo.getName().length() + 1);
          return getRecursiveAttributeInfo(childName, associationAttributeInfo.getFeature().getAttributes());
        }
      }
    }
    return null;
  }
View Full Code Here

                  primitive.getType());
          }
        }
      } else if (info instanceof AssociationAttributeInfo) {
        Object associationItem = item.getAttributeAsObject(AssociationItem.ASSOCIATION_ITEM_ATTRIBUTE_KEY);
        AssociationAttributeInfo associationInfo = (AssociationAttributeInfo) info;
        if (associationItem != null) {
          switch (associationInfo.getType()) {
            case MANY_TO_ONE:
              ((ManyToOneItem<?>) associationItem).toItem((ManyToOneAttribute) attribute)// NOSONAR
              break;
            case ONE_TO_MANY:
              ((OneToManyItem<?>) associationItem).toItem((OneToManyAttribute) attribute); // NOSONAR
              break;
            default:
              throw new IllegalStateException("Unhandled association attribute type " +
                  associationInfo.getType());
          }
        }
      }
      item.fireEvent(new ChangedEvent(item.getJsObj()));
    }
View Full Code Here

      FormItem formItem = formWidget.getItem(info.getName());
      if (formItem != null) {
        if (info instanceof AssociationAttributeInfo) {
          Object associationItem = formItem
              .getAttributeAsObject(AssociationItem.ASSOCIATION_ITEM_ATTRIBUTE_KEY);
          AssociationAttributeInfo associationInfo = (AssociationAttributeInfo) info;
          if (associationItem != null) {
            switch (associationInfo.getType()) {
              case MANY_TO_ONE:
                ((ManyToOneItem<?>) associationItem).clearValue(); // NOSONAR valid cast
                break;
              case ONE_TO_MANY:
                ((OneToManyItem<?>) associationItem).clearValue(); // NOSONAR valid cast
                break;
              default:
                throw new IllegalStateException("Unhandled association attribute type " +
                    associationInfo.getType());
            }
          }
        } else {
          formItem.clearValue();
View Full Code Here

          }
        } else {
          record.setAttribute(attributeInfo.getName(), "");
        }
      } else {
        AssociationAttributeInfo associationAttributeInfo = (AssociationAttributeInfo) attributeInfo;
        String displayName = associationAttributeInfo.getFeature().getDisplayAttributeName();
        Object value = attr.getValue();
        if (value != null) {
          if (displayName == null) {
            displayName = associationAttributeInfo.getFeature().getAttributes().get(0).getName();
          }
          switch (associationAttributeInfo.getType()) {
            case MANY_TO_ONE:
              ManyToOneAttribute manyToOneAttribute = (ManyToOneAttribute) attr;
              Object displayValue = manyToOneAttribute.getValue().getAllAttributes().get(displayName)
                  .getValue();
              if (displayValue != null) {
View Full Code Here

TOP

Related Classes of org.geomajas.configuration.AssociationAttributeInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.