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();
}
Aggregations