+ this.key = new PfConceptKey(copyConcept.key);
+ this.derivedFrom = (copyConcept.derivedFrom != null ? new PfConceptKey(copyConcept.derivedFrom) : null);
+ this.metadata = (copyConcept.metadata != null ? new TreeMap<>(copyConcept.metadata) : null);
+ this.description = copyConcept.description;
+ }
+
+ /**
+ * Authorative constructor.
+ *
+ * @param authorativeConcept the authorative concept to copy from
+ */
+ public JpaToscaEntityType(final T authorativeConcept) {
+ this.fromAuthorative(authorativeConcept);
+ }
+
+ @Override
+ public T toAuthorative() {
+ toscaEntity.setName(getKey().getName());
+ toscaEntity.setVersion(getKey().getVersion());
+
+ if (derivedFrom != null) {
+ toscaEntity.setDerivedFrom(derivedFrom.getName());
+ }
+
+ if (description != null) {
+ toscaEntity.setDescription(description);
+ }
+
+ if (metadata != null) {
+ Map<String, String> metadataMap = new LinkedHashMap<>();
+
+ for (Entry<String, String> entry : metadata.entrySet()) {
+ metadataMap.put(entry.getKey(), entry.getValue());
+ }
+
+ toscaEntity.setMetadata(metadataMap);
+ }
+
+ return toscaEntity;
+ }
+
+ @Override
+ public void fromAuthorative(T toscaEntity) {
+ key = new PfConceptKey();
+
+ if (toscaEntity.getName() != null) {
+ key.setName(toscaEntity.getName());
+ }
+
+ if (toscaEntity.getVersion() != null) {
+ key.setVersion(toscaEntity.getVersion());
+ }
+
+ if (toscaEntity.getDerivedFrom() != null) {
+ // CHeck if the derived from field contains a name-version ID
+ if (toscaEntity.getDerivedFrom().contains(":")) {
+ derivedFrom = new PfConceptKey(toscaEntity.getDerivedFrom());
+ } else {
+ derivedFrom = new PfConceptKey(toscaEntity.getDerivedFrom(), PfKey.NULL_KEY_VERSION);
+ }
+ }
+
+ if (toscaEntity.getDescription() != null) {
+ description = toscaEntity.getDescription();
+ }
+
+ if (toscaEntity.getMetadata() != null) {
+ metadata = new LinkedHashMap<>();
+
+ for (Entry<String, String> metadataEntry : toscaEntity.getMetadata().entrySet()) {
+ metadata.put(metadataEntry.getKey(), metadataEntry.getValue());
+ }
+ }