Package org.geomajas.layer.feature.attribute

Examples of org.geomajas.layer.feature.attribute.AssociationValue


  @Test
  public void testManyToOneAttribute() throws LayerException {
    Map<String, Attribute<?>> attributes = new HashMap<String, Attribute<?>>();
    FeatureBean bean = new FeatureBean();
    AssociationValue value = new AssociationValue(new LongAttribute(),new HashMap<String, Attribute<?>>(), false);
    value.getAllAttributes().put("stringAttr",new StringAttribute("mto"));
    attributes.put("manyToOneAttr", new ManyToOneAttribute(value));
    service.setAttributes(bean, layerBeans.getLayerInfo().getFeatureInfo(), new DummyMapper(), attributes);
    Assert.assertNotNull(bean.getManyToOneAttr());
    Assert.assertEquals("mto",bean.getManyToOneAttr().getStringAttr());
    // test replacing
View Full Code Here


 
  @Test
  public void testNonEditable() throws LayerException {
    Map<String, Attribute<?>> attributes = new HashMap<String, Attribute<?>>();
    FeatureBean bean = new FeatureBean();
    AssociationValue value = new AssociationValue(new LongAttribute(),new HashMap<String, Attribute<?>>(), false);
    value.getAllAttributes().put("stringAttr",new StringAttribute("mto"));
    attributes.put("manyToOneAttr", new ManyToOneAttribute(value));
    attributes.put("stringAttr", new StringAttribute("top"));
    service.setAttributes(bean, layerNonEditableBeans.getLayerInfo().getFeatureInfo(), new DummyMapper(), attributes);
    Assert.assertNotNull(bean.getManyToOneAttr());
    Assert.assertNull(bean.getManyToOneAttr().getStringAttr());
View Full Code Here

      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();
View Full Code Here

    Map<String, Attribute<?>> attributes = new HashMap<String, Attribute<?>>();
    for (AttributeInfo attributeInfo : childInfo.getAttributes()) {
      attributes.put(attributeInfo.getName(),
          getRecursiveAttribute(entity, childInfo, new String[] { attributeInfo.getName() }));
    }
    AssociationValue value = new AssociationValue(id, attributes, false);
    return value;
  }
View Full Code Here

    Attribute many = featureModel.getAttribute(f1, "many");
    Assert.assertTrue(many instanceof OneToManyAttribute);
    Assert.assertNotNull(many.getValue());
    Iterator<AssociationValue> it2 = ((OneToManyAttribute) many).getValue().iterator();
    Assert.assertTrue(it2.hasNext());
    AssociationValue v = it2.next();
    Attribute<?> manyInMany = v.getAllAttributes().get("manyInMany");
    Assert.assertNotNull(manyInMany);
    Assert.assertTrue(manyInMany instanceof OneToManyAttribute);
    Attribute<?> oneInMany = v.getAllAttributes().get("oneInMany");
    Assert.assertNotNull(oneInMany);
    Assert.assertTrue(oneInMany instanceof ManyToOneAttribute);
    Attribute one = featureModel.getAttribute(f1, "one");
    Assert.assertTrue(one instanceof ManyToOneAttribute);
    Assert.assertNotNull(one.getValue());
    AssociationValue v2 = ((ManyToOneAttribute) one).getValue();
    Attribute<?> oneInOne = v2.getAllAttributes().get("oneInOne");
    Assert.assertNotNull(oneInOne);
    Assert.assertTrue(oneInOne instanceof ManyToOneAttribute);
    Attribute<?> manyInOne = v2.getAllAttributes().get("manyInOne");
    Assert.assertNotNull(manyInOne);
    Assert.assertTrue(manyInOne instanceof OneToManyAttribute);
  }
