/** * @return true if the type is a {@link ExtendedArtifactType}. */ public boolean isExtendedType() { return getArtifactType() == ArtifactTypeEnum.ExtendedArtifactType || getArtifactType() == ArtifactTypeEnum.ExtendedDocument; }
/** * @return the artifact type */ public String getType() { if (getArtifactType() == ArtifactTypeEnum.ExtendedArtifactType || getArtifactType() == ArtifactTypeEnum.ExtendedDocument) { return getExtendedType(); } else { return getArtifactType().getType(); } }
/** * @return the artifact model */ public String getModel() { return getArtifactType().getModel(); }
/** * @return the artifact type label */ public String getLabel() { return getArtifactType().getLabel(); }
/** * @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()); }
/** * Called to unwrap the S-RAMP artifact from its wrapper. * @param artifactWrapper the S-RAMP artifact wrapper * @return the specific artifact based on type */ public BaseArtifactType unwrap(Artifact artifactWrapper) { try { Method method = Artifact.class.getMethod("get" + getArtifactType().getType()); BaseArtifactType artifact = (BaseArtifactType) method.invoke(artifactWrapper); artifact.setArtifactType(this.getArtifactType().getApiType()); return artifact; } catch (Exception e) { throw new RuntimeException(Messages.i18n.format("ARTIFACT_UNWRAP_ERROR", getArtifactType().getType()), e); } }
/** * 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 true if the artifact is a document artifact */ public boolean isDocument() { if (isDerived()) { return false; } else { return getArtifactType().isDocument(); } }
/** * @return true if the artifact is derived */ public boolean isDerived() { return getArtifactType().isDerived() || isExtendedDerivedType(); }
/** * Asserts that the given feature is enabled. If it is not, then an exception * is thrown. If this client is not set to validating, then this method will * always pass. * @param feature * @throws ArtificerClientException */ private void assertFeatureEnabled(ArtifactType feature) throws ArtificerClientException { if (this.validating) { if (!this.enabledFeatures.contains(feature.getArtifactType().getType())) { throw new ArtificerClientException(Messages.i18n.format("FEATURE_NOT_SUPPORTED")); } } }
try { String atomUrl = String.format("%1$s/%2$s/%3$s/%4$s/media", srampEndpoint, artifactType.getArtifactType().getModel(), artifactType.getArtifactType().getType(), artifactUuid);
/** * Common visit method for all artifacts. * @param artifact */ protected void visitBase(BaseArtifactType artifact) { ArtifactType artifactType = ArtifactType.valueOf(artifact); BaseArtifactEnum apiType = artifactType.getArtifactType().getApiType(); artifact.setArtifactType(apiType); // Subclasses can do common visit logic here }
/** * 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); } }
private void verifyModel(BaseArtifactType artifact) { if (! artifactType.getArtifactType().getApiType().equals(artifact.getArtifactType())) { error = new ArtificerWrongModelException(artifactType.getArtifactType().getApiType().value(), artifact.getArtifactType().value()); } }
public BaseArtifactType addComment(String uuid, ArtifactType type, String text) throws ArtificerClientException, ArtificerServerException { assertFeatureEnabled(type); ClientResponse<Entry> 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(); } String atomUrl = String.format("%1$s/%2$s/%3$s/%4$s/comment", srampEndpoint, artifactModel, artifactType, uuid); ClientRequest request = createClientRequest(atomUrl); request.body(MediaType.TEXT_PLAIN, text); response = request.post(Entry.class); Entry entry = response.getEntity(); return ArtificerAtomUtils.unwrapSrampArtifact(type, entry); } catch (ArtificerServerException e) { throw e; } catch (Throwable e) { throw new ArtificerClientException(e); } finally { closeQuietly(response); } }
/** * Gets the full meta-data listing for an Artifact in the S-RAMP repository. * @param artifactType * @param artifactUuid * @throws ArtificerClientException * @throws ArtificerServerException */ public BaseArtifactType getArtifactMetaData(ArtifactType artifactType, String artifactUuid) throws ArtificerClientException, ArtificerServerException { assertFeatureEnabled(artifactType); ClientResponse<Entry> response = null; try { String atomUrl = String.format("%1$s/%2$s/%3$s/%4$s", srampEndpoint, artifactType.getArtifactType().getModel(), artifactType.getArtifactType().getType(), artifactUuid); ClientRequest request = createClientRequest(atomUrl); response = request.get(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); } }
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();
for (ArtifactSummary summary : rset) { ArtifactType type = summary.getArtifactType(); String displayType = type.getArtifactType().getType().toString(); if (type.isExtendedType() && type.getExtendedType() != null) { displayType = type.getExtendedType();
@Override protected void visitDerived(DerivedArtifactType srampArtifact) { super.visitDerived(srampArtifact); try { if (includeAssociations) { ArtificerArtifact derivedFrom = artificerArtifact.getDerivedFrom(); if (derivedFrom != null) { DocumentArtifactTarget target = new DocumentArtifactTarget(); ArtifactType derivedFromType = ArtifactType.valueOf(derivedFrom.getType(), derivedFrom.isDocument()); DocumentArtifactEnum documentArtifactEnum = DocumentArtifactEnum.fromValue(derivedFromType.getArtifactType().getApiType()); target.setArtifactType(documentArtifactEnum); target.setValue(derivedFrom.getUuid()); srampArtifact.setRelatedDocument(target); } } } catch (Exception e) { throw new RuntimeException(e); } }
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(MediaType.TEXT_PLAIN, path);