/** * 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; }
@Override protected void visitExtended(ExtendedArtifactType artifact) { // override the type with extendedType artificerArtifact.setType(artifact.getExtendedType()); }
/** * @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); }
@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$ }
/** * 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); } }
/** * Create an instance of {@link ExtendedArtifactType } * */ public ExtendedArtifactType createExtendedArtifactType() { return new ExtendedArtifactType(); }
name = componentSvc.getAttribute("name"); //$NON-NLS-1$ ExtendedArtifactType componentServiceArtifact = SwitchYardModel.newComponentServiceArtifact(name); componentServiceArtifact.setUuid(UUID.randomUUID().toString()); derivedArtifacts.add(componentServiceArtifact); SrampModelUtils.addGenericRelationship(componentArtifact, SwitchYardModel.REL_OFFERS, componentServiceArtifact.getUuid());
/** * 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$ } }
/** * Create an instance of {@link ExtendedArtifactType } * */ public ExtendedArtifactType createExtendedArtifactType() { return new ExtendedArtifactType(); }
/** * @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; }
/** * @see org.overlord.sramp.common.visitors.HierarchicalArtifactVisitorAdapter#visit(org.oasis_open.docs.s_ramp.ns.s_ramp_v1.ExtendedArtifactType) */ @Override public void visit(ExtendedArtifactType artifact) { super.visit(artifact); try { if (artifact.getExtendedType() != null) setProperty(JCRConstants.SRAMP_EXTENDED_TYPE, artifact.getExtendedType()); } catch (Exception e) { error = e; } }
/** * @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 + ""); }
/** * @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$ } }
/** * Visits a switchyard artifact. * @param artifact * @param visitor */ public static final void visitArtifact(ExtendedArtifactType artifact, SwitchYardArtifactVisitor visitor) { if (SwitchYardModel.SwitchYardService.equals(artifact.getExtendedType())) { visitor.visitService(artifact); } else if (SwitchYardModel.SwitchYardComponent.equals(artifact.getExtendedType())) { visitor.visitComponent(artifact); } else if (SwitchYardModel.SwitchYardComponentService.equals(artifact.getExtendedType())) { visitor.visitComponentService(artifact); } else if (SwitchYardModel.SwitchYardTransformer.equals(artifact.getExtendedType())) { visitor.visitTransformer(artifact); } else if (SwitchYardModel.SwitchYardValidator.equals(artifact.getExtendedType())) { visitor.visitValidator(artifact); } else { throw new RuntimeException(Messages.i18n.format("VISITOR_NOT_IMPLEMENTED", artifact.getExtendedType())); //$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$ }
/** * @see org.overlord.sramp.common.visitors.ArtifactVisitorAdapter#visit(org.oasis_open.docs.s_ramp.ns.s_ramp_v1.ExtendedArtifactType) */ @SuppressWarnings("unchecked") @Override public void visit(ExtendedArtifactType artifact) { super.visit(artifact); if (this.atomEntry != null) { String extendedType = artifact.getExtendedType(); this.atomEntry.getExtensionAttributes().put(SrampConstants.SRAMP_EXTENDED_TYPE_QNAME, extendedType); } }
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$ try { persistenceManager.persistArtifact(document, pdf);
/** * @param artifact the artifact being checked (cannot be <code>null</code>) * @param extendedType the expected extended type (cannot be <code>null</code>) * @return <code>true</code> if the artifact is an {@link ExtendedArtifactType} with the specified extended type */ protected boolean isExtendedType( final BaseArtifactType artifact, final TeiidExtendedType extendedType ) { assert (artifact != null); assert (extendedType != null); if (artifact instanceof ExtendedArtifactType) { return extendedType.extendedType().equals(((ExtendedArtifactType)artifact).getExtendedType()); } return false; }
try { archive = new SrampArchive(); ExtendedArtifactType nonDocArtifact = new ExtendedArtifactType(); nonDocArtifact.setArtifactType(BaseArtifactEnum.EXTENDED_ARTIFACT_TYPE); nonDocArtifact.setExtendedType("TestArtifact"); //$NON-NLS-1$ nonDocArtifact.setName("My Test Artifact"); //$NON-NLS-1$
String extendedType = ((ExtendedArtifactType) artifact).getExtendedType(); artifactType.setExtendedType(extendedType); } else if (artifactType.getArtifactType() == ArtifactTypeEnum.ExtendedDocument) { .getExtendedType() : ((ExtendedDocument) artifact).getExtendedType(); String extendedDerived = artifact.getOtherAttributes().get(SrampConstants.SRAMP_DERIVED_QNAME); artifactType.setExtendedType(extendedType);