/** * 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); } }
for (ArtifactTypeEnum t : ArtifactTypeEnum.values()) { modelCandidates.add(t.getModel()); String partialModel = split[2]; Set<String> modelCandidates = new TreeSet<>(); for (ArtifactTypeEnum t : ArtifactTypeEnum.values()) { if (t.getModel().startsWith(partialModel)) modelCandidates.add(t.getModel()); String model = split[2]; Set<String> typeCandidates = new TreeSet<>(); for (ArtifactTypeEnum t : ArtifactTypeEnum.values()) { if (t.getModel().equals(model)) { typeCandidates.add(t.getType()); String partialType = split[3]; Set<String> typeCandidates = new TreeSet<>(); for (ArtifactTypeEnum t : ArtifactTypeEnum.values()) { if (t.getModel().equals(model) && t.getType().startsWith(partialType)) { typeCandidates.add(t.getType());
/** * Figures out the artifact type from the class. * @param artyClass */ private static ArtifactType valueOf(Class<? extends BaseArtifactType> artyClass) { ArtifactType rval = null; for (ArtifactTypeEnum e : ArtifactTypeEnum.values()) { if (e.getTypeClass().equals(artyClass)) { rval = new ArtifactType(e, null); } } return rval; }
@Override public void complete(CompleterInvocation completerInvocation) { String currentValue = completerInvocation.getGivenCompleteValue(); for (ArtifactTypeEnum t : ArtifactTypeEnum.values()) { String candidate = t.getType(); if (StringUtils.isBlank(currentValue) || candidate.startsWith(currentValue)) { completerInvocation.addCompleterValue(candidate); } } } }
/** * Figures out the type from the s-ramp API type. * @param apiType */ public static ArtifactTypeEnum valueOf(BaseArtifactEnum apiType) { ArtifactTypeEnum[] values = values(); for (ArtifactTypeEnum artifactType : values) { if (artifactType.getApiType() == apiType) { return artifactType; } } throw new RuntimeException(Messages.i18n.format("ARTIFACT_TYPE_FROM_APITYPE_ERROR", apiType.value())); }
/** * @return the artifact model */ public String getModel() { return getArtifactType().getModel(); }
/** * 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")); } } }
if ("ext".equals(model)) { ArtifactTypeEnum artifactTypeEnum = null; if ( type.equals(ArtifactTypeEnum.ExtendedDocument.getType()) || ( !type.equals(ArtifactTypeEnum.ExtendedArtifactType.getType()) && isDocument!=null && isDocument ) ) { artifactTypeEnum = ArtifactTypeEnum.ExtendedDocument; } else { artifactType.setExtendedType(type); } else { ArtifactTypeEnum artifactTypeEnum = ArtifactTypeEnum.valueOf(type); artifactType = new ArtifactType(artifactTypeEnum, null);
/** * Figures out the type from the artifact instance. * @param artifact */ public static ArtifactTypeEnum valueOf(BaseArtifactType artifact) { BaseArtifactEnum apiType = artifact.getArtifactType(); if (apiType != null) { return valueOf(apiType); } ArtifactTypeEnum[] values = values(); for (ArtifactTypeEnum artifactType : values) { if (artifactType.getTypeClass().equals(artifact.getClass())) { return artifactType; } } throw new RuntimeException(Messages.i18n.format("ARTIFACT_TYPE_FROM_CLASS_ERROR", artifact.getClass())); }
/** * 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); } }
public static ArtifactType valueOf(String artifactType, boolean isDocument) { if (StringUtils.isEmpty(artifactType)) { return null; } else if (ArtifactTypeEnum.hasEnum(artifactType)) { ArtifactTypeEnum artifactTypeEnum = ArtifactTypeEnum.valueOf(artifactType); return new ArtifactType(artifactTypeEnum, null); } else { ArtifactTypeEnum artifactTypeEnum; if (isDocument) { artifactTypeEnum = ArtifactTypeEnum.ExtendedDocument; } else { artifactTypeEnum = ArtifactTypeEnum.ExtendedArtifactType; } ArtifactType rval = new ArtifactType(artifactTypeEnum, null); rval.setExtendedType(artifactType); rval.setMimeType("application/octet-stream"); return rval; } }
/** * @return the artifact type label */ public String getLabel() { return getArtifactType().getLabel(); }
/** * 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(); } }
@Override public void complete(CompleterInvocation completerInvocation) { UploadArtifactCommand command = (UploadArtifactCommand) completerInvocation.getCommand(); if (CollectionUtils.isEmpty(command.arguments)) { FileNameCompleterDelegate.complete(completerInvocation); } else if (command.arguments.size() == 1) { String currentValue = completerInvocation.getGivenCompleteValue(); for (ArtifactTypeEnum t : ArtifactTypeEnum.values()) { String candidate = t.getType(); if (StringUtils.isBlank(currentValue) || candidate.startsWith(currentValue)) { completerInvocation.addCompleterValue(candidate); } } } } }
/** * @return the artifact type */ public String getType() { if (getArtifactType() == ArtifactTypeEnum.ExtendedArtifactType || getArtifactType() == ArtifactTypeEnum.ExtendedDocument) { return getExtendedType(); } else { return getArtifactType().getType(); } }
/** * Figures out the type from the s-ramp API type. * @param apiType */ public static ArtifactType valueOf(BaseArtifactEnum apiType) { ArtifactTypeEnum[] values = ArtifactTypeEnum.values(); for (ArtifactTypeEnum artifactType : values) { if (artifactType.getApiType() == apiType) { return new ArtifactType(artifactType, null); } } throw new RuntimeException(Messages.i18n.format("ARTIFACT_TYPE_FROM_APITYPE_ERROR", apiType.value())); }
ArtifactTypeEnum[] values = ArtifactTypeEnum.values(); for (ArtifactTypeEnum artifactTypeEnum : values) { if (artifactTypeEnum.getTypeClass().equals(artifact.getClass())) { ArtifactType artifactType = new ArtifactType(artifactTypeEnum, null); if (artifactTypeEnum == ArtifactTypeEnum.ExtendedArtifactType || artifactTypeEnum == ArtifactTypeEnum.ExtendedDocument) {
private void verifyModel(BaseArtifactType artifact) { if (! artifactType.getArtifactType().getApiType().equals(artifact.getArtifactType())) { error = new ArtificerWrongModelException(artifactType.getArtifactType().getApiType().value(), artifact.getArtifactType().value()); } }