View Full Code Here

  @Test
  public void testCreate() throws LayerException {
    Object o = featureModel.newInstance();
    OneToManyAttribute many = new OneToManyAttribute(new ArrayList<AssociationValue>());
    ManyToOneAttribute one = new ManyToOneAttribute(new AssociationValue(null, new HashMap<String, Attribute<?>>(),
        false));

    // create 2 manyInMany
    OneToManyAttribute manyInMany = new OneToManyAttribute(new ArrayList<AssociationValue>());
    AssociationValue manyInMany1 = new AssociationValue(null, new HashMap<String, Attribute<?>>(), false);
    manyInMany1.getAllAttributes().put("textAttr", new StringAttribute("manyInMany1"));
    manyInMany.getValue().add(manyInMany1);
    AssociationValue manyInMany2 = new AssociationValue(null, new HashMap<String, Attribute<?>>(), false);
    manyInMany2.getAllAttributes().put("textAttr", new StringAttribute("manyInMany2"));
    manyInMany.getValue().add(manyInMany2);

    // create oneInMany
    ManyToOneAttribute oneInMany = new ManyToOneAttribute();
    AssociationValue oneInManyValue = new AssociationValue(null, new HashMap<String, Attribute<?>>(), false);
    oneInManyValue.getAllAttributes().put("textAttr", new StringAttribute("oneInMany"));
    oneInMany.setValue(oneInManyValue);

    // create 2 manyInOne
    OneToManyAttribute manyInOne = new OneToManyAttribute(new ArrayList<AssociationValue>());
    AssociationValue manyInOne1 = new AssociationValue(null, new HashMap<String, Attribute<?>>(), false);
    manyInOne1.getAllAttributes().put("textAttr", new StringAttribute("manyInOne1"));
    manyInOne.getValue().add(manyInOne1);
    AssociationValue manyInOne2 = new AssociationValue(null, new HashMap<String, Attribute<?>>(), false);
    manyInOne2.getAllAttributes().put("textAttr", new StringAttribute("manyInOne2"));
    manyInOne.getValue().add(manyInOne2);

    // create oneInOne
    ManyToOneAttribute oneInOne = new ManyToOneAttribute();
    AssociationValue oneInOneValue = new AssociationValue(null, new HashMap<String, Attribute<?>>(), false);
    oneInOneValue.getAllAttributes().put("textAttr", new StringAttribute("oneInOne"));
    oneInOne.setValue(oneInOneValue);

    // create 2 many
    AssociationValue many1 = new AssociationValue(null, new HashMap<String, Attribute<?>>(), false);
    AssociationValue many2 = new AssociationValue(null, new HashMap<String, Attribute<?>>(), false);
    // add manyInMany to many1
    many1.getAllAttributes().put("manyInMany", manyInMany);
    // add oneInMany to many2
    many2.getAllAttributes().put("oneInMany", oneInMany);
    // add to many
    many.getValue().add(many1);
    many.getValue().add(many2);

    // add manyInOne to one
View Full Code Here

    Object o = featureModel.newInstance();
    Map<String, Attribute> attributes = new HashMap<String, Attribute>();
    // create many attribute
    OneToManyAttribute many = new OneToManyAttribute(new ArrayList<AssociationValue>());
    // create empty and add
    AssociationValue many1 = new AssociationValue(null, new HashMap<String, Attribute<?>>(), false);
    many.getValue().add(many1);
    // create an existing one-in-many and add
    ManyToOneAttribute oneInMany2 = new ManyToOneAttribute();
    AssociationValue oneInManyValue = new AssociationValue(new LongAttribute(oneInMany1.getId()), new HashMap<String, Attribute<?>>(), false);
    oneInMany2.setValue(oneInManyValue);
    AssociationValue many2 = new AssociationValue(null, new HashMap<String, Attribute<?>>(), false);
    many2.getAllAttributes().put("oneInMany", oneInMany2);
    many.getValue().add(many2);
    // add many
    attributes.put("many", many);
    featureModel.setAttributes(o, attributes);
   
    // check text attr
    Object feature = layer.create(o);
    OneToManyAttribute attr = (OneToManyAttribute)featureModel.getAttribute(feature, "many");
    AssociationValue val = attr.getValue().get(1);
    ManyToOneAttribute one = (ManyToOneAttribute)val.getAllAttributes().get("oneInMany");
    Assert.assertEquals("existing1", one.getValue().getAttributeValue("textAttr"));

  }
View Full Code Here

    }

    public void addManyToOne(String name, AssociationAttributeInfo attributeInfo, ManyToOneAttribute association)
        throws LayerException {
      Entity existing = entity.getChild(name);
      AssociationValue value = association.getValue();
      if (value == null) {
        addChild(new DeleteManyToOneOperation(getMapper(), getEntity(), attributeInfo));
      } else if (existing == null) {
        addChild(new CreateManyToOneOperation(getMapper(), getEntity(), attributeInfo, association.getValue()));
      } else {
        Object id = existing.getId(attributeInfo.getFeature().getIdentifier().getName());
        if (value.getId() == null || value.getId().isEmpty() || !value.getId().getValue().equals(id)) {
          addChild(new CreateManyToOneOperation(getMapper(), getEntity(), attributeInfo,
              association.getValue()));
        } else {
          addChild(new UpdateManyToOneOperation(getMapper(), attributeInfo, existing, value));
        }
View Full Code Here

      }
    }
    PrimitiveAttribute<?> id = (PrimitiveAttribute<?>) toDto(
        getBeanProperty(value, associationAttributeInfo.getFeature().getIdentifier().getName()),
        associationAttributeInfo.getFeature().getIdentifier());
    return new AssociationValue(id, attributes, primitiveOnly);
  }
View Full Code Here

    attributes.put(PARAM_INT_ATTR, new IntegerAttribute(100));
    attributes.put(PARAM_FLOAT_ATTR, new FloatAttribute(100.0f));
    attributes.put(PARAM_DOUBLE_ATTR, new DoubleAttribute(100.0));
    attributes.put(PARAM_DATE_ATTR, new DateAttribute(date));

    return new ManyToOneAttribute(new AssociationValue(new LongAttribute(id), attributes));
  }
View Full Code Here

TOP

Related Classes of org.geomajas.layer.feature.attribute.AssociationValue

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.