Search in sources :

Example 1 with DefinitionsChildId

use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.

the class AbstractComponentInstanceResource method putId.

@POST
@Path("localName")
@Consumes(MediaType.APPLICATION_JSON)
public Response putId(RenameApiData data) {
    DefinitionsChildId newId;
    newId = BackendUtils.getDefinitionsChildId(this.getId().getClass(), this.getId().getNamespace().getDecoded(), data.localname, false);
    if (data.renameAllComponents) {
        return RestUtils.renameAllVersionsOfOneDefinition(this.getId(), newId);
    } else {
        return RestUtils.rename(this.getId(), newId).getResponse();
    }
}
Also used : DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 2 with DefinitionsChildId

use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.

the class RepositoryAdminResource method touchAllDefinitions.

@POST
@Path("touch")
public Response touchAllDefinitions() {
    try {
        IRepository repository = RepositoryFactory.getRepository();
        SortedSet<DefinitionsChildId> definitionIds = Stream.of(ArtifactTypeId.class, CapabilityTypeId.class, NodeTypeId.class, PolicyTypeId.class, RelationshipTypeId.class, RequirementTypeId.class, ServiceTemplateId.class, DataTypeId.class).flatMap(id -> repository.getAllDefinitionsChildIds(id).stream()).collect(Collectors.toCollection(TreeSet::new));
        for (DefinitionsChildId id : definitionIds) {
            TDefinitions definitions = repository.getDefinitions(id);
            BackendUtils.persist(repository, id, definitions);
        }
        return Response.ok().build();
    } catch (Exception e) {
        LOGGER.error("Error touching types: {}", e.getMessage(), e);
        return Response.serverError().build();
    }
}
Also used : PathParam(javax.ws.rs.PathParam) SortedSet(java.util.SortedSet) Produces(javax.ws.rs.Produces) FormDataContentDisposition(org.glassfish.jersey.media.multipart.FormDataContentDisposition) GET(javax.ws.rs.GET) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId) Path(javax.ws.rs.Path) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) LoggerFactory(org.slf4j.LoggerFactory) TreeSet(java.util.TreeSet) MediaType(javax.ws.rs.core.MediaType) Consumes(javax.ws.rs.Consumes) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) DELETE(javax.ws.rs.DELETE) PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) MultiRepository(org.eclipse.winery.repository.filebased.MultiRepository) RepositoryProperties(org.eclipse.winery.repository.backend.filebased.RepositoryProperties) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) StreamingOutput(javax.ws.rs.core.StreamingOutput) Collectors(java.util.stream.Collectors) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) List(java.util.List) FormDataParam(org.glassfish.jersey.media.multipart.FormDataParam) Stream(java.util.stream.Stream) GitBasedRepository(org.eclipse.winery.repository.backend.filebased.GitBasedRepository) Response(javax.ws.rs.core.Response) MultiRepositoryManager(org.eclipse.winery.repository.filebased.MultiRepositoryManager) IRepository(org.eclipse.winery.repository.backend.IRepository) DataTypeId(org.eclipse.winery.model.ids.definitions.DataTypeId) InputStream(java.io.InputStream) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) IRepository(org.eclipse.winery.repository.backend.IRepository) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 3 with DefinitionsChildId

use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.

the class BackendUtils method compare.

public static ToscaDiff compare(DefinitionsChildId id, WineryVersion versionToCompareTo, IRepository repository) {
    DefinitionsChildId versionToCompare = VersionSupport.getDefinitionInTheGivenVersion(id, versionToCompareTo);
    TExtensibleElements workingVersion = repository.getDefinitions(id).getElement();
    TExtensibleElements baseVersion = repository.getDefinitions(versionToCompare).getElement();
    return VersionSupport.calculateDifferences(baseVersion, workingVersion);
}
Also used : DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) TExtensibleElements(org.eclipse.winery.model.tosca.TExtensibleElements)

Example 4 with DefinitionsChildId

use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.

the class IRepository method getReferencedDefinitionsChildIds.

default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(RequirementTypeId id) {
    Collection<DefinitionsChildId> ids = new ArrayList<>(1);
    final TRequirementType element = this.getElement(id);
    QName requiredCapabilityType = element.getRequiredCapabilityType();
    if (requiredCapabilityType != null) {
        CapabilityTypeId capId = new CapabilityTypeId(requiredCapabilityType);
        ids.add(capId);
    }
    return ids;
}
Also used : DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) TRequirementType(org.eclipse.winery.model.tosca.TRequirementType)

Example 5 with DefinitionsChildId

