Search in sources :

Example 21 with Definitions

use of org.eclipse.winery.model.tosca.Definitions 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();
    }
    ResourceCreationResult 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 IRepository repository = RepositoryFactory.getRepository();
        final Definitions definitions = repository.getDefinitions(id);
        final TExtensibleElements element = definitions.getElement();
        ((HasType) element).setType(jsonData.type);
        if (id instanceof EntityTemplateId) {
            BackendUtils.initializeProperties(repository, (TEntityTemplate) element);
        }
        try {
            BackendUtils.persist(id, definitions);
        } catch (IOException e) {
            throw new WebApplicationException(e);
        }
    }
    return creationResult.getResponse();
}
Also used : EntityTemplateId(org.eclipse.winery.common.ids.definitions.EntityTemplateId) WebApplicationException(javax.ws.rs.WebApplicationException) DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) Definitions(org.eclipse.winery.model.tosca.Definitions) HasType(org.eclipse.winery.model.tosca.HasType) TExtensibleElements(org.eclipse.winery.model.tosca.TExtensibleElements) IOException(java.io.IOException) IRepository(org.eclipse.winery.repository.backend.IRepository) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Aggregations

Definitions (org.eclipse.winery.model.tosca.Definitions)21 RepositoryFileReference (org.eclipse.winery.common.RepositoryFileReference)7 TDefinitions (org.eclipse.winery.model.tosca.TDefinitions)7 IOException (java.io.IOException)6 JAXBException (javax.xml.bind.JAXBException)5 QName (javax.xml.namespace.QName)5 Test (org.junit.Test)5 Unmarshaller (javax.xml.bind.Unmarshaller)4 TServiceTemplate (org.eclipse.winery.model.tosca.yaml.TServiceTemplate)4 BufferedInputStream (java.io.BufferedInputStream)3 InputStream (java.io.InputStream)3 DefinitionsChildId (org.eclipse.winery.common.ids.definitions.DefinitionsChildId)3 PolicyTemplateId (org.eclipse.winery.common.ids.definitions.PolicyTemplateId)3 TArtifactTemplate (org.eclipse.winery.model.tosca.TArtifactTemplate)3 TEntityType (org.eclipse.winery.model.tosca.TEntityType)3 TExtensibleElements (org.eclipse.winery.model.tosca.TExtensibleElements)3 TImport (org.eclipse.winery.model.tosca.TImport)3 TPolicyTemplate (org.eclipse.winery.model.tosca.TPolicyTemplate)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 URI (java.net.URI)2