/** * Updates the generic artifact relationships. * @param artifact * @throws Exception */ private void updateGenericRelationships(BaseArtifactType artifact) throws Exception { for (Relationship relationship : artifact.getRelationship()) { if (relationship.getRelationshipTarget().size() > 0) { setRelationships(relationship.getRelationshipType(), RelationshipType.GENERIC, relationship.getRelationshipTarget(), relationship.getOtherAttributes()); } } }
/** * Updates the generic artifact relationships. * @param artifact * @throws RepositoryException */ private void updateGenericRelationships(BaseArtifactType artifact) throws Exception { // Create/Update all the relationships included in the artifact Set<String> updatedRelationshipTypes = new HashSet<String>(); for (Relationship relationship : artifact.getRelationship()) { setRelationships(relationship.getRelationshipType(), -1, 0, null, true, relationship.getRelationshipTarget()); updatedRelationshipTypes.add(relationship.getRelationshipType()); } // Now remove any relationships that weren't just updated or created (the ones // not included on the artifact but that have existing JCR nodes). NodeIterator existingNodes = this.jcrNode.getNodes(); while (existingNodes.hasNext()) { Node node = existingNodes.nextNode(); // Only roemove generic relationships if (node.isNodeType("sramp:relationship") && node.hasProperty("sramp:generic") //$NON-NLS-1$ //$NON-NLS-2$ && node.getProperty("sramp:generic").getBoolean()) { //$NON-NLS-1$ String type = node.getProperty("sramp:relationshipType").getString(); //$NON-NLS-1$ // If this relationship type was *not* updated above, then remove it because // it's not included in the latest artifact meta-data if (!updatedRelationshipTypes.contains(type)) { node.remove(); } } } }
/** * @see org.overlord.sramp.integration.switchyard.model.SwitchYardArtifactVisitor#visitService(org.oasis_open.docs.s_ramp.ns.s_ramp_v1.ExtendedArtifactType) */ @Override public void visitService(ExtendedArtifactType artifact) { // Handle unresolved "implements" relationships Relationship relationship = SrampModelUtils.getGenericRelationship(artifact, SwitchYardModel.REL_IMPLEMENTS); if (relationship != null && relationship.getOtherAttributes().containsKey(SwitchYardXmlDeriver.UNRESOLVED_REF)) { String ref = relationship.getOtherAttributes().remove(SwitchYardXmlDeriver.UNRESOLVED_REF); if (ref.startsWith("java:")) { //$NON-NLS-1$ String refInterfaceName = ref.substring(5); BaseArtifactType artifactRef = findJavaInterfaceArtifact(refInterfaceName); if (artifactRef != null) { Target target = new Target(); target.setValue(artifactRef.getUuid()); relationship.getRelationshipTarget().add(target); } } else if (ref.startsWith("wsdl:")) { //$NON-NLS-1$ String refWsdl = ref.substring(5); BaseArtifactType artifactRef = findWsdlArtifact(refWsdl); if (artifactRef != null) { Target target = new Target(); target.setValue(artifactRef.getUuid()); relationship.getRelationshipTarget().add(target); } } } }
/** * @see org.overlord.sramp.integration.switchyard.model.SwitchYardArtifactVisitor#visitComponentService(org.oasis_open.docs.s_ramp.ns.s_ramp_v1.ExtendedArtifactType) */ @Override public void visitComponentService(ExtendedArtifactType artifact) { // Handle unresolved "implements" relationships Relationship relationship = SrampModelUtils.getGenericRelationship(artifact, SwitchYardModel.REL_IMPLEMENTS); if (relationship != null && relationship.getOtherAttributes().containsKey(SwitchYardXmlDeriver.UNRESOLVED_REF)) { String ref = relationship.getOtherAttributes().remove(SwitchYardXmlDeriver.UNRESOLVED_REF); if (ref.startsWith("java:")) { //$NON-NLS-1$ String refInterfaceName = ref.substring(5); BaseArtifactType artifactRef = findJavaInterfaceArtifact(refInterfaceName); if (artifactRef != null) { Target target = new Target(); target.setValue(artifactRef.getUuid()); relationship.getRelationshipTarget().add(target); } } else if (ref.startsWith("wsdl:")) { //$NON-NLS-1$ String refWsdl = ref.substring(5); BaseArtifactType artifactRef = findWsdlArtifact(refWsdl); if (artifactRef != null) { Target target = new Target(); target.setValue(artifactRef.getUuid()); relationship.getRelationshipTarget().add(target); } } } }
/** * @see org.overlord.sramp.common.visitors.HierarchicalArtifactVisitorAdapter#visitBase(org.oasis_open.docs.s_ramp.ns.s_ramp_v1.BaseArtifactType) */ @Override protected void visitBase(BaseArtifactType artifact) { List<Relationship> relationships = artifact.getRelationship(); if (relationships != null) { for (Relationship relationship : relationships) { String type = relationship.getRelationshipType(); List<Target> targets = relationship.getRelationshipTarget(); visitRelationships(type, targets); } } super.visitBase(artifact); }
/** * @see HierarchicalArtifactVisitor#visitBase(org.oasis_open.docs.s_ramp.ns.s_ramp_v1.BaseArtifactType) */ @Override protected void visitBase(BaseArtifactType artifact) { // expansion String archiveUuid = artifact.getOtherAttributes().get(ArtificerConstants.ARTIFICER_EXPANDED_FROM_ARCHIVE_UUID_QNAME); if (StringUtils.isNotBlank(archiveUuid)) { visitRelationship("expandedFromArchive", archiveUuid, false); } List<Relationship> relationships = artifact.getRelationship(); if (relationships != null) { for (Relationship relationship : relationships) { String type = relationship.getRelationshipType(); List<Target> targets = relationship.getRelationshipTarget(); visitRelationships(type, targets, true); } } super.visitBase(artifact); }
Target target = new Target(); target.setValue(artifactRef.getUuid()); relationship.getRelationshipTarget().add(target); Target target = new Target(); target.setValue(artifactRef.getUuid()); relationship.getRelationshipTarget().add(target); Target target = new Target(); target.setValue(artifactRef.getUuid()); relationship.getRelationshipTarget().add(target);
Target target = new Target(); target.setValue(artifactRef.getUuid()); relationship.getRelationshipTarget().add(target); Target target = new Target(); target.setValue(artifactRef.getUuid()); relationship.getRelationshipTarget().add(target); Target target = new Target(); target.setValue(artifactRef.getUuid()); relationship.getRelationshipTarget().add(target); Target target = new Target(); target.setValue(artifactRef.getUuid()); relationship.getRelationshipTarget().add(target);
target.setValue(targetUUID); target.getOtherAttributes().putAll(targetOtherAttributes); relationship.getRelationshipTarget().add(target);
/** * Adds a new generic {@link Relationship} to the artifact. * @param artifact * @param relationshipType * @param targetUUID * @return the created {@link Relationship} */ public static Relationship addGenericRelationship(BaseArtifactType artifact, String relationshipType, String targetUUID) { Relationship relationship = null; for (Relationship r : artifact.getRelationship()) { if (r.getRelationshipType().equals(relationshipType)) { relationship = r; break; } } if (relationship == null) { relationship = new Relationship(); relationship.setRelationshipType(relationshipType); artifact.getRelationship().add(relationship); } // TODO check for duplicates first? if (targetUUID != null) { Target target = new Target(); target.setValue(targetUUID); relationship.getRelationshipTarget().add(target); } return relationship; }
Target target = new Target(); target.setValue(artifactRef.getUuid()); relationship.getRelationshipTarget().add(target); Target target = new Target(); target.setValue(artifactRef.getUuid()); relationship.getRelationshipTarget().add(target); Target target = new Target(); target.setValue(artifactRef.getUuid()); relationship.getRelationshipTarget().add(target); Target target = new Target(); target.setValue(artifactRef.getUuid()); relationship.getRelationshipTarget().add(target); Target target = new Target(); target.setValue(artifactRef.getUuid()); relationship.getRelationshipTarget().add(target); Target target = new Target(); target.setValue(artifactRef.getUuid()); relationship.getRelationshipTarget().add(target); Target target = new Target(); target.setValue(artifactRef.getUuid()); relationship.getRelationshipTarget().add(target); Target target = new Target();
private void visitGenericRelationships(BaseArtifactType srampArtifact) throws Exception { for (ArtificerRelationship artificerRelationship : artificerArtifact.getRelationships()) { if (artificerRelationship.getType() == RelationshipType.GENERIC) { Relationship srampRelationship = new Relationship(); srampRelationship.setRelationshipType(artificerRelationship.getName()); for (ArtificerTarget artificerTarget : artificerRelationship.getTargets()) { Target srampTarget = createTarget(Target.class, artificerTarget); srampRelationship.getRelationshipTarget().add(srampTarget); } setOtherAttributes(artificerRelationship.getOtherAttributes(), srampRelationship.getOtherAttributes()); srampArtifact.getRelationship().add(srampRelationship); } } }
Target target = new Target(); target.setValue(targetUUID); relationship.getRelationshipTarget().add(target);
if (relationship.getRelationshipType().equals(relationshipType.relationshipType())) { relationshipFound = true; final List<Target> targets = relationship.getRelationshipTarget();
new QName("xlink:href"), "http://example.org/s-ramp/xsd/XsdDocument/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaa6b"); relationship.getRelationshipTarget().add(relationshipTarget); new QName("xlink:href"), "http://example.org/s-ramp/xsd/XsdDocument/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaa6c"); relationship.getRelationshipTarget().add(relationshipTarget2); xsdDocument.getRelationship().add(relationship);
Assert.assertEquals("Expected 1 relationship.", 1, artifact.getRelationship().size()); //$NON-NLS-1$ Assert.assertEquals("NoTargetRelationship", artifact.getRelationship().get(0).getRelationshipType()); //$NON-NLS-1$ Assert.assertEquals(Collections.EMPTY_LIST, artifact.getRelationship().get(0).getRelationshipTarget()); Assert.assertNotNull(relationship); Assert.assertEquals("NoTargetRelationship", relationship.getRelationshipType()); //$NON-NLS-1$ Assert.assertEquals(Collections.EMPTY_LIST, relationship.getRelationshipTarget()); relationship = SrampModelUtils.getGenericRelationship(artifact, "TargetedRelationship"); //$NON-NLS-1$ Assert.assertNotNull(relationship); Assert.assertEquals("TargetedRelationship", relationship.getRelationshipType()); //$NON-NLS-1$ Assert.assertEquals(1, relationship.getRelationshipTarget().size()); // has only one target Assert.assertEquals(uuid2, relationship.getRelationshipTarget().get(0).getValue()); Assert.assertNotNull(relationship); Assert.assertEquals("NoTargetRelationship", relationship.getRelationshipType()); //$NON-NLS-1$ Assert.assertEquals(Collections.EMPTY_LIST, relationship.getRelationshipTarget()); relationship = SrampModelUtils.getGenericRelationship(artifact, "TargetedRelationship"); //$NON-NLS-1$ Assert.assertNotNull(relationship); Assert.assertEquals("TargetedRelationship", relationship.getRelationshipType()); //$NON-NLS-1$ Assert.assertEquals(2, relationship.getRelationshipTarget().size()); Set<String> expected = new HashSet<String>(); Set<String> actual = new HashSet<String>(); expected.add(uuid2); expected.add(uuid3); actual.add(relationship.getRelationshipTarget().get(0).getValue()); actual.add(relationship.getRelationshipTarget().get(1).getValue()); Assert.assertEquals(expected, actual);
commandInvocation.getShell().out().println(Messages.i18n.format("PrintArtifact.GenericRelationshipsHeading")); for (Relationship relationship : artifact.getRelationship()) { List<Target> targets = relationship.getRelationshipTarget(); printRelationship(relationship.getRelationshipType(), targets);
relationship = SrampModelUtils.getGenericRelationship(inventoryServiceComponent, SwitchYardModel.REL_IMPLEMENTED_BY); Assert.assertNotNull(relationship); Assert.assertTrue(relationship.getRelationshipTarget().isEmpty()); Assert.assertTrue(relationship.getOtherAttributes().containsKey(SwitchYardXmlDeriver.UNRESOLVED_REF)); relationship = SrampModelUtils.getGenericRelationship(inventoryServiceComponent, SwitchYardModel.REL_REFERENCES); relationship = SrampModelUtils.getGenericRelationship(orderServiceComponent, SwitchYardModel.REL_IMPLEMENTED_BY); Assert.assertNotNull(relationship); Assert.assertTrue(relationship.getRelationshipTarget().isEmpty()); Assert.assertTrue(relationship.getOtherAttributes().containsKey(SwitchYardXmlDeriver.UNRESOLVED_REF)); relationship = SrampModelUtils.getGenericRelationship(orderServiceComponent, SwitchYardModel.REL_REFERENCES); Assert.assertNotNull(relationship); Assert.assertTrue(relationship.getRelationshipTarget().isEmpty()); Assert.assertTrue(relationship.getOtherAttributes().containsKey(SwitchYardXmlDeriver.UNRESOLVED_REF)); relationship = SrampModelUtils.getGenericRelationship(orderService, SwitchYardModel.REL_PROMOTES); Assert.assertNotNull(relationship); Assert.assertNotNull(relationship.getRelationshipTarget()); Assert.assertFalse(relationship.getRelationshipTarget().isEmpty()); Assert.assertEquals(orderServiceComponent.getUuid(), relationship.getRelationshipTarget().iterator().next().getValue()); relationship = SrampModelUtils.getGenericRelationship(camelServiceComponent, SwitchYardModel.REL_IMPLEMENTED_BY); Assert.assertNotNull(relationship); Assert.assertTrue(relationship.getRelationshipTarget().isEmpty()); Assert.assertTrue(relationship.getOtherAttributes().containsKey(SwitchYardXmlDeriver.UNRESOLVED_REF)); relationship = SrampModelUtils.getGenericRelationship(camelServiceComponent, SwitchYardModel.REL_REFERENCES); relationship = SrampModelUtils.getGenericRelationship(transformJava, SwitchYardModel.REL_IMPLEMENTED_BY); Assert.assertNotNull(relationship); Assert.assertTrue(relationship.getRelationshipTarget().isEmpty());