Search in sources :

Example 1 with BaseSelectionImpl

use of com.dexels.navajo.document.base.BaseSelectionImpl in project navajo by Dexels.

the class SaxHandler method parseProperty.

private final void parseProperty(Map<String, String> h) throws NavajoException {
    // logger.info("NAME: "+(String)h.get("name"));
    String sLength = null;
    String myName = h.get(Property.PROPERTY_NAME);
    String myValue = h.get(Property.PROPERTY_VALUE);
    String subType = h.get(Property.PROPERTY_SUBTYPE);
    String description = h.get(Property.PROPERTY_DESCRIPTION);
    String direction = h.get(Property.PROPERTY_DIRECTION);
    String type = h.get(Property.PROPERTY_TYPE);
    sLength = h.get(Property.PROPERTY_LENGTH);
    String cardinality = h.get(Property.PROPERTY_CARDINALITY);
    String extendsProp = h.get(Property.PROPERTY_EXTENDS);
    String reference = h.get(Property.PROPERTY_REFERENCE);
    String key = h.get(Property.PROPERTY_KEY);
    String bind = h.get(Property.PROPERTY_BIND);
    String method = h.get(Property.PROPERTY_METHOD);
    Integer plength = null;
    Property definitionProperty = null;
    String subtype = null;
    int length = 0;
    try {
        if (sLength != null) {
            length = Integer.parseInt(sLength);
            plength = Integer.valueOf(length);
        }
    } catch (Exception e1) {
    // logger.info("ILLEGAL LENGTH IN PROPERTY " + myName + ": " +
    // sLength);
    }
    if (myName == null) {
        throw NavajoFactory.getInstance().createNavajoException("Can not parse property without a name ");
    }
    boolean isListType = (type != null && type.equals(Property.SELECTION_PROPERTY));
    if (isListType) {
        currentProperty = (BasePropertyImpl) NavajoFactory.getInstance().createProperty(currentDocument, myName, cardinality, description, direction);
    } else {
        currentProperty = (BasePropertyImpl) NavajoFactory.getInstance().createProperty(currentDocument, myName, type, myValue, length, description, direction, subtype);
    }
    if (messageStack.isEmpty()) {
        throw NavajoFactory.getInstance().createNavajoException("Can not parse property without being inside a message, probably an input error");
    }
    Message current = messageStack.peek();
    current.addProperty(currentProperty);
    BaseMessageImpl arrayParent = (BaseMessageImpl) current.getArrayParentMessage();
    if (arrayParent != null && arrayParent.isArrayMessage()) {
        definitionProperty = arrayParent.getPropertyDefinition(myName);
        if (definitionProperty != null) {
            if (description == null || "".equals(description)) {
                description = definitionProperty.getDescription();
            }
            if (direction == null || "".equals(direction)) {
                direction = definitionProperty.getDirection();
            }
            if (type == null || "".equals(type)) {
                type = definitionProperty.getType();
            }
            if (plength == null) {
                length = definitionProperty.getLength();
            }
            if (subType == null) {
                if (definitionProperty.getSubType() != null) {
                    currentProperty.setSubType(definitionProperty.getSubType());
                }
            } else {
                if (definitionProperty.getSubType() != null) {
                    /**
                     * Concatenated subtypes. The if the same key of a subtype is present
                     * in both the property and the definition property.
                     */
                    currentProperty.setSubType(definitionProperty.getSubType() + "," + subType);
                }
            }
        }
    }
    if (subType == null && NavajoFactory.getInstance().getDefaultSubtypeForType(type) != null) {
        currentProperty.setSubType(NavajoFactory.getInstance().getDefaultSubtypeForType(type));
    } else {
        currentProperty.setSubType(subType);
    }
    if (type == null && current.isArrayMessage()) {
        logger.info("Found undefined property: " + currentProperty.getName());
    }
    isListType = (type != null && type.equals(Property.SELECTION_PROPERTY));
    if (isListType && definitionProperty != null) {
        if (cardinality == null) {
            cardinality = definitionProperty.getCardinality();
        }
        type = Property.SELECTION_PROPERTY;
        List<Selection> l = definitionProperty.getAllSelections();
        for (int i = 0; i < l.size(); i++) {
            BaseSelectionImpl s1 = (BaseSelectionImpl) l.get(i);
            BaseSelectionImpl s2 = (BaseSelectionImpl) s1.copy(currentDocument);
            currentProperty.addSelection(s2);
        }
    }
    currentProperty.setType(type);
    currentProperty.setDescription(description);
    currentProperty.setDirection(direction);
    currentProperty.setCardinality(cardinality);
    currentProperty.setLength(length);
    currentProperty.setExtends(extendsProp);
    currentProperty.setKey(key);
    currentProperty.setReference(reference);
    currentProperty.setBind(bind);
    currentProperty.setMethod(method);
}
Also used : BaseMessageImpl(com.dexels.navajo.document.base.BaseMessageImpl) Message(com.dexels.navajo.document.Message) Selection(com.dexels.navajo.document.Selection) BaseSelectionImpl(com.dexels.navajo.document.base.BaseSelectionImpl) Property(com.dexels.navajo.document.Property) NavajoException(com.dexels.navajo.document.NavajoException) IOException(java.io.IOException) EOFException(java.io.EOFException)

