Examples of AssociationValue


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

  @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

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

    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

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

    }

    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

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

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

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

    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

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

    // TODO: check manyToOne value with an ID (so the corresponding object must be fetched from DB).

    final String newValue = "hello world";
    Map<String, PrimitiveAttribute<?>> mtoAttributes = new HashMap<String, PrimitiveAttribute<?>>();
    mtoAttributes.put(ManyToOneProperty.PARAM_TEXT_ATTR, new StringAttribute(newValue));
    AssociationValue assoValue = new AssociationValue(null, mtoAttributes);
    ManyToOneAttribute mtoAttribute = new ManyToOneAttribute(assoValue);

    Map<String, Attribute> attributes = new HashMap<String, Attribute>();
    attributes.put(MTO, mtoAttribute);
    featureModel.setAttributes(feature1, attributes);
View Full Code Here

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

  }

  public Object createNested() throws LayerException {
    Object o = layer.getFeatureModel().newInstance();
    OneToManyAttribute many = new OneToManyAttribute(new ArrayList<AssociationValue>());
    ManyToOneAttribute one = new ManyToOneAttribute(new AssociationValue(null, new HashMap<String, Attribute<?>>(),
        false));
    one.getValue().getAllAttributes().put("stringAttr", new StringAttribute("one"));

    // create 2 manyInMany
    OneToManyAttribute manyInMany = new OneToManyAttribute(new ArrayList<AssociationValue>());
    AssociationValue manyInMany1 = new AssociationValue(null, new HashMap<String, Attribute<?>>(), false);
    manyInMany1.getAllAttributes().put("stringAttr", new StringAttribute("manyInMany1"));
    manyInMany.getValue().add(manyInMany1);
    AssociationValue manyInMany2 = new AssociationValue(null, new HashMap<String, Attribute<?>>(), false);
    manyInMany2.getAllAttributes().put("stringAttr", 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("stringAttr", 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("stringAttr", new StringAttribute("manyInOne1"));
    manyInOne.getValue().add(manyInOne1);
    AssociationValue manyInOne2 = new AssociationValue(null, new HashMap<String, Attribute<?>>(), false);
    manyInOne2.getAllAttributes().put("stringAttr", 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("stringAttr", 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("oneToManyAttr", manyInMany);
    // add oneInMany to many2
    many2.getAllAttributes().put("manyToOneAttr", oneInMany);
    // add to many
    many.getValue().add(many1);
    many.getValue().add(many2);

    // add manyInOne to one
View Full Code Here

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

    return o;
  }

  public Object createExistingManyToOne() throws LayerException {
    Object o = layer.getFeatureModel().newInstance();
    ManyToOneAttribute one = new ManyToOneAttribute(new AssociationValue(new LongAttribute(1L),
        new HashMap<String, Attribute<?>>(), false));
    Map<String, Attribute> attributes = new HashMap<String, Attribute>();
    attributes.put("manyToOneAttr", one);
    layer.getFeatureModel().setAttributes(o, attributes);
    return o;
View Full Code Here

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

      date = format.parse("01/01/2009");
    } catch (ParseException e) {
      date = new Date();
    }
    attributes.put("dateAttr", new DateAttribute(date));
    return new ManyToOneAttribute(new AssociationValue(new LongAttribute(id), attributes));
  }
View Full Code Here

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

   *
   * @param attributeInfo
   * @return an empty value
   */
  public static AssociationValue createEmptyAssociationValue(AssociationAttributeInfo attributeInfo) {
    AssociationValue value = new AssociationValue();
    Map<String, Attribute<?>> attributes = new HashMap<String, Attribute<?>>();
    for (AttributeInfo attrInfo : attributeInfo.getFeature().getAttributes()) {
      attributes.put(attrInfo.getName(), createEmptyAttribute(attrInfo));
    }
    value.setAllAttributes(attributes);
    value.setId(createEmptyPrimitiveAttribute(attributeInfo.getFeature().getIdentifier()));
    return value;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.