/** * Figures out the artifact type (enum) from the given S-RAMP artifact type string. * @param artifactType */ public static ArtifactType valueOf(String artifactType) { return valueOf(artifactType, false); }
public static BaseArtifactType visit(ArtificerArtifact artificerArtifact, ArtifactType artifactType, boolean includeAssociations) throws Exception { if (artifactType.isExtendedType() && artificerArtifact.isDocument()) { artifactType = ArtifactType.ExtendedDocument(artifactType.getExtendedType()); } BaseArtifactType srampArtifact = artifactType.newArtifactInstance(); HibernateEntityToSrampVisitor visitor = new HibernateEntityToSrampVisitor(artificerArtifact, artifactType, includeAssociations); ArtifactVisitorHelper.visitArtifact(visitor, srampArtifact); visitor.throwError(); return srampArtifact; }
/** * Resolves the proper artifact model given an artifact type. * @param artifactType the S-RAMP artifact type */ private String resolveArtifactModel(String artifactType) { return ArtifactType.valueOf(artifactType).getArtifactType().getModel(); } }
/** * @return the artifact type */ public String getType() { if (getArtifactType() == ArtifactTypeEnum.ExtendedArtifactType || getArtifactType() == ArtifactTypeEnum.ExtendedDocument) { return getExtendedType(); } else { return getArtifactType().getType(); } }
/** * Returns true if the archive is 1.) in the Extended model and 2.) of the given extended type. * * @param archiveExtendedType * @return boolean */ public boolean isExtendedTypeArchive(String archiveExtendedType) { if (archiveArtifactType != null) { return archiveArtifactType.isExtendedType() && archiveArtifactType.getExtendedType().equalsIgnoreCase(archiveExtendedType); } return false; }
protected CommandResult doExecute(CommandInvocation commandInvocation) throws Exception { ArtificerAtomApiClient client = client(commandInvocation); ArtifactType artifactType = ArtifactType.valueOf(type); if (artifactType.isExtendedType()) { artifactType = ArtifactType.ExtendedArtifactType(artifactType.getExtendedType(), false); } if (artifactType.isDerived()) { commandInvocation.getShell().out().println(Messages.i18n.format("ArtifactModel.isDerived")); return CommandResult.FAILURE; } else if (artifactType.isDocument()) { commandInvocation.getShell().out().println(Messages.i18n.format("ArtifactModel.isDocument")); return CommandResult.FAILURE; } else { BaseArtifactType artifact = artifactType.newArtifactInstance(); artifact.setName(name); artifact.setDescription(description); artifact = client.createArtifact(artifact); // Put the artifact in the session as the active artifact context(commandInvocation).setCurrentArtifact(artifact); } commandInvocation.getShell().out().println(Messages.i18n.format("CreateArtifactCommand.Successful", name)); return CommandResult.SUCCESS; }
ArtifactType artifactType = ArtifactType.valueOf(artifact); commandInvocation.getShell().out().println(Messages.i18n.format("PrintArtifact.CoreHeading")); if (artifactType.isExtendedType()) printProperty(Messages.i18n.format("PrintArtifact.Type"), artifactType.getExtendedType()); else printProperty(Messages.i18n.format("PrintArtifact.Type"), artifactType.getArtifactType().getType()); printProperty(Messages.i18n.format("PrintArtifact.Model"), artifactType.getArtifactType().getModel()); printProperty(Messages.i18n.format("PrintArtifact.UUID"), artifact.getUuid()); printProperty(Messages.i18n.format("PrintArtifact.Name"), artifact.getName()); printProperty(Messages.i18n.format("PrintArtifact.Version"), artifact.getVersion()); printProperty(Messages.i18n.format("PrintArtifact.Derived"), String.valueOf(artifactType.isDerived())); String archiveUuid = artifact.getOtherAttributes().get(ArtificerConstants.ARTIFICER_EXPANDED_FROM_ARCHIVE_UUID_QNAME); if (StringUtils.isNotBlank(archiveUuid)) {
ArtifactType artifactType = valueOf(apiType); if (DocumentArtifactType.class.isAssignableFrom(artifact.getClass())) { artifactType.setMimeType(((DocumentArtifactType)artifact).getContentType()); if (artifactType.isExtendedType()) { if ((artifact.getOtherAttributes().keySet().contains(ArtificerConstants.SRAMP_CONTENT_TYPE_QNAME))) { String contentTypeStr = artifact.getOtherAttributes().get(ArtificerConstants.SRAMP_CONTENT_TYPE_QNAME); artifactType.setMimeType(contentTypeStr); artifactType.setExtendedDerivedType("true".equals(extendedDerived)); if (artifactType.getArtifactType() == ArtifactTypeEnum.ExtendedArtifactType) { String extendedType = ((ExtendedArtifactType) artifact).getExtendedType(); artifactType.setExtendedType(extendedType); } else if (artifactType.getArtifactType() == ArtifactTypeEnum.ExtendedDocument) { String extendedType = ((ExtendedDocument) artifact).getExtendedType(); artifactType.setExtendedType(extendedType); for (ArtifactTypeEnum artifactTypeEnum : values) { if (artifactTypeEnum.getTypeClass().equals(artifact.getClass())) { ArtifactType artifactType = new ArtifactType(artifactTypeEnum, null); if (artifactTypeEnum == ArtifactTypeEnum.ExtendedArtifactType || artifactTypeEnum == ArtifactTypeEnum.ExtendedDocument) { if ((artifact.getOtherAttributes().keySet().contains(ArtificerConstants.SRAMP_CONTENT_TYPE_QNAME))) { String contentTypeStr = artifact.getOtherAttributes().get(ArtificerConstants.SRAMP_CONTENT_TYPE_QNAME); artifactType.setMimeType(contentTypeStr); artifactType.setExtendedType(extendedType); artifactType.setExtendedDerivedType("true".equals(extendedDerived));
for (ArtifactSummary summary : rset) { ArtifactType type = summary.getArtifactType(); String displayType = type.getArtifactType().getType().toString(); if (type.isExtendedType() && type.getExtendedType() != null) { displayType = type.getExtendedType();
ArtifactType artifactType = ArtifactType.valueOf(baseArtifactType); assertFeatureEnabled(artifactType); ClientResponse<Entry> response = null; try { String type = artifactType.getType(); String atomUrl = String.format("%1$s/%2$s/%3$s", srampEndpoint, artifactType.getArtifactType().getModel(), type); ClientRequest request = createClientRequest(atomUrl); request.body(artifactType.getMimeType(), content); MediaType mediaType2 = MediaType.getInstance(artifactType.getMimeType()); output.addPart(content, mediaType2);
ArtifactType type = ArtifactType.valueOf(artifact); assertFeatureEnabled(type); ClientResponse<?> response = null; try { String artifactModel = type.getArtifactType().getModel(); String artifactType = type.getArtifactType().getType(); if ("ext".equals(type.getArtifactType().getModel()) && type.getExtendedType()!=null) { artifactType = type.getExtendedType();
/** * 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); } }
/** * Creates a new artifact in the S-RAMP repository. Use this method when creating * logical artifacts in the repository (i.e. artifacts without document content). * @param artifact */ public BaseArtifactType createArtifact(BaseArtifactType artifact) throws ArtificerClientException, ArtificerServerException { ArtifactType artifactType = ArtifactType.valueOf(artifact); if (ArtificerModelUtils.isDocumentArtifact(artifact)) { throw new ArtificerClientException(Messages.i18n.format("MISSING_ARTIFACT_CONTEN")); } assertFeatureEnabled(artifactType); ClientResponse<Entry> response = null; try { String type = artifactType.getType(); String atomUrl = String.format("%1$s/%2$s/%3$s", srampEndpoint, artifactType.getModel(), type); ClientRequest request = createClientRequest(atomUrl); request.body(MediaType.APPLICATION_ATOM_XML_ENTRY, ArtificerAtomUtils.wrapSrampArtifact(artifact)); response = request.post(Entry.class); Entry entry = response.getEntity(); return ArtificerAtomUtils.unwrapSrampArtifact(artifactType, entry); } catch (ArtificerServerException e) { throw e; } catch (Throwable e) { throw new ArtificerClientException(e); } finally { closeQuietly(response); } }
/** * @return true if the type is a {@link ExtendedArtifactType}. */ public boolean isExtendedType() { return getArtifactType() == ArtifactTypeEnum.ExtendedArtifactType || getArtifactType() == ArtifactTypeEnum.ExtendedDocument; }
ClientResponse<Entry> response = null; try { String type = artifactType.getType(); String atomUrl = String.format("%1$s/%2$s/%3$s", srampEndpoint, artifactType.getArtifactType().getModel(), type); ClientRequest request = createClientRequest(atomUrl); if (artifactFileName != null) request.header("Slug", artifactFileName); request.body(artifactType.getMimeType(), content);
@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; }
@Override protected CommandResult doExecute(CommandInvocation commandInvocation) throws Exception { if (CollectionUtils.isEmpty(arguments)) { return doHelp(commandInvocation); } String pathToContent = optionalArgument(arguments, 0); InputStream contentStream = null; try { ArtifactType artifactType = ArtifactType.valueOf(type); String name = new File(type).getName(); if (pathToContent != null) { File contentFile = new File(pathToContent); contentStream = FileUtils.openInputStream(contentFile); } BaseArtifactType artifact = artifactType.newArtifactInstance(); artifact.setName(name); currentArchive(commandInvocation).addEntry(entryPath, artifact, contentStream); commandInvocation.getShell().out().println(Messages.i18n.format("AddEntry.Added", entryPath)); } catch (ArtificerArchiveException e) { commandInvocation.getShell().out().println(Messages.i18n.format("AddEntry.ArtificerArchiveException", e.getLocalizedMessage())); } finally { IOUtils.closeQuietly(contentStream); } return CommandResult.SUCCESS; }
private BaseArtifactType doPersistArtifact(final BaseArtifactType srampArtifact, final ArtifactContent content, final HibernateRelationshipFactory relationshipFactory, EntityManager entityManager) throws Exception { final ArtifactType artifactType = ArtifactType.valueOf(srampArtifact); if (artifactType.isDocument()) { ArtificerDocumentArtifact artificerDocumentArtifact = (ArtificerDocumentArtifact) artificerArtifact; processDocument(artificerDocumentArtifact, content); for (BaseArtifactType derivedSrampArtifact : derivedSrampArtifacts) { ArtifactType derivedSrampArtifactType = ArtifactType.valueOf(derivedSrampArtifact); ArtificerArtifact artificerDerivedArtifact = SrampToHibernateEntityVisitor.visit( derivedSrampArtifact, derivedSrampArtifactType, classificationHelper);
/** * @return true if the artifact is a document artifact */ public boolean isDocument() { if (isDerived()) { return false; } else { return getArtifactType().isDocument(); } }
/** * @see java.lang.Object#toString() */ @Override public String toString() { return String.format("/s-ramp/%1$s/%2$s (%3$s)", getArtifactType().getModel(), getArtifactType() .getType(), getMimeType()); }