Example 2 with BaseSelectionImpl

use of com.dexels.navajo.document.base.BaseSelectionImpl in project navajo by Dexels.

the class TestProperty method tesSelectionEqualsUpdateFix.

@Test
public void tesSelectionEqualsUpdateFix() {
    BaseNavajoImpl n = new BaseNavajoImpl(NavajoFactory.getInstance());
    BasePropertyImpl p1 = new BasePropertyImpl(n, "Noot");
    p1.setType("selection");
    p1.setCardinality("1");
    p1.addSelection(new BaseSelectionImpl(n, "opt1", "1", false));
    p1.addSelection(new BaseSelectionImpl(n, "opt2", "2", true));
    p1.addPropertyChangeListener(e -> {
        logger.info("Old: {}", e.getOldValue());
        logger.info("New: {}", e.getNewValue());
        // no real change.
        Assert.fail();
    });
    p1.setSelected(p1.getSelection("opt2"));
}
Also used : BaseNavajoImpl(com.dexels.navajo.document.base.BaseNavajoImpl) BasePropertyImpl(com.dexels.navajo.document.base.BasePropertyImpl) BaseSelectionImpl(com.dexels.navajo.document.base.BaseSelectionImpl) Test(org.junit.Test)

Example 3 with BaseSelectionImpl

use of com.dexels.navajo.document.base.BaseSelectionImpl in project navajo by Dexels.

the class TestProperty method tesSelections.

@Test
@Deprecated
public void tesSelections() {
    BaseNavajoImpl n = new BaseNavajoImpl(NavajoFactory.getInstance());
    BasePropertyImpl p1 = new BasePropertyImpl(n, "Noot");
    p1.setType("selection");
    p1.setCardinality("1");
    p1.addSelection(new BaseSelectionImpl(n, "opt1", "1", false));
    p1.addSelection(new BaseSelectionImpl(n, "opt2", "2", false));
    p1.addSelection(new BaseSelectionImpl(n, "opt3", "3", false));
    assertEquals("___DUMMY_ELEMENT___", p1.getSelected().getValue());
    // Cardinality 1
    p1.setSelected("1");
    assertEquals("1", p1.getSelected().getValue());
    assertFalse("2".equals(p1.getSelected().getValue()));
    assertFalse("3".equals(p1.getSelected().getValue()));
    p1.setSelected("2");
    assertEquals("2", p1.getSelected().getValue());
    assertFalse("1".equals(p1.getSelected().getValue()));
    assertFalse("3".equals(p1.getSelected().getValue()));
    p1.setSelected("3");
    assertEquals("3", p1.getSelected().getValue());
    assertFalse("1".equals(p1.getSelected().getValue()));
    assertFalse("2".equals(p1.getSelected().getValue()));
    // Cardinality +
    p1.setCardinality("+");
    p1.clearSelections();
    assertFalse("1".equals(p1.getSelected().getValue()));
    assertFalse("2".equals(p1.getSelected().getValue()));
    assertFalse("3".equals(p1.getSelected().getValue()));
    p1.setSelected("1");
    p1.setSelected("2");
    List<Selection> all = p1.getAllSelectedSelections();
    for (int i = 0; i < all.size(); i++) {
        assertTrue(all.get(i).getValue().equals("1") || all.get(i).getValue().equals("2"));
        assertFalse(all.get(i).getValue().equals("3"));
    }
}
Also used : BaseNavajoImpl(com.dexels.navajo.document.base.BaseNavajoImpl) BasePropertyImpl(com.dexels.navajo.document.base.BasePropertyImpl) Selection(com.dexels.navajo.document.Selection) BaseSelectionImpl(com.dexels.navajo.document.base.BaseSelectionImpl) Test(org.junit.Test)

