Search in sources :

Example 11 with PolicyTemplateId

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

the class RestUtils method create.

/**
 * Generates given TOSCA element and returns appropriate response code <br  />
 * <p>
 * In the case of an existing resource, the other possible return code is 302. This code has no Status constant,
 * therefore we use Status.CONFLICT, which is also possible.
 *
 * @return <ul> <li> <ul> <li>Status.CREATED (201) if the resource has been created,</li> <li>Status.CONFLICT if the
 * resource already exists,</li> <li>Status.INTERNAL_SERVER_ERROR (500) if something went wrong</li> </ul> </li>
 * <li>URI: the absolute URI of the newly created resource</li> </ul>
 */
public static ResourceResult create(GenericId id, String name) {
    ResourceResult res = new ResourceResult();
    if (RepositoryFactory.getRepository().exists(id)) {
        // res.setStatus(302);
        res.setStatus(Status.CONFLICT);
    } else {
        if (RepositoryFactory.getRepository().flagAsExisting(id)) {
            res.setStatus(Status.CREATED);
            // @formatter:off
            // This method is a generic method
            // We cannot return an "absolute" URL as the URL is always
            // relative to the caller
            // Does not work: String path = Environment.getUrlConfiguration().getRepositoryApiUrl()
            // + "/" +
            // Utils.getUrlPathForPathInsideRepo(id.getPathInsideRepo());
            // We distinguish between two cases: DefinitionsChildId and
            // TOSCAelementId
            // @formatter:on
            String path;
            if (id instanceof DefinitionsChildId) {
                // here, we return namespace + id, as it is only possible to
                // post on the definition child*s* resource to create an
                // instance of a definition child
                DefinitionsChildId tcId = (DefinitionsChildId) id;
                path = tcId.getNamespace().getEncoded() + "/" + tcId.getXmlId().getEncoded() + "/";
                // in case the resource additionally supports a name attribute, we set the original name
                if ((tcId instanceof ServiceTemplateId) || (tcId instanceof ArtifactTemplateId) || (tcId instanceof PolicyTemplateId)) {
                    // these three types have an additional name (instead of a pure id)
                    // we store the name
                    IHasName resource = (IHasName) AbstractComponentsResource.getComponentInstanceResource(tcId);
                    resource.setName(name);
                }
            } else {
                assert (id instanceof ToscaElementId);
                // We just return the id as we assume that only the parent
                // of this id may create sub elements
                path = id.getXmlId().getEncoded() + "/";
            }
            // we have to encode it twice to get correct URIs
            path = Util.getUrlPath(path);
            URI uri = URI.create(path);
            res.setUri(uri);
            res.setId(id);
        } else {
            res.setStatus(Status.INTERNAL_SERVER_ERROR);
        }
    }
    return res;
}
Also used : ToscaElementId(org.eclipse.winery.model.ids.elements.ToscaElementId) ResourceResult(org.eclipse.winery.repository.rest.resources._support.ResourceResult) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) PolicyTemplateId(org.eclipse.winery.model.ids.definitions.PolicyTemplateId) IHasName(org.eclipse.winery.repository.rest.resources._support.IHasName) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) URI(java.net.URI) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)

Example 12 with PolicyTemplateId

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

the class BackendUtilsTestWithGitBackedRepository method getVersionWithEditableFlagFromComponentWithoutAVersion.

@Test
public void getVersionWithEditableFlagFromComponentWithoutAVersion() throws Exception {
    this.setRevisionTo("origin/plain");
    PolicyTemplateId policyTemplateId = new PolicyTemplateId("http://plain.winery.opentosca.org/policytemplates", "PolicyTemplateWithoutProperties", false);
    List<WineryVersion> versions = WineryVersionUtils.getAllVersionsOfOneDefinition(policyTemplateId, repository);
    // For convenience, we accept editing already existing components without versions
    assertTrue(versions.get(0).isEditable());
}
Also used : PolicyTemplateId(org.eclipse.winery.model.ids.definitions.PolicyTemplateId) WineryVersion(org.eclipse.winery.common.version.WineryVersion) Test(org.junit.jupiter.api.Test)

Aggregations

PolicyTemplateId (org.eclipse.winery.model.ids.definitions.PolicyTemplateId)12 TPolicyTemplate (org.eclipse.winery.model.tosca.TPolicyTemplate)8 QName (javax.xml.namespace.QName)7 Test (org.junit.jupiter.api.Test)5 ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)4 TDefinitions (org.eclipse.winery.model.tosca.TDefinitions)4 ArtifactTypeId (org.eclipse.winery.model.ids.definitions.ArtifactTypeId)3 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)3 PolicyTypeId (org.eclipse.winery.model.ids.definitions.PolicyTypeId)3 RelationshipTypeId (org.eclipse.winery.model.ids.definitions.RelationshipTypeId)3 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)3 TPolicy (org.eclipse.winery.model.tosca.TPolicy)3 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)3 LinkedHashMap (java.util.LinkedHashMap)2 CapabilityTypeId (org.eclipse.winery.model.ids.definitions.CapabilityTypeId)2 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)2 InterfaceTypeId (org.eclipse.winery.model.ids.definitions.InterfaceTypeId)2 NodeTypeImplementationId (org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId)2 RelationshipTypeImplementationId (org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId)2 RequirementTypeId (org.eclipse.winery.model.ids.definitions.RequirementTypeId)2