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