Search in sources :

Example 66 with DefinitionsChildId

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

the class RestUtils method renameAllVersionsOfOneDefinition.

public static Response renameAllVersionsOfOneDefinition(DefinitionsChildId oldId, DefinitionsChildId newId) {
    SortedSet<? extends DefinitionsChildId> definitions = WineryVersionUtils.getOtherVersionDefinitionsFromDefinition(oldId, RepositoryFactory.getRepository());
    Response finalResponse = null;
    for (DefinitionsChildId definition : definitions) {
        ResourceResult response = rename(definition, newId);
        if (response.getStatus() == Status.INTERNAL_SERVER_ERROR) {
            return response.getResponse();
        }
        if (Objects.isNull(finalResponse) || definition.equals(oldId)) {
            finalResponse = response.getResponse();
        }
    }
    return finalResponse;
}
Also used : Response(javax.ws.rs.core.Response) ResourceResult(org.eclipse.winery.repository.rest.resources._support.ResourceResult) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId)

Example 67 with DefinitionsChildId

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

the class AbstractComponentsResource method getAll.

/**
 * Returns resources for all known component instances
 * <p>
 * Required by XaaSPackager logic
 * <p>
 * TODO: remove that method and refactor callers
 */
public Collection<AbstractComponentInstanceResource> getAll() {
    Class<? extends DefinitionsChildId> idClass = RestUtils.getComponentIdClassForComponentContainer(this.getClass());
    SortedSet<? extends DefinitionsChildId> allDefinitionsChildIds = RepositoryFactory.getRepository().getAllDefinitionsChildIds(idClass);
    ArrayList<AbstractComponentInstanceResource> res = new ArrayList<>(allDefinitionsChildIds.size());
    for (DefinitionsChildId id : allDefinitionsChildIds) {
        AbstractComponentInstanceResource r = AbstractComponentsResource.getComponentInstanceResource(id);
        res.add(r);
    }
    return res;
}
Also used : DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) ArrayList(java.util.ArrayList)

Example 68 with DefinitionsChildId

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

the class AbstractComponentsResource method onPost.

/**
 * Creates a new component instance in the given namespace
 *
 * @param namespace plain namespace
 * @param name      the name; used as id
 */
protected ResourceResult onPost(String namespace, String name) {
    ResourceResult res;
    if (StringUtils.isEmpty(namespace) || StringUtils.isEmpty(name)) {
        res = new ResourceResult(Status.BAD_REQUEST);
    } else {
        String id = RestUtils.createXmlIdAsString(name);
        DefinitionsChildId tcId;
        try {
            tcId = this.getDefinitionsChildId(namespace, id, false);
            res = RestUtils.create(tcId, name);
            res.setMessage(getComponentInstanceResource(tcId).getElement());
        } catch (Exception e) {
            AbstractComponentsResource.LOGGER.debug("Could not create id instance", e);
            res = new ResourceResult(Status.INTERNAL_SERVER_ERROR);
        }
    }
    return res;
}
Also used : DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) NotFoundException(javax.ws.rs.NotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 69 with DefinitionsChildId

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

the class AbstractComponentsWithoutTypeReferenceResource method onJsonPost.

/**
 * Creates a new component instance in the given namespace
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response onJsonPost(QNameApiData jsonData) {
    ResourceResult creationResult = super.onPost(jsonData.namespace, jsonData.localname);
    DefinitionsChildId definitionsChildId = this.getDefinitionsChildId(jsonData.namespace, jsonData.localname, false);
    creationResult.setMessage(RepositoryFactory.getRepository().getElement(definitionsChildId));
    return creationResult.getResponse();
}
Also used : DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 70 with DefinitionsChildId

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

the class AbstractComponentsWithTypeReferenceResource method onJsonPost.

@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response onJsonPost(QNameWithTypeApiData jsonData) {
    // only check for type parameter as namespace and name are checked in super.onPost
    if (StringUtils.isEmpty(jsonData.type)) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    ResourceResult creationResult = super.onPost(jsonData.namespace, jsonData.localname);
    if (!creationResult.isSuccess()) {
        return creationResult.getResponse();
    }
    if (creationResult.getStatus().equals(Status.CREATED)) {
        final DefinitionsChildId id = (DefinitionsChildId) creationResult.getId();
        final TDefinitions definitions = requestRepository.getDefinitions(id);
        final TExtensibleElements element = definitions.getElement();
        ((HasType) element).setType(jsonData.type);
        if (id instanceof EntityTemplateId) {
            BackendUtils.initializeProperties(requestRepository, (TEntityTemplate) element);
        }
        try {
            BackendUtils.persist(requestRepository, id, definitions);
        } catch (IOException e) {
            throw new WebApplicationException(e);
        }
    }
    return creationResult.getResponse();
}
Also used : EntityTemplateId(org.eclipse.winery.model.ids.definitions.EntityTemplateId) WebApplicationException(javax.ws.rs.WebApplicationException) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) HasType(org.eclipse.winery.model.tosca.HasType) TExtensibleElements(org.eclipse.winery.model.tosca.TExtensibleElements) IOException(java.io.IOException) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

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