/** * @see org.overlord.sramp.common.visitors.HierarchicalArtifactVisitorAdapter#visitExtended(org.oasis_open.docs.s_ramp.ns.s_ramp_v1.ExtendedArtifactType) */ @Override protected void visitExtended(ExtendedArtifactType artifact) { String extendedType = getProperty(jcrNode, "sramp:extendedType"); //$NON-NLS-1$ String extendedDerived = getProperty(jcrNode, "sramp:derived", "false"); //$NON-NLS-1$ //$NON-NLS-2$ artifact.setExtendedType(extendedType); artifact.getOtherAttributes().put(SrampConstants.SRAMP_DERIVED_QNAME, extendedDerived); }
/** * @param extendedType the extended artifact type of the artifact to create (cannot be <code>null</code> or empty) * @return the created artifact (never <code>null</code>) */ private static BaseArtifactType create( final TeiidExtendedType extendedType ) { final ExtendedArtifactType artifact = new ExtendedArtifactType(); artifact.setArtifactType(BaseArtifactEnum.EXTENDED_ARTIFACT_TYPE); artifact.setExtendedType(extendedType.extendedType()); artifact.setUuid(UUID.randomUUID().toString()); return artifact; }
/** * Creates a new extended artifact type for a SwitchYard artifact. * @param name */ private static final ExtendedArtifactType newArtifact(String switchYardType, String name) { ExtendedArtifactType artifact = new ExtendedArtifactType(); artifact.setArtifactType(BaseArtifactEnum.EXTENDED_ARTIFACT_TYPE); artifact.setExtendedType(switchYardType); artifact.setUuid(UUID.randomUUID().toString()); artifact.setName(name); return artifact; }
/** * @see org.artificer.common.visitors.HierarchicalArtifactVisitor#visitExtended(org.oasis_open.docs.s_ramp.ns.s_ramp_v1.ExtendedArtifactType) */ @Override protected void visitExtended(ExtendedArtifactType artifact) { super.visitExtended(artifact); String extendedType = artificerArtifact.getType(); boolean extendedDerived = artificerArtifact.isDerived(); artifact.setExtendedType(extendedType); artifact.getOtherAttributes().put(ArtificerConstants.SRAMP_DERIVED_QNAME, extendedDerived + ""); }
/** * Instantiates an S-RAMP artifact of the correct type, and populates the artifactType and the * contentType. * @param artifactType */ public BaseArtifactType newArtifactInstance() { try { BaseArtifactType baseArtifactType = getArtifactType().getTypeClass().newInstance(); baseArtifactType.setArtifactType(getArtifactType().getApiType()); if (DocumentArtifactType.class.isAssignableFrom(baseArtifactType.getClass())) { ((DocumentArtifactType) baseArtifactType).setContentType(getMimeType()); } if (getArtifactType() == ArtifactTypeEnum.ExtendedArtifactType) { baseArtifactType.getOtherAttributes().put(ArtificerConstants.SRAMP_CONTENT_TYPE_QNAME, getMimeType()); ((ExtendedArtifactType) baseArtifactType).setExtendedType(getExtendedType()); } if (getArtifactType() == ArtifactTypeEnum.ExtendedDocument) { baseArtifactType.getOtherAttributes().put(ArtificerConstants.SRAMP_CONTENT_TYPE_QNAME, getMimeType()); ((ExtendedDocument) baseArtifactType).setExtendedType(getExtendedType()); } return baseArtifactType; } catch (Exception e) { throw new RuntimeException(Messages.i18n.format("ARTIFACT_INSTANTIATION_ERROR", getArtifactType().getTypeClass()), e); } }
/** * Instantiates an S-RAMP artifact of the correct type, and populates the artifactType and the * contentType. * @param artifactType */ public BaseArtifactType newArtifactInstance() { try { BaseArtifactType baseArtifactType = getArtifactType().getTypeClass().newInstance(); baseArtifactType.setArtifactType(getArtifactType().getApiType()); if (DocumentArtifactType.class.isAssignableFrom(baseArtifactType.getClass())) { ((DocumentArtifactType) baseArtifactType).setContentType(getMimeType()); } if (getArtifactType() == ArtifactTypeEnum.ExtendedArtifactType) { baseArtifactType.getOtherAttributes().put(SrampConstants.SRAMP_CONTENT_TYPE_QNAME, getMimeType()); ((ExtendedArtifactType) baseArtifactType).setExtendedType(getExtendedType()); } if (getArtifactType() == ArtifactTypeEnum.ExtendedDocument) { baseArtifactType.getOtherAttributes().put(SrampConstants.SRAMP_CONTENT_TYPE_QNAME, getMimeType()); ((ExtendedDocument) baseArtifactType).setExtendedType(getExtendedType()); } return baseArtifactType; } catch (Exception e) { throw new RuntimeException(Messages.i18n.format("ARTIFACT_INSTANTIATION_ERROR", getArtifactType().getTypeClass()), e); //$NON-NLS-1$ } }
/** * @param derivedArtifacts * @param artifact * @param rootElement * @param xpath * @throws XPathExpressionException */ private void processRoot(Collection<BaseArtifactType> derivedArtifacts, BaseArtifactType artifact, Element rootElement, XPath xpath) throws XPathExpressionException { NodeList nodes = (NodeList) this.query(xpath, rootElement, "./credit", XPathConstants.NODESET); //$NON-NLS-1$ for (int idx = 0; idx < nodes.getLength(); idx++) { Element node = (Element) nodes.item(idx); ExtendedArtifactType credit = new ExtendedArtifactType(); credit.setArtifactType(BaseArtifactEnum.EXTENDED_ARTIFACT_TYPE); credit.setUuid(UUID.randomUUID().toString()); String type = node.getAttribute("type"); //$NON-NLS-1$ String name = node.getAttribute("name"); //$NON-NLS-1$ String part = node.getAttribute("part"); //$NON-NLS-1$ String year = node.getAttribute("year"); //$NON-NLS-1$ credit.setExtendedType(StringUtils.capitalize(type) + "Credit"); //$NON-NLS-1$ credit.setName(name); SrampModelUtils.setCustomProperty(credit, "part", part); //$NON-NLS-1$ SrampModelUtils.setCustomProperty(credit, "year", year); //$NON-NLS-1$ derivedArtifacts.add(credit); // Set a relationship from original artifact to the listener credit.setUuid(UUID.randomUUID().toString()); SrampModelUtils.addGenericRelationship(artifact, "hasCredit", credit.getUuid()); //$NON-NLS-1$ } }
@Test public void testPersistArtifact_ExtendedArtifactType() throws Exception { ExtendedArtifactType extendedArtifact = new ExtendedArtifactType(); extendedArtifact.setArtifactType(BaseArtifactEnum.EXTENDED_ARTIFACT_TYPE); extendedArtifact.setExtendedType("FooArtifactType"); //$NON-NLS-1$ extendedArtifact.setName("MyExtendedArtifact"); //$NON-NLS-1$ extendedArtifact.setDescription("This is a simple description for testing."); //$NON-NLS-1$ BaseArtifactType artifact = persistenceManager.persistArtifact(extendedArtifact, null); Assert.assertNotNull(artifact); log.info("persisted extended artifact to JCR, returned artifact uuid=" + artifact.getUuid()); //$NON-NLS-1$ //print out the derived node if (log.isDebugEnabled()) { persistenceManager.printArtifactGraph(artifact.getUuid(), ArtifactType.XmlDocument()); } Assert.assertEquals(ExtendedArtifactType.class, artifact.getClass()); String name = ((ExtendedArtifactType) artifact).getName(); String description = ((ExtendedArtifactType) artifact).getDescription(); Assert.assertEquals("MyExtendedArtifact", name); //$NON-NLS-1$ Assert.assertEquals("This is a simple description for testing.", description); //$NON-NLS-1$ }
ExtendedArtifactType extendedArtifact = new ExtendedArtifactType(); extendedArtifact.setArtifactType(BaseArtifactEnum.EXTENDED_ARTIFACT_TYPE); extendedArtifact.setExtendedType("FooArtifactType"); //$NON-NLS-1$ extendedArtifact.setName("MyExtendedArtifact"); //$NON-NLS-1$ extendedArtifact.setUuid("12345"); //$NON-NLS-1$
/** * Test method for {@link SrampAtomApiClient#createArtifact(BaseArtifactType)}. */ @Test public void testCreateArtifact() throws Exception { ExtendedArtifactType artifact = new ExtendedArtifactType(); artifact.setArtifactType(BaseArtifactEnum.EXTENDED_ARTIFACT_TYPE); artifact.setExtendedType("TestArtifact"); //$NON-NLS-1$ artifact.setName("My Test Artifact"); //$NON-NLS-1$ artifact.setDescription("Description of my test artifact."); //$NON-NLS-1$ SrampAtomApiClient client = new SrampAtomApiClient(generateURL("/s-ramp")); //$NON-NLS-1$ BaseArtifactType createdArtifact = client.createArtifact(artifact); Assert.assertNotNull(artifact); Assert.assertEquals("My Test Artifact", createdArtifact.getName()); //$NON-NLS-1$ Assert.assertEquals("Description of my test artifact.", createdArtifact.getDescription()); //$NON-NLS-1$ }
ExtendedArtifactType nonDocArtifact = new ExtendedArtifactType(); nonDocArtifact.setArtifactType(BaseArtifactEnum.EXTENDED_ARTIFACT_TYPE); nonDocArtifact.setExtendedType("TestArtifact"); //$NON-NLS-1$ nonDocArtifact.setName("My Test Artifact"); //$NON-NLS-1$