Search in sources :

Example 1 with KeyWrapper

use of com.amalto.workbench.detailtabs.sections.model.entity.KeyWrapper in project tmdm-studio-se by Talend.

the class EntityCommitHandler method commitKeyAddition.

private boolean commitKeyAddition() {
    boolean hasChanges = false;
    for (KeyWrapper eachKeyWrapper : getCommitedObj().getKeys()) {
        if (!eachKeyWrapper.isUserCreated()) {
            continue;
        }
        hasChanges = true;
        XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
        XSDIdentityConstraintDefinition newKey = factory.createXSDIdentityConstraintDefinition();
        newKey.setName(eachKeyWrapper.getName());
        newKey.setIdentityConstraintCategory(eachKeyWrapper.getType());
        XSDXPathDefinition selector = factory.createXSDXPathDefinition();
        selector.setValue(eachKeyWrapper.getSelector());
        selector.setVariety(XSDXPathVariety.SELECTOR_LITERAL);
        newKey.setSelector(selector);
        for (FieldWrapper newFields : eachKeyWrapper.getFields()) {
            XSDXPathDefinition field = factory.createXSDXPathDefinition();
            field.setValue(newFields.getXPath());
            field.setVariety(XSDXPathVariety.FIELD_LITERAL);
            newKey.getFields().add(field);
        }
        getCommitedObj().getSourceEntity().getIdentityConstraintDefinitions().add(newKey);
        getCommitedObj().getSourceEntity().updateElement();
    }
    return hasChanges;
}
Also used : KeyWrapper(com.amalto.workbench.detailtabs.sections.model.entity.KeyWrapper) XSDFactory(org.eclipse.xsd.XSDFactory) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) FieldWrapper(com.amalto.workbench.detailtabs.sections.model.entity.FieldWrapper) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition)

Example 2 with KeyWrapper

use of com.amalto.workbench.detailtabs.sections.model.entity.KeyWrapper in project tmdm-studio-se by Talend.

the class EntityCommitHandler method getNeedRemovedKeys.

private XSDIdentityConstraintDefinition[] getNeedRemovedKeys() {
    List<XSDIdentityConstraintDefinition> curLeftSourceKeys = new ArrayList<XSDIdentityConstraintDefinition>();
    List<XSDIdentityConstraintDefinition> needRemovedKeys = new ArrayList<XSDIdentityConstraintDefinition>();
    for (KeyWrapper eachKeyWrapper : getCommitedObj().getKeys()) {
        if (!eachKeyWrapper.isUserCreated()) {
            curLeftSourceKeys.add(eachKeyWrapper.getSourceKey());
        }
    }
    for (XSDIdentityConstraintDefinition eachSourceKey : getCommitedObj().getSourceEntity().getIdentityConstraintDefinitions()) {
        if (!curLeftSourceKeys.contains(eachSourceKey)) {
            needRemovedKeys.add(eachSourceKey);
        }
    }
    return needRemovedKeys.toArray(new XSDIdentityConstraintDefinition[0]);
}
Also used : KeyWrapper(com.amalto.workbench.detailtabs.sections.model.entity.KeyWrapper) ArrayList(java.util.ArrayList) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition)

Example 3 with KeyWrapper

use of com.amalto.workbench.detailtabs.sections.model.entity.KeyWrapper in project tmdm-studio-se by Talend.

the class EntityCommitHandler method validateEntityKeys.

private void validateEntityKeys() throws CommitValidationException {
    for (KeyWrapper eachKeyWrapper : getCommitedObj().getKeys()) {
        validateEachKey(eachKeyWrapper);
    }
    validateKeyUnique();
    validateDuplicateKeyNameInEntityWrapper();
}
Also used : KeyWrapper(com.amalto.workbench.detailtabs.sections.model.entity.KeyWrapper)

Aggregations

KeyWrapper (com.amalto.workbench.detailtabs.sections.model.entity.KeyWrapper)3 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)2 FieldWrapper (com.amalto.workbench.detailtabs.sections.model.entity.FieldWrapper)1 ArrayList (java.util.ArrayList)1 XSDFactory (org.eclipse.xsd.XSDFactory)1 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)1