/** * 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())); }
/** * 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 }
/** * 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())); }
/** * 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); } }
private void verifyModel(BaseArtifactType artifact) { if (! artifactType.getArtifactType().getApiType().equals(artifact.getArtifactType())) { error = new ArtificerWrongModelException(artifactType.getArtifactType().getApiType().value(), artifact.getArtifactType().value()); } }
/** * 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); } }
@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); } }
srampArtifact.setArtifactType(artifactType.getArtifactType().getApiType()); srampArtifact.setCreatedBy(artificerArtifact.getCreatedBy().getUsername()); XMLGregorianCalendar createdTimestamp = HibernateEntityFactory.calendar(artificerArtifact.getCreatedBy().getLastActionTime());