/** * Prints out a single relationship. * @param name * @param target */ private void printRelationship(String name, Target target) { String targetStr = target.getValue(); printProperty(name, targetStr); }
/** * Prints out a single relationship. * @param name * @param targets */ private void printRelationship(String name, List<? extends Target> targets) { String targetStr = ""; boolean first = true; for (Target target : targets) { if (!first) { targetStr += ", "; } else { first = false; } targetStr += target.getValue(); } printProperty(name, targetStr); }
private void setRelationship(String relationshipName, RelationshipType relationshipType, Target target) throws Exception { if (target != null && StringUtils.isNotBlank(target.getValue())) { ArtificerRelationship artificerRelationship = createRelationship(relationshipName, relationshipType, Collections.EMPTY_MAP); createTarget(artificerRelationship, target); artificerArtifact.getRelationships().add(artificerRelationship); } }
private void setRelationships(String relationshipName, RelationshipType relationshipType, List<? extends Target> targets, Map<QName, String> relationshipOtherAttributes) throws Exception { if (targets.size() > 0) { ArtificerRelationship artificerRelationship = createRelationship(relationshipName, relationshipType, relationshipOtherAttributes); for (Target target : targets) { if (StringUtils.isNotBlank(target.getValue())) { createTarget(artificerRelationship, target); } } if (!artificerRelationship.getTargets().isEmpty()) { artificerArtifact.getRelationships().add(artificerRelationship); } } }
/** * Sets a relationship on the given artifact parent node. * @param relationshipType * @param maxCardinality * @param minCardinality * @param targetType * @param isGeneric * @param targets * @throws Exception */ private void setRelationships(String relationshipType, int maxCardinality, int minCardinality, String targetType, boolean isGeneric, List<? extends Target> targets) throws Exception { if (!isProcessRelationships()) return; if ((targets != null && targets.size() > 0) || minCardinality == 0) { Node relationshipNode = getOrCreateRelationshipNode(this.jcrNode, relationshipType, maxCardinality, targetType, isGeneric); Value[] values = new Value[targets.size()]; for (int idx = 0; idx < targets.size(); idx++) { values[idx] = this.referenceFactory.createReference(targets.get(idx).getValue()); } relationshipNode.setProperty("sramp:relationshipTarget", values); //$NON-NLS-1$ } else { // If the minimum cardinality is > 0 but no targets have been provided, then // remove the relationship node. removeRelationship(relationshipType); } }
private void createTarget(ArtificerRelationship artificerRelationship, Target target) throws Exception { ArtificerTarget artificerTarget = new ArtificerTarget(); artificerTarget.setTarget(relationshipFactory.createRelationship(target.getValue(), entityManager)); // Use reflection to get the 'artifact type' enum attribute found on // most (all?) targets. Unfortunately, the method and field are // redefined in each subclass of Target. // Get ^^^ changed in the spec! try { Method m = target.getClass().getMethod("getArtifactType"); Object o = m.invoke(target); // the enum itself m = o.getClass().getMethod("name"); String targetType = (String) m.invoke(o); artificerTarget.setTargetType(targetType); } catch (Exception e) { // eat it } artificerTarget.setRelationship(artificerRelationship); for (QName key : target.getOtherAttributes().keySet()) { String value = target.getOtherAttributes().get(key); artificerTarget.getOtherAttributes().put(key.toString(), value); } artificerRelationship.getTargets().add(artificerTarget); } }
/** * Sets a relationship on the given artifact parent node. * @param relationshipType * @param maxCardinality * @param minCardinality * @param targetType * @param isGeneric * @param target * @throws Exception */ private void setRelationship(String relationshipType, int maxCardinality, int minCardinality, String targetType, boolean isGeneric, Target target) throws Exception { if (!isProcessRelationships()) return; if (target != null || minCardinality == 0) { Node relationshipNode = getOrCreateRelationshipNode(this.jcrNode, relationshipType, maxCardinality, targetType, isGeneric); Value [] values = new Value[1]; values[0] = this.referenceFactory.createReference(target.getValue()); relationshipNode.setProperty("sramp:relationshipTarget", values); //$NON-NLS-1$ } else { // If the minimum cardinality is > 0 but no targets have been provided, then // remove the relationship node. removeRelationship(relationshipType); } }
/** * Gets an artifact by a {@link Target}. * @param target * @throws Exception */ private BaseArtifactType getArtifactByTarget(Target target) throws Exception { Assert.assertNotNull("Missing target/relationship.", target); //$NON-NLS-1$ return getArtifactByUUID(target.getValue()); }
/** * Gets an artifact by a {@link Target}. * @param target * @throws Exception */ private BaseArtifactType getArtifactByTarget(Target target) throws Exception { Assert.assertNotNull("Missing target/relationship.", target); //$NON-NLS-1$ return getArtifactByUUID(target.getValue()); }
if (targetArtifactUuid.equals(target.getValue())) { targetFound = true; break;
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()); expected.add(uuid2); expected.add(uuid3); actual.add(relationship.getRelationshipTarget().get(0).getValue()); actual.add(relationship.getRelationshipTarget().get(1).getValue()); Assert.assertEquals(expected, actual);
Assert.assertNotNull(relationship.getRelationshipTarget()); Assert.assertFalse(relationship.getRelationshipTarget().isEmpty()); Assert.assertEquals(orderServiceComponent.getUuid(), relationship.getRelationshipTarget().iterator().next().getValue());