Skip to content

Commit

Permalink
Remove Definitions in canonical model.
Browse files Browse the repository at this point in the history
This change is useful because it simplifies the existing serialization mechanisms around the canonical model
and the original justification for Definitions having an anonymous type derived from tDefinitions is moot
for winery purposes. This is primarily because the winery REST API does not expose specific features
that rely on Definitions being extensible.

In addition this prepares the separation of XML and YAML providers and fully diverges from the schema definition
outlined in the XML-1.0 standard, which was no longer tenable when considering the incompatibilities between
XML and YAML standard..
  • Loading branch information
Vogel612 committed Jul 17, 2020
1 parent 6ae80f7 commit 7512a63
Show file tree
Hide file tree
Showing 32 changed files with 249 additions and 271 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.eclipse.winery.model.ids.definitions.NodeTypeId;
import org.eclipse.winery.model.ids.definitions.PolicyTemplateId;
import org.eclipse.winery.model.ids.definitions.PolicyTypeId;
import org.eclipse.winery.model.tosca.Definitions;
import org.eclipse.winery.model.tosca.TDefinitions;
import org.eclipse.winery.model.tosca.TBoolean;
import org.eclipse.winery.model.tosca.TBoundaryDefinitions;
import org.eclipse.winery.model.tosca.TNodeType;
Expand Down Expand Up @@ -216,7 +216,7 @@ public String createThreatAndMitigationTemplates(ThreatCreationApiData data) thr
threatProps.setKVProperties(propMap);
threat.setProperties(threatProps);

Definitions threatDefinitions = BackendUtils.createWrapperDefinitions(threatID, repository);
TDefinitions threatDefinitions = BackendUtils.createWrapperDefinitions(threatID, repository);
threatDefinitions.setElement(threat);