use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.

the class IRepository method getReferencedDefinitionsChildIds.

default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(NodeTypeId id) {
    Collection<NodeTypeImplementationId> allNodeTypeImplementations = this.getAllElementsReferencingGivenType(NodeTypeImplementationId.class, id.getQName());
    Collection<DefinitionsChildId> ids = new HashSet<>(allNodeTypeImplementations);
    final TNodeType nodeType = this.getElement(id);
    // Add all referenced requirement types, but only in XML mode.
    // For YAML mode add referenced RelationshipType and CapabilityType, if present
    List<TRequirementDefinition> reqDefs = nodeType.getRequirementDefinitions();
    if (reqDefs != null) {
        for (TRequirementDefinition reqDef : reqDefs) {
            // if either of these is set, we're dealing with a type defined in YAML
            if (Objects.nonNull(reqDef.getRelationship()) || Objects.nonNull(reqDef.getCapability()) || Objects.nonNull(reqDef.getNode())) {
                if (Objects.nonNull(reqDef.getRelationship())) {
                    ids.add(new RelationshipTypeId(reqDef.getRelationship()));
                }
                if (Objects.nonNull(reqDef.getCapability())) {
                    ids.add(new CapabilityTypeId(reqDef.getCapability()));
                }
                if (Objects.nonNull(reqDef.getNode())) {
                    ids.add(new NodeTypeId(reqDef.getNode()));
                }
            } else {
                RequirementTypeId reqTypeId = new RequirementTypeId(reqDef.getRequirementType());
                ids.add(reqTypeId);
            }
        }
    }
    // add all referenced capability types
    List<TCapabilityDefinition> capabilityDefinitions = nodeType.getCapabilityDefinitions();
    if (capabilityDefinitions != null) {
        for (TCapabilityDefinition capDef : capabilityDefinitions) {
            CapabilityTypeId capTypeId = new CapabilityTypeId(capDef.getCapabilityType());
            ids.add(capTypeId);
            // Add all types referenced in valid source types
            if (Objects.nonNull(capDef.getValidSourceTypes())) {
                capDef.getValidSourceTypes().forEach(sourceType -> ids.add(new NodeTypeId(sourceType)));
            }
        }
    }
    List<TInterfaceDefinition> interfaceDefinitions = nodeType.getInterfaceDefinitions();
    if (Objects.nonNull(interfaceDefinitions) && !interfaceDefinitions.isEmpty()) {
        for (TInterfaceDefinition intDef : interfaceDefinitions) {
            InterfaceTypeId interfaceTypeId = new InterfaceTypeId(intDef.getType());
            ids.add(interfaceTypeId);
        }
    }
    // Store all referenced artifact types
    List<TArtifact> artifacts = nodeType.getArtifacts();
    if (Objects.nonNull(artifacts)) {
        artifacts.forEach(a -> ids.add(new ArtifactTypeId(a.getType())));
    }
    getReferencedDefinitionsOfProperties(ids, nodeType.getProperties());
    return ids;
}
Also used : NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) TNodeType(org.eclipse.winery.model.tosca.TNodeType) InterfaceTypeId(org.eclipse.winery.model.ids.definitions.InterfaceTypeId) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId) TArtifact(org.eclipse.winery.model.tosca.TArtifact) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TRequirementDefinition(org.eclipse.winery.model.tosca.TRequirementDefinition) TCapabilityDefinition(org.eclipse.winery.model.tosca.TCapabilityDefinition) TInterfaceDefinition(org.eclipse.winery.model.tosca.TInterfaceDefinition) HashSet(java.util.HashSet)

Aggregations

DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)77 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)29 Test (org.junit.jupiter.api.Test)21 QName (javax.xml.namespace.QName)19 IOException (java.io.IOException)18 ArrayList (java.util.ArrayList)17 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)16 TDefinitions (org.eclipse.winery.model.tosca.TDefinitions)16 HashMap (java.util.HashMap)15 IRepository (org.eclipse.winery.repository.backend.IRepository)14 TNodeType (org.eclipse.winery.model.tosca.TNodeType)13 Path (java.nio.file.Path)12 Map (java.util.Map)12 RelationshipTypeId (org.eclipse.winery.model.ids.definitions.RelationshipTypeId)12 TExtensibleElements (org.eclipse.winery.model.tosca.TExtensibleElements)12 Logger (org.slf4j.Logger)11 LoggerFactory (org.slf4j.LoggerFactory)11 InputStream (java.io.InputStream)10 HashSet (java.util.HashSet)10 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)10