/** * @see java.util.LinkedList#add(java.lang.Object) */ @Override public boolean add(BaseArtifactType artifact) { // Pre-set the UUIDs for all the derived artifacts. This is useful // if something downstream needs to reference them. if (StringUtils.isBlank(artifact.getUuid())) { artifact.setUuid(UUID.randomUUID().toString()); } indexArtifact(artifact); return super.add(artifact); }
/** * Creates a one way relationship. Creates the relationship instance if necessary. * * @param sourceArtifact the artifact where the relationship starts (cannot be <code>null</code>) * @param targetArtifact the artifact where the relationship ends (cannot be <code>null</code>) * @param relationshipType the relationship type (cannot be <code>null</code> or empty) */ public static void addRelationship( final BaseArtifactType sourceArtifact, final BaseArtifactType targetArtifact, final TeiidRelationshipType relationshipType ) { SrampModelUtils.addGenericRelationship(sourceArtifact, relationshipType.relationshipType(), targetArtifact.getUuid()); }
/** * Creates a two way relationship. Creates the relationship instances if necessary. * * @param sourceArtifact the artifact where the relationship starts (cannot be <code>null</code>) * @param targetArtifact the artifact where the relationship ends (cannot be <code>null</code>) * @param relationshipType the relationship type (cannot be <code>null</code> or empty) * @param inverseRelationshipType the relationship type of the inverse relationship (cannot be <code>null</code> or empty) */ public static void addTwoWayRelationship( final BaseArtifactType sourceArtifact, final BaseArtifactType targetArtifact, final TeiidRelationshipType relationshipType, final TeiidRelationshipType inverseRelationshipType ) { SrampModelUtils.addGenericRelationship(sourceArtifact, relationshipType.relationshipType(), targetArtifact.getUuid()); SrampModelUtils.addGenericRelationship(targetArtifact, inverseRelationshipType.relationshipType(), sourceArtifact.getUuid()); }
/** * @see org.overlord.sramp.repository.DerivedArtifacts#linkArtifacts(org.overlord.sramp.common.derived.LinkerContext, org.oasis_open.docs.s_ramp.ns.s_ramp_v1.BaseArtifactType, java.util.Collection) */ @Override public void linkArtifacts(LinkerContext context, BaseArtifactType sourceArtifact, Collection<BaseArtifactType> derivedArtifacts) throws SrampException { try { ArtifactDeriver deriver = ArtifactDeriverFactory.createArtifactDeriver(ArtifactType.valueOf(sourceArtifact)); deriver.link(context, sourceArtifact, derivedArtifacts); log.debug(Messages.i18n.format("SUCCESSFUL_LINKAGE", derivedArtifacts.size(), sourceArtifact.getUuid())); //$NON-NLS-1$ } catch (Exception e) { throw new SrampServerException(e); } }
/** * @see org.overlord.sramp.repository.DerivedArtifacts#deriveArtifacts(org.oasis_open.docs.s_ramp.ns.s_ramp_v1.BaseArtifactType, java.io.InputStream) */ @Override public Collection<BaseArtifactType> deriveArtifacts(BaseArtifactType sourceArtifact, InputStream sourceArtifactContent) throws SrampException { try { ArtifactDeriver deriver = ArtifactDeriverFactory.createArtifactDeriver(ArtifactType.valueOf(sourceArtifact)); Collection<BaseArtifactType> derivedArtifacts = deriver.derive(sourceArtifact, sourceArtifactContent); log.debug(Messages.i18n.format("SUCCESSFUL_DERIVATION", derivedArtifacts.size(), sourceArtifact.getUuid())); //$NON-NLS-1$ return derivedArtifacts; } catch (IOException e) { throw new SrampServerException(e); } }
/** * @see org.overlord.sramp.common.visitors.ArtifactVisitorAdapter#visit(org.oasis_open.docs.s_ramp.ns.s_ramp_v1.OperationOutput) */ @Override public void visit(OperationOutput artifact) { super.visit(artifact); MessageTarget message = artifact.getMessage(); if (message != null && message.getOtherAttributes().containsKey(WsdlDeriver.UNRESOLVED_REF)) { String encodedRef = message.getOtherAttributes().remove(WsdlDeriver.UNRESOLVED_REF); QName ref = QName.valueOf(encodedRef); BaseArtifactType artifactRef = findArtifact(ArtifactTypeEnum.Message, ref); if (artifactRef != null) { message.setValue(artifactRef.getUuid()); } else { artifact.setMessage(null); } } }
/** * @see org.overlord.sramp.common.visitors.ArtifactVisitorAdapter#visit(org.oasis_open.docs.s_ramp.ns.s_ramp_v1.Port) */ @Override public void visit(Port artifact) { super.visit(artifact); BindingTarget binding = artifact.getBinding(); if (binding != null && binding.getOtherAttributes().containsKey(WsdlDeriver.UNRESOLVED_REF)) { String encodedRef = binding.getOtherAttributes().remove(WsdlDeriver.UNRESOLVED_REF); QName ref = QName.valueOf(encodedRef); BaseArtifactType artifactRef = findArtifact(ArtifactTypeEnum.Binding, ref); if (artifactRef != null) { binding.setValue(artifactRef.getUuid()); } else { artifact.setBinding(null); } } }
/** * @see org.overlord.sramp.common.visitors.ArtifactVisitorAdapter#visit(org.oasis_open.docs.s_ramp.ns.s_ramp_v1.Fault) */ @Override public void visit(Fault artifact) { super.visit(artifact); MessageTarget message = artifact.getMessage(); if (message != null && message.getOtherAttributes().containsKey(WsdlDeriver.UNRESOLVED_REF)) { String encodedRef = message.getOtherAttributes().remove(WsdlDeriver.UNRESOLVED_REF); QName ref = QName.valueOf(encodedRef); BaseArtifactType artifactRef = findArtifact(ArtifactTypeEnum.Message, ref); if (artifactRef != null) { message.setValue(artifactRef.getUuid()); } else { artifact.setMessage(null); } } }
/** * @see org.overlord.sramp.common.visitors.ArtifactVisitorAdapter#visit(org.oasis_open.docs.s_ramp.ns.s_ramp_v1.OperationInput) */ @Override public void visit(OperationInput artifact) { super.visit(artifact); MessageTarget message = artifact.getMessage(); if (message != null && message.getOtherAttributes().containsKey(WsdlDeriver.UNRESOLVED_REF)) { String encodedRef = message.getOtherAttributes().remove(WsdlDeriver.UNRESOLVED_REF); QName ref = QName.valueOf(encodedRef); BaseArtifactType artifactRef = findArtifact(ArtifactTypeEnum.Message, ref); if (artifactRef != null) { message.setValue(artifactRef.getUuid()); } else { artifact.setMessage(null); } } }
/** * @see org.overlord.sramp.common.visitors.ArtifactVisitorAdapter#visit(org.oasis_open.docs.s_ramp.ns.s_ramp_v1.Binding) */ @Override public void visit(Binding artifact) { super.visit(artifact); PortTypeTarget portType = artifact.getPortType(); if (portType != null && portType.getOtherAttributes().containsKey(WsdlDeriver.UNRESOLVED_REF)) { String encodedRef = portType.getOtherAttributes().remove(WsdlDeriver.UNRESOLVED_REF); QName ref = QName.valueOf(encodedRef); BaseArtifactType artifactRef = findArtifact(ArtifactTypeEnum.PortType, ref); if (artifactRef != null) { portType.setValue(artifactRef.getUuid()); } else { artifact.setPortType(null); } } }
@Override protected CommandResult doExecute(CommandInvocation commandInvocation) throws Exception { BaseArtifactType artifact = currentArtifact(commandInvocation); // Print out the meta-data information commandInvocation.getShell().out().println(Messages.i18n.format("RefreshMetaData.MetaDataFor", artifact.getUuid())); commandInvocation.getShell().out().println("--------------"); PrintArtifactMetaDataVisitor visitor = new PrintArtifactMetaDataVisitor(commandInvocation); ArtifactVisitorHelper.visitArtifact(visitor, artifact); return CommandResult.SUCCESS; }
@Override protected CommandResult doExecute(CommandInvocation commandInvocation) throws Exception { if (CollectionUtils.isEmpty(arguments) || arguments.size() < 1) { return doHelp(commandInvocation); } String text = arguments.get(0); ArtificerAtomApiClient client = client(commandInvocation); BaseArtifactType artifact = currentArtifact(commandInvocation); try { client.addComment(artifact.getUuid(), ArtifactType.valueOf(artifact), text); commandInvocation.getShell().out().println(Messages.i18n.format("AddComment.Success", artifact.getName())); } catch (Exception e) { commandInvocation.getShell().out().println(Messages.i18n.format("AddComment.Failure")); commandInvocation.getShell().out().println("\t" + e.getMessage()); return CommandResult.FAILURE; } return CommandResult.SUCCESS; }
/** * @return a new artifact * @throws SrampException */ private BaseArtifactType createXsdArtifact() throws SrampException { String artifactFileName = "PO.xsd"; //$NON-NLS-1$ InputStream content = this.getClass().getResourceAsStream("/sample-files/xsd/" + artifactFileName); //$NON-NLS-1$ XsdDocument document = new XsdDocument(); document.setName(artifactFileName); document.setArtifactType(BaseArtifactEnum.XSD_DOCUMENT); BaseArtifactType artifact = persistenceManager.persistArtifact(document, content); Assert.assertNotNull(artifact); log.info("persisted PO.xsd to JCR, returned artifact uuid=" + artifact.getUuid()); //$NON-NLS-1$ return artifact; }
@Test public void testPersistArtifactPO_XML() throws Exception { String artifactFileName = "PO.xml"; //$NON-NLS-1$ InputStream POXml = this.getClass().getResourceAsStream("/sample-files/core/" + artifactFileName); //$NON-NLS-1$ Document document = new Document(); document.setName(artifactFileName); document.setArtifactType(BaseArtifactEnum.XML_DOCUMENT); BaseArtifactType artifact = persistenceManager.persistArtifact(document, POXml); Assert.assertNotNull(artifact); log.info("persisted PO.xml 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(XmlDocument.class, artifact.getClass()); long size = ((DocumentArtifactType) artifact).getContentSize(); Assert.assertTrue(size >= 825L); // Not doing an equals here due to the vagaries of Windows vs *nix line endings }
@Test public void testPersistArtifactPO_XSD() throws Exception { String artifactFileName = "PO.xsd"; //$NON-NLS-1$ InputStream POXsd = this.getClass().getResourceAsStream("/sample-files/xsd/" + artifactFileName); //$NON-NLS-1$ XsdDocument document = new XsdDocument(); document.setName(artifactFileName); document.setArtifactType(BaseArtifactEnum.XSD_DOCUMENT); BaseArtifactType artifact = persistenceManager.persistArtifact(document, POXsd); Assert.assertNotNull(artifact); log.info("persisted PO.xsd to JCR, returned artifact uuid=" + artifact.getUuid()); //$NON-NLS-1$ //print out the derived node if (log.isDebugEnabled()) { persistenceManager.printArtifactGraph(artifact.getUuid(), ArtifactType.XsdDocument()); } Assert.assertEquals(XsdDocument.class, artifact.getClass()); long size = ((DocumentArtifactType) artifact).getContentSize(); Assert.assertTrue(size >= 2376L); // Not doing an equals here due to the vagaries of Windows vs *nix line endings }
@Test public void testPersistArtifact_PDF() throws Exception { String artifactFileName = "s-ramp-press-release.pdf"; //$NON-NLS-1$ InputStream pdf = this.getClass().getResourceAsStream("/sample-files/core/" + artifactFileName); //$NON-NLS-1$ Document document = new Document(); document.setName(artifactFileName); document.setArtifactType(BaseArtifactEnum.DOCUMENT); BaseArtifactType artifact = persistenceManager.persistArtifact(document, pdf); Assert.assertNotNull(artifact); log.info("persisted s-ramp-press-release.pdf to JCR, returned artifact uuid=" + artifact.getUuid()); //$NON-NLS-1$ //print out the derived node if (log.isDebugEnabled()) { persistenceManager.printArtifactGraph(artifact.getUuid(), ArtifactType.Document()); } Assert.assertEquals(Document.class, artifact.getClass()); Assert.assertEquals(new Long(18873l), ((DocumentArtifactType) artifact).getContentSize()); Assert.assertEquals("4ee67f4c9f12ebe58c0c6d55d20d9dab91d8ab39", ((DocumentArtifactType) artifact).getContentHash()); //$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$ }
/** * Test method for {@link SrampAtomApiClient#uploadArtifact(java.lang.String, java.lang.String, java.io.InputStream, java.lang.String)}. */ @Test public void testUploadArtifactAndContent() throws Exception { String artifactFileName = "PO.xsd"; //$NON-NLS-1$ InputStream is = this.getClass().getResourceAsStream("/sample-files/xsd/" + artifactFileName); //$NON-NLS-1$ try { SrampAtomApiClient client = new SrampAtomApiClient(generateURL("/s-ramp")); //$NON-NLS-1$ XsdDocument xsdDocument = new XsdDocument(); xsdDocument.setName(artifactFileName); xsdDocument.setUuid("my-client-side-supplied-UUID"); //$NON-NLS-1$ BaseArtifactType artifact = client.uploadArtifact(xsdDocument, is); Assert.assertNotNull(artifact); Assert.assertEquals(artifactFileName, artifact.getName()); Assert.assertEquals("my-client-side-supplied-UUID", artifact.getUuid()); //$NON-NLS-1$ } finally { IOUtils.closeQuietly(is); } }
@Test public void testWithDerivedArtifacts() throws Exception { BaseArtifactType artifact = createXsdArtifact(); AuditEntrySet entries = auditManager.getArtifactAuditEntries(artifact.getUuid()); Assert.assertNotNull(entries); Assert.assertEquals(1, entries.size()); // Get all audit entries for the user. There should only be 7 because the // source document has 6 derived artifacts. entries = auditManager.getUserAuditEntries("junituser"); //$NON-NLS-1$ Assert.assertNotNull(entries); Assert.assertEquals(7, entries.size()); }
@Test public void testLastModifiedBy() throws Exception { BaseArtifactType artifact = createArtifact(null); // Now update the artifact as a different user. MockSecurityContext.currentUser = "junituser2"; //$NON-NLS-1$ artifact.setDescription("New description of the artifact."); //$NON-NLS-1$ persistenceManager.updateArtifact(artifact, ArtifactType.Document()); MockSecurityContext.currentUser = "junituser"; //$NON-NLS-1$ artifact = persistenceManager.getArtifact(artifact.getUuid(), ArtifactType.Document()); Assert.assertEquals("junituser", artifact.getCreatedBy()); //$NON-NLS-1$ Assert.assertEquals("junituser2", artifact.getLastModifiedBy()); //$NON-NLS-1$ }