try {
Expand All @@ -243,7 +243,7 @@ public String createThreatAndMitigationTemplates(ThreatCreationApiData data) thr
mitigationProps.setKVProperties(mitigationPropMap);
mitigation.setProperties(mitigationProps);

Definitions mitigationDefinitions = BackendUtils.createWrapperDefinitions(threatID, repository);
TDefinitions mitigationDefinitions = BackendUtils.createWrapperDefinitions(threatID, repository);
mitigationDefinitions.setElement(mitigation);

try {
Expand Down Expand Up @@ -303,7 +303,7 @@ public void setupThreatModelingTypes() throws Exception {
ModelUtilities.replaceWinerysPropertiesDefinition(threat, threatProps);

PolicyTypeId threatID = BackendUtils.getDefinitionsChildId(PolicyTypeId.class, ThreatModelingConstants.THREATMODELING_NAMESPACE, ThreatModelingConstants.THREAT_POLICY_NAME, false);
Definitions threatDefinitions = BackendUtils.createWrapperDefinitions(threatID, repository);
TDefinitions threatDefinitions = BackendUtils.createWrapperDefinitions(threatID, repository);

threatDefinitions.setElement(threat);

Expand All @@ -329,7 +329,7 @@ public void setupThreatModelingTypes() throws Exception {
ModelUtilities.replaceWinerysPropertiesDefinition(mitigation, mitigationProps);

PolicyTypeId mitigationID = BackendUtils.getDefinitionsChildId(PolicyTypeId.class, ThreatModelingConstants.THREATMODELING_NAMESPACE, ThreatModelingConstants.MITIGATION_POLICY_NAME, false);
Definitions mitigationDefinitions = BackendUtils.createWrapperDefinitions(mitigationID, repository);
TDefinitions mitigationDefinitions = BackendUtils.createWrapperDefinitions(mitigationID, repository);

mitigationDefinitions.setElement(mitigation);

Expand All @@ -339,7 +339,7 @@ public void setupThreatModelingTypes() throws Exception {
.build();

NodeTypeId svnfID = new NodeTypeId(QName.valueOf(ThreatModelingConstants.SVNF_NODE_TYPE));
Definitions svnfDefinitions = BackendUtils.createWrapperDefinitions(svnfID, repository);
TDefinitions svnfDefinitions = BackendUtils.createWrapperDefinitions(svnfID, repository);
svnfDefinitions.setElement(svnf);

try {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
Expand All @@ -28,10 +30,12 @@
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElements;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;
import javax.xml.namespace.QName;

import org.eclipse.winery.model.tosca.visitor.Visitor;

Expand All @@ -47,9 +51,18 @@
"types",
"serviceTemplateOrNodeTypeOrNodeTypeImplementation"
})
@XmlSeeAlso( {
Definitions.class
})
@XmlRootElement(name = "Definitions")
/**
* This is the canonical model's TDefinitions type. It's a combination of the tDefinitions type from the XML-1.0 standard
* and the Definitions type from the YAML standard and acts as a superset to both of them.
*
* This means instead of the XML-1.0 standard's definition of Definitions having a complex type inheriting from tDefinitions,
* the Definitions are <b>of type</b> tDefinitions.
*
* This could cause issues when deserializing XML-standard conform Definitions as TDefinitions.
* Therefor all deserialization of user-input that doesn't use winery Definitions as basis needs to be performed by the standard-specific repository implementations
* to correctly handle the discrepancies between the standards.
*/
public class TDefinitions extends HasId implements HasName, HasTargetNamespace {
@XmlElement(name = "Extensions")
protected TDefinitions.Extensions extensions;
Expand Down Expand Up @@ -82,6 +95,10 @@ public class TDefinitions extends HasId implements HasName, HasTargetNamespace {
@XmlSchemaType(name = "anyURI")
protected String targetNamespace;

@JsonIgnore
@XmlTransient
protected Map<String, QName> importDefinitions = new HashMap<>();

public TDefinitions() {
}

Expand All @@ -95,6 +112,14 @@ public TDefinitions(Builder builder) {
this.targetNamespace = builder.target_namespace;
}

public Map<String, QName> getImportDefinitions() {
return importDefinitions;
}

public void setImportDefinitions(Map<String, QName> importDefinitions) {
this.importDefinitions = importDefinitions;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down Expand Up @@ -875,6 +900,7 @@ public T addPolicyTemplates(TPolicyTemplate policyTemplate) {

@ADR(11)
@Override
@SuppressWarnings("unchecked") // we assume the cast is safe here
public T self() {
return (T) this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import org.eclipse.winery.model.ids.definitions.DefinitionsChildId;
import org.eclipse.winery.common.interfaces.QNameWithName;
import org.eclipse.winery.common.json.JsonFeature;
import org.eclipse.winery.model.tosca.Definitions;
import org.eclipse.winery.model.tosca.TDefinitions;
import org.eclipse.winery.model.tosca.TEntityType;
import org.eclipse.winery.model.tosca.TExtensibleElements;
Expand Down Expand Up @@ -172,11 +171,11 @@ private static TDefinitions getDefinitions(WebTarget wr, String path, String ns,
return WineryRepositoryClient.getDefinitions(componentListResource, ns, localPart);
}

private static Definitions getDefinitions(WebTarget instanceResource) {
private static TDefinitions getDefinitions(WebTarget instanceResource) {
Response response = instanceResource.request(MediaType.APPLICATION_XML).get();
if (response.getStatusInfo().equals(Response.Status.OK)) {
// also handles 404
return response.readEntity(Definitions.class);
return response.readEntity(TDefinitions.class);
}
return null;
}
Expand Down Expand Up @@ -357,10 +356,10 @@ public <T extends TEntityType> T getType(QName qname, Class<T> type) {
}

@Override
public Definitions getDefinitions(DefinitionsChildId id) {
public TDefinitions getDefinitions(DefinitionsChildId id) {
for (WebTarget wr : this.repositoryResources) {
String path = Util.getUrlPath(id);
Definitions definitions = WineryRepositoryClient.getDefinitions(wr.path(path));
TDefinitions definitions = WineryRepositoryClient.getDefinitions(wr.path(path));
if (definitions == null) {
// in case of an error, just try the next one
continue;
Expand All @@ -371,7 +370,7 @@ public Definitions getDefinitions(DefinitionsChildId id) {
return definitions;
}
}
return new Definitions();
return new TDefinitions();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
import org.eclipse.winery.model.ids.elements.ToscaElementId;
import org.eclipse.winery.common.version.WineryVersion;
import org.eclipse.winery.model.selfservice.Application;
import org.eclipse.winery.model.tosca.Definitions;
import org.eclipse.winery.model.tosca.TDefinitions;
import org.eclipse.winery.model.tosca.HasType;
import org.eclipse.winery.model.tosca.TArtifactTemplate;
import org.eclipse.winery.model.tosca.TConstraint;
Expand Down Expand Up @@ -505,7 +505,7 @@ public static ServiceTemplateId cloneServiceTemplate(ServiceTemplateId serviceTe

RepositoryFileReference fileRef = new RepositoryFileReference(newServiceTemplateId, "ServiceTemplate.tosca");

Definitions defs = new ServiceTemplateResource(serviceTemplate).getDefinitions();
TDefinitions defs = new ServiceTemplateResource(serviceTemplate).getDefinitions();

defs.setId(newName + "Definitions");
defs.setName(newName + "Definitions generated from Artifact " + artifactName);
Expand Down Expand Up @@ -540,7 +540,7 @@ public static ServiceTemplateId cloneServiceTemplate(ServiceTemplateId serviceTe
oldSTModel.getTags().getTag().removeAll(toRemove);
}

JAXBContext context = JAXBContext.newInstance(Definitions.class);
JAXBContext context = JAXBContext.newInstance(TDefinitions.class);
Marshaller m = context.createMarshaller();
StringWriter sw = new StringWriter();
m.marshal(defs, sw);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import javax.xml.namespace.QName;

import org.eclipse.winery.model.tosca.Definitions;
import org.eclipse.winery.model.tosca.TDefinitions;
import org.eclipse.winery.common.version.WineryVersion;

public class ComponentId {
Expand All @@ -24,10 +24,10 @@ public class ComponentId {
private String name;
private String namespace;
private QName qName;
private Definitions full;
private TDefinitions full;
private WineryVersion version;

public ComponentId(String id, String name, String namespace, QName qName, Definitions full, WineryVersion version) {
public ComponentId(String id, String name, String namespace, QName qName, TDefinitions full, WineryVersion version) {
this.id = id;
this.name = name;
this.namespace = namespace;
Expand All @@ -52,7 +52,7 @@ public QName getqName() {
return qName;
}

public Definitions getFull() {
public TDefinitions getFull() {
return full;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@

import java.util.Objects;

import org.eclipse.winery.model.tosca.Definitions;
import org.eclipse.winery.model.tosca.TDefinitions;

public class LocalNameForAngular {

private final String id;
private final String text;
private final Definitions full;
private final TDefinitions full;

public LocalNameForAngular(String id, String text) {
this(id, text, null);
}

public LocalNameForAngular(String id, String text, Definitions full) {
public LocalNameForAngular(String id, String text, TDefinitions full) {
this.id = id;
this.text = text;
this.full = full;
Expand All @@ -41,7 +41,7 @@ public String getText() {
return text;
}

public Definitions getFull() {
public TDefinitions getFull() {
return full;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
import org.eclipse.winery.model.version.ToscaDiff;
import org.eclipse.winery.common.version.VersionUtils;
import org.eclipse.winery.common.version.WineryVersion;
import org.eclipse.winery.model.tosca.Definitions;
import org.eclipse.winery.model.tosca.TDefinitions;
import org.eclipse.winery.model.tosca.HasIdInIdOrNameField;
import org.eclipse.winery.model.tosca.OTComplianceRule;
import org.eclipse.winery.model.tosca.TEntityType;
Expand Down Expand Up @@ -123,7 +123,7 @@ public abstract class AbstractComponentInstanceResource implements Comparable<Ab
private final RepositoryFileReference ref;

// the object representing the data of this resource
private Definitions definitions = null;
private TDefinitions definitions = null;

/**
* Instantiates the resource. Assumes that the resource should exist (assured by the caller)
Expand Down Expand Up @@ -466,7 +466,7 @@ public String getDefinitionsAsXMLString() {
/**
* @return the reference to the internal Definitions object
*/
public Definitions getDefinitions() {
public TDefinitions getDefinitions() {
return this.definitions;
}

Expand All @@ -478,7 +478,7 @@ public RepositoryFileReference getRepositoryFileReference() {
@Consumes( {MimeTypes.MIMETYPE_TOSCA_DEFINITIONS, MediaType.APPLICATION_XML, MediaType.TEXT_XML})
public Response updateDefinitions(InputStream requestBodyStream) {
Unmarshaller u;
Definitions defs;
TDefinitions defs;
Document doc;
final StringBuilder sb = new StringBuilder();
try {
Expand All @@ -492,7 +492,7 @@ public Response updateDefinitions(InputStream requestBodyStream) {
}
try {
u = JAXBSupport.createUnmarshaller();
defs = (Definitions) u.unmarshal(doc);
defs = (TDefinitions) u.unmarshal(doc);
} catch (JAXBException e) {
AbstractComponentInstanceResource.LOGGER.debug("Could not unmarshal from request body stream", e);
return RestUtils.getResponseForException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package org.eclipse.winery.repository.rest.resources._support;

import org.eclipse.winery.model.ids.definitions.DefinitionsChildId;
import org.eclipse.winery.model.tosca.Definitions;
import org.eclipse.winery.model.tosca.TDefinitions;

import javax.ws.rs.WebApplicationException;
import java.io.IOException;
Expand All @@ -36,7 +36,7 @@ public String getDefinitionsAsXMLString() {
}

@Override
public Definitions getDefinitions() {
public TDefinitions getDefinitions() {
try {
this.synchronizeReferences();
} catch (IOException e) {
Expand Down
Loading

0 comments on commit 7512a63

Please sign in to comment.