private void fixAssociations( String path, String type, boolean isSource, boolean isTarget, Association[] toAdd) throws RegistryException { final String SEPARATOR = ":"; // Get the existing association list which is related to the current operation Set<String> existingSet = new HashSet<String>(); for (Association association : registry.getAllAssociations(path)) { if (type.equals(association.getAssociationType()) && ((isSource && association.getSourcePath().equals(path)) || (isTarget && association.getDestinationPath().equals(path)))) { existingSet.add( association.getSourcePath() + SEPARATOR + association.getDestinationPath() + SEPARATOR + association.getAssociationType()); } } // Get the updated association list from the projectGroup object Set<String> updatedSet = new HashSet<String>(); for (Association association : toAdd) { updatedSet.add( association.getSourcePath() + SEPARATOR + association.getDestinationPath() + SEPARATOR + association.getAssociationType()); } Set<String> removedAssociations = new HashSet<String>(existingSet); removedAssociations.removeAll(updatedSet); Set<String> newAssociations = new HashSet<String>(updatedSet); newAssociations.removeAll(existingSet); for (String removedAssociation : removedAssociations) { String[] params = removedAssociation.split(SEPARATOR); registry.removeAssociation(params[0], params[1], params[2]); } for (String newAssociation : newAssociations) { String[] params = newAssociation.split(SEPARATOR); registry.addAssociation(params[0], params[1], params[2]); } }
public boolean associationSourcepathExists(String path, String sourcePath) throws Exception { Association association[] = registry.getAllAssociations(path); boolean value = false; for (Association anAssociation : association) { anAssociation.getAssociationType(); if (sourcePath.equals(anAssociation.getSourcePath())) { value = true; } } return value; }
private void addRelationships(String path, GovernanceArtifact artifact) throws RegistryException { Map<String, AssociationInteger> typeMap = new LinkedHashMap<String, AssociationInteger>(); for (Association relationship : relationshipDefinitions) { String type = relationship.getAssociationType(); String source = relationship.getSourcePath(); String target = relationship.getDestinationPath(); if (typeMap.containsKey(type)) { AssociationInteger associationInteger = typeMap.get(type); if (source == null) { if (associationInteger.getInteger() < 0) { associationInteger.setInteger(0); } for (String targetPath : GovernanceUtils.getPathsFromPathExpression(target, artifact)) { associationInteger.getAssociations().add(new Association(path, targetPath, type)); } } else if (target == null) { if (associationInteger.getInteger() > 0) { associationInteger.setInteger(0); } for (String sourcePath : GovernanceUtils.getPathsFromPathExpression(source, artifact)) { associationInteger.getAssociations().add(new Association(sourcePath, path, type)); } } } else { AssociationInteger associationInteger = new AssociationInteger(); if (source == null) { associationInteger.setInteger(1); for (String targetPath : GovernanceUtils.getPathsFromPathExpression(target, artifact)) { associationInteger.getAssociations().add(new Association(path, targetPath, type)); } } else if (target == null) { associationInteger.setInteger(-1); for (String sourcePath : GovernanceUtils.getPathsFromPathExpression(source, artifact)) { associationInteger.getAssociations().add(new Association(sourcePath, path, type)); } } typeMap.put(type, associationInteger); } } for (Map.Entry<String, AssociationInteger> e : typeMap.entrySet()) { AssociationInteger value = e.getValue(); List<Association> associations = value.getAssociations(); fixAssociations( path, e.getKey(), value.getInteger() >= 0, value.getInteger() <= 0, associations.toArray(new Association[associations.size()])); } }
public boolean getAssocitionbySourceByType(String path, String type) throws Exception { Association[] asso; asso = registry.getAssociations(path, type); boolean assoFound = false; if (asso == null) { return assoFound; } for (Association a2 : asso) { if (a2.getSourcePath().equals(path)) { assoFound = true; break; } } return assoFound; }