/** * Finds a component artifact (previously created) with the given name. * @param derivedArtifacts * @param componentName */ private BaseArtifactType findComponentByName(Collection<BaseArtifactType> derivedArtifacts, String componentName) { for (BaseArtifactType artifact : derivedArtifacts) { ArtifactType at = ArtifactType.valueOf(artifact); if (at.getType().equals(SwitchYardModel.SwitchYardComponent) && artifact.getName().equals(componentName)) { return artifact; } } return null; }
private void processProperties( final BaseArtifactType artifact, final Element element, final XPath xpath ) throws Exception { final NodeList props = (NodeList)query(xpath, element, Utils.getElementQueryString(Propertied.XmlId.PROPERTY), XPathConstants.NODESET); if (props.getLength() != 0) { LOGGER.debug("VdbManifestDeriver:processing '{}' properties", props.getLength()); //$NON-NLS-1$ for (int propIndex = 0, numProps = props.getLength(); propIndex < numProps; ++propIndex) { final Element prop = (Element)props.item(propIndex); final String name = prop.getAttribute(Propertied.XmlId.NAME); final String value = prop.getAttribute(Propertied.XmlId.VALUE); SrampModelUtils.setCustomProperty(artifact, name, value); } if (LOGGER.isDebugEnabled()) { for (final Property prop : artifact.getProperty()) { LOGGER.debug("VdbManifestDeriver:artifact '{}' has property '{}' with value '{}'", //$NON-NLS-1$ new Object[] {artifact.getName(), prop.getPropertyName(), prop.getPropertyValue()}); } } } }
/** * Updates the basic s-ramp meta data. * @param artifact * @throws Exception */ private void updateArtifactMetaData(BaseArtifactType artifact) throws Exception { if (artifact.getName() != null) setProperty("sramp:name", artifact.getName()); //$NON-NLS-1$ else setProperty("sramp:name", artifact.getClass().getSimpleName()); //$NON-NLS-1$ if (artifact.getDescription() != null) setProperty("sramp:description", artifact.getDescription()); //$NON-NLS-1$ if (artifact.getVersion() != null) setProperty("version", artifact.getVersion()); //$NON-NLS-1$ setProperty("sramp:derived", this.artifactType.isDerived()); //$NON-NLS-1$ }
@Override protected CommandResult doExecute(CommandInvocation commandInvocation) throws Exception { ArtificerAtomApiClient client = client(commandInvocation); BaseArtifactType artifact = currentArtifact(commandInvocation); try { client.updateArtifactMetaData(artifact); commandInvocation.getShell().out().println(Messages.i18n.format("UpdateMetaData.Success", artifact.getName())); } catch (Exception e) { commandInvocation.getShell().out().println(Messages.i18n.format("UpdateMetaData.Failure")); commandInvocation.getShell().out().println("\t" + e.getMessage()); return CommandResult.FAILURE; } 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; }
/** * Gets a single derived artifact from the collection of derived artifacts. Narrows * it down by type and name. * @param derivedArtifacts * @param artifactType * @param name */ private BaseArtifactType getDerivedArtifact(Collection<BaseArtifactType> derivedArtifacts, ArtifactType artifactType, String name) { for (BaseArtifactType artifact : derivedArtifacts) { ArtifactType at = ArtifactType.valueOf(artifact); if (at.equals(artifactType) && artifact.getName().equals(name)) { return artifact; } } return null; }
@Test public void testSimpleBatch() throws Exception { List<BatchItem> items = new ArrayList<BatchItem>(); BatchItem item = createBatchItem("/sample-files/batch/simple-1.txt", new Document(), BaseArtifactEnum.DOCUMENT); //$NON-NLS-1$ items.add(item); item = createBatchItem("/sample-files/batch/simple-2.txt", new Document(), BaseArtifactEnum.DOCUMENT); //$NON-NLS-1$ items.add(item); List<Object> response = persistenceManager.persistBatch(items); for (Object object : response) { Assert.assertTrue(object instanceof BaseArtifactType); } BaseArtifactType simple1 = (BaseArtifactType) response.get(0); BaseArtifactType simple2 = (BaseArtifactType) response.get(1); Assert.assertEquals("simple-1.txt", simple1.getName()); //$NON-NLS-1$ Assert.assertEquals("simple-2.txt", simple2.getName()); //$NON-NLS-1$ }
@Override protected CommandResult doExecute(CommandInvocation commandInvocation) throws Exception { ArtificerAtomApiClient client = client(commandInvocation); BaseArtifactType artifact = currentArtifact(commandInvocation); try { ArtifactType type = ArtifactType.valueOf(artifact); BaseArtifactType metaData = client.getArtifactMetaData(type, artifact.getUuid()); context(commandInvocation).setCurrentArtifact(metaData); commandInvocation.getShell().out().println(Messages.i18n.format("RefreshMetaData.Success", metaData.getName())); commandInvocation.getShell().out().println(Messages.i18n.format("RefreshMetaData.MetaDataFor", metaData.getUuid())); commandInvocation.getShell().out().println("--------------"); PrintArtifactMetaDataVisitor visitor = new PrintArtifactMetaDataVisitor(commandInvocation); ArtifactVisitorHelper.visitArtifact(visitor, metaData); } catch (Exception e) { commandInvocation.getShell().out().println(Messages.i18n.format("RefreshMetaData.Failure")); commandInvocation.getShell().out().println("\t" + e.getMessage()); return CommandResult.FAILURE; } return CommandResult.SUCCESS; }
/** * Updates the basic s-ramp meta data. * @param srampArtifact * @throws Exception */ private void updateArtifactMetaData(BaseArtifactType srampArtifact) throws Exception { artificerArtifact.setUuid(srampArtifact.getUuid()); artificerArtifact.setModel(artifactType.getModel()); // may have already been set... if (StringUtils.isBlank(artificerArtifact.getType())) { artificerArtifact.setType(artifactType.getType()); } ArtificerUser createdBy = HibernateEntityFactory.user(srampArtifact.getCreatedBy(), srampArtifact.getCreatedTimestamp()); artificerArtifact.setCreatedBy(createdBy); ArtificerUser modifiedBy = HibernateEntityFactory.user(srampArtifact.getLastModifiedBy(), srampArtifact.getLastModifiedTimestamp()); artificerArtifact.setModifiedBy(modifiedBy); if (srampArtifact.getName() != null) artificerArtifact.setName(srampArtifact.getName()); else artificerArtifact.setName(srampArtifact.getClass().getSimpleName()); artificerArtifact.setDescription(srampArtifact.getDescription()); artificerArtifact.setVersion(srampArtifact.getVersion()); }
/** * Test method for {@link SrampAtomApiClient#uploadArtifact(java.lang.String, java.lang.String, java.io.InputStream, java.lang.String)}. */ @Test public void testUploadArtifact() 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$ BaseArtifactType artifact = client.uploadArtifact(ArtifactType.XsdDocument(), is, artifactFileName); Assert.assertNotNull(artifact); Assert.assertEquals(artifactFileName, artifact.getName()); } finally { IOUtils.closeQuietly(is); } }
@Override protected CommandResult doExecute(CommandInvocation commandInvocation) throws Exception { ArtificerAtomApiClient client = client(commandInvocation); BaseArtifactType artifact = context(commandInvocation).getCurrentArtifact(); QueryResultSet feed = context(commandInvocation).getCurrentArtifactFeed(); if (client == null) { commandInvocation.getShell().out().println(Messages.i18n.format("Status.Status1")); } else { commandInvocation.getShell().out().println(Messages.i18n.format("Status.Status2", client.getEndpoint())); } if (artifact == null) { commandInvocation.getShell().out().println(Messages.i18n.format("Status.Status3")); } else { ArtifactType type = ArtifactType.valueOf(artifact); commandInvocation.getShell().out().println(Messages.i18n.format("Status.Status4", artifact.getName(), type.getType())); } if (feed == null) { commandInvocation.getShell().out().println(Messages.i18n.format("Status.Status5")); } else { commandInvocation.getShell().out().println(Messages.i18n.format("Status.Status6", feed.size())); } return CommandResult.SUCCESS; }
/** * Test method for {@link SrampAtomApiClient#uploadArtifact(java.lang.String, java.lang.String, java.io.InputStream, java.lang.String)}. */ @Test public void testExtendedDocumentArtifact() 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$ BaseArtifactType artifact = client.uploadArtifact(ArtifactType.ExtendedDocument("TestDocument"), is, artifactFileName); //$NON-NLS-1$ Assert.assertNotNull(artifact); Assert.assertEquals(artifactFileName, artifact.getName()); Assert.assertEquals(BaseArtifactEnum.EXTENDED_DOCUMENT, artifact.getArtifactType()); Assert.assertEquals(ExtendedDocument.class, artifact.getClass()); } finally { IOUtils.closeQuietly(is); } }
/** * 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); } }
/** * Ensures that a single artifact exists of the given type and name. * @param type * @param name * @throws Exception */ private BaseArtifactType assertSingleArtifact(ArtifactTypeEnum type, String name) throws Exception { String q = String.format("/s-ramp/%1$s/%2$s[@name = ?]", type.getModel(), type.getType()); //$NON-NLS-1$ SrampQuery query = queryManager.createQuery(q); query.setString(name); ArtifactSet artifactSet = null; try { artifactSet = query.executeQuery(); Assert.assertEquals(1, artifactSet.size()); BaseArtifactType arty = artifactSet.iterator().next(); Assert.assertEquals(name, arty.getName()); return arty; } finally { if (artifactSet != null) artifactSet.close(); } }
/** * Ensures that a single artifact exists of the given type and name. * @param type * @param name * @throws Exception */ private BaseArtifactType assertSingleArtifact(ArtifactTypeEnum type, String name) throws Exception { String q = String.format("/s-ramp/%1$s/%2$s[@name = ?]", type.getModel(), type.getType()); //$NON-NLS-1$ SrampQuery query = queryManager.createQuery(q); query.setString(name); ArtifactSet artifactSet = null; try { artifactSet = query.executeQuery(); Assert.assertEquals(1, artifactSet.size()); BaseArtifactType arty = artifactSet.iterator().next(); Assert.assertEquals(name, arty.getName()); return arty; } finally { if (artifactSet != null) artifactSet.close(); } }
/** * Test method for {@link SrampAtomApiClient#getArtifactMetaData(String)} */ @Test public void testGetArtifactMetaDataNoType() throws Exception { String uuid = null; 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$ BaseArtifactType artifact = client.uploadArtifact(ArtifactType.XsdDocument(), is, artifactFileName); Assert.assertNotNull(artifact); uuid = artifact.getUuid(); } finally { IOUtils.closeQuietly(is); } // Now test that we can fetch the meta-data using just the UUID { SrampAtomApiClient client = new SrampAtomApiClient(generateURL("/s-ramp")); //$NON-NLS-1$ BaseArtifactType metaData = client.getArtifactMetaData(uuid); Assert.assertNotNull(metaData); Assert.assertEquals(artifactFileName, metaData.getName()); } }
/** * Test method for {@link SrampAtomApiClient#getArtifactMetaData(ArtifactType, String)} */ @Test public void testGetArtifactMetaData() throws Exception { String uuid = null; 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$ BaseArtifactType artifact = client.uploadArtifact(ArtifactType.XsdDocument(), is, artifactFileName); Assert.assertNotNull(artifact); uuid = artifact.getUuid(); } finally { IOUtils.closeQuietly(is); } // Now test that we can fetch the meta-data using the artifact type and UUID { SrampAtomApiClient client = new SrampAtomApiClient(generateURL("/s-ramp")); //$NON-NLS-1$ BaseArtifactType metaData = client.getArtifactMetaData(ArtifactType.XsdDocument(), uuid); Assert.assertNotNull(metaData); Assert.assertEquals(artifactFileName, metaData.getName()); } }
/** * Tests the query manager. * @throws Exception */ @Test public void testQueryManager() throws Exception { // First, store an artifact. BaseArtifactType artifact = createDocument(1); log.info("persisted to JCR, returned artifact uuid=" + artifact.getUuid()); //$NON-NLS-1$ // Now query for it SrampQuery query = queryManager.createQuery("/s-ramp/core/Document"); //$NON-NLS-1$ ArtifactSet artifactSet = query.executeQuery(); Assert.assertNotNull(artifactSet); Assert.assertEquals(1, artifactSet.size()); BaseArtifactType found = artifactSet.iterator().next(); Assert.assertNotNull("Expected artifact not found in artifact set.", found); //$NON-NLS-1$ Assert.assertEquals(artifact.getUuid(), found.getUuid()); Assert.assertEquals(artifact.getName(), found.getName()); Assert.assertEquals(artifact.getDescription(), found.getDescription()); Assert.assertEquals(artifact.getLastModifiedBy(), found.getLastModifiedBy()); }
@Test public void testGetArtifact_XSD() throws Exception { String artifactFileName = "PO.xsd"; //$NON-NLS-1$ InputStream POXsd = this.getClass().getResourceAsStream("/sample-files/xsd/" + artifactFileName); //$NON-NLS-1$ Document document = new Document(); 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$ 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 BaseArtifactType artifact2 = persistenceManager.getArtifact(artifact.getUuid(), ArtifactType.XsdDocument()); Assert.assertEquals(artifact.getUuid(), artifact2.getUuid()); Assert.assertEquals(artifact.getCreatedBy(), artifact2.getCreatedBy()); Assert.assertEquals(artifact.getDescription(), artifact2.getDescription()); Assert.assertEquals(artifact.getLastModifiedBy(), artifact2.getLastModifiedBy()); Assert.assertEquals(artifact.getName(), artifact2.getName()); Assert.assertEquals(artifact.getVersion(), artifact2.getVersion()); Assert.assertEquals(artifact.getLastModifiedTimestamp(), artifact2.getLastModifiedTimestamp()); }
/** * 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$ }