Example 4 with BaseSelectionImpl

use of com.dexels.navajo.document.base.BaseSelectionImpl in project navajo by Dexels.

the class TestProperty method tesEqualProperties.

@Test
public void tesEqualProperties() {
    BaseNavajoImpl n = new BaseNavajoImpl(NavajoFactory.getInstance());
    BasePropertyImpl p1 = new BasePropertyImpl(n, "Noot");
    BasePropertyImpl p2 = new BasePropertyImpl(n, "Noot");
    // Strings
    p1.setAnyValue("Aap");
    p2.setAnyValue("Aap");
    assertTrue(p1.isEqual(p2));
    p2.setAnyValue("Kip");
    assertFalse(p1.isEqual(p2));
    // Selections
    p1.setType("selection");
    p1.setCardinality("1");
    p1.addSelection(new BaseSelectionImpl(n, "opt1", "1", false));
    p1.addSelection(new BaseSelectionImpl(n, "opt2", "2", true));
    p1.addSelection(new BaseSelectionImpl(n, "opt3", "3", false));
    p2.setType("selection");
    p2.setCardinality("1");
    p2.addSelection(new BaseSelectionImpl(n, "opt1", "1", false));
    p2.addSelection(new BaseSelectionImpl(n, "opt2", "2", true));
    p2.addSelection(new BaseSelectionImpl(n, "opt3", "3", false));
    assertTrue(p1.isEqual(p2));
    p2.setSelected(new BaseSelectionImpl(n, "opt2", "2", true), false);
    p2.setSelected(new BaseSelectionImpl(n, "opt2", "3", true), true);
    assertFalse(p1.isEqual(p2));
    p1.setSelected(new BaseSelectionImpl(n, "opt2", "2", true), false);
    p1.setSelected(new BaseSelectionImpl(n, "opt2", "3", true), true);
    assertTrue(p1.isEqual(p2));
    // Date
    p1.setType("date");
    p1.removeAllSelections();
    p2.setType("date");
    p2.removeAllSelections();
    // these could be non-equal, right?
    p1.setAnyValue(new java.util.Date());
    p2.setAnyValue(new java.util.Date());
    assertTrue(p1.isEqual(p2));
    p2.setAnyValue(new java.util.Date(32131332L));
    assertFalse(p1.isEqual(p2));
}
Also used : BaseNavajoImpl(com.dexels.navajo.document.base.BaseNavajoImpl) BasePropertyImpl(com.dexels.navajo.document.base.BasePropertyImpl) Date(java.util.Date) BaseSelectionImpl(com.dexels.navajo.document.base.BaseSelectionImpl) Test(org.junit.Test)

Aggregations

BaseSelectionImpl (com.dexels.navajo.document.base.BaseSelectionImpl)4 BaseNavajoImpl (com.dexels.navajo.document.base.BaseNavajoImpl)3 BasePropertyImpl (com.dexels.navajo.document.base.BasePropertyImpl)3 Test (org.junit.Test)3 Selection (com.dexels.navajo.document.Selection)2 Message (com.dexels.navajo.document.Message)1 NavajoException (com.dexels.navajo.document.NavajoException)1 Property (com.dexels.navajo.document.Property)1 BaseMessageImpl (com.dexels.navajo.document.base.BaseMessageImpl)1 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1 Date (java.util.Date)1