Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,12 @@
*******************************************************************************/
package de.dlr.sc.virsat.server.resources.model;

import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import java.util.Collections;

import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.edit.command.AddCommand;

import de.dlr.sc.virsat.model.concept.types.category.ABeanCategoryAssignment;
import de.dlr.sc.virsat.model.concept.types.category.BeanCategoryAssignment;
import de.dlr.sc.virsat.model.concept.types.category.IBeanCategoryAssignment;
import de.dlr.sc.virsat.model.concept.types.factory.BeanCategoryAssignmentFactory;
import de.dlr.sc.virsat.model.dvlm.categories.CategoriesPackage;
Expand All @@ -35,8 +25,8 @@
import de.dlr.sc.virsat.model.dvlm.structural.StructuralElementInstance;
import de.dlr.sc.virsat.server.dataaccess.RepositoryUtility;
import de.dlr.sc.virsat.server.resources.ApiErrorHelper;
import de.dlr.sc.virsat.server.resources.modelaccess.RepositoryAccessResource;
import de.dlr.sc.virsat.server.resources.modelaccess.ModelAccessResource;
import de.dlr.sc.virsat.server.resources.modelaccess.RepositoryAccessResource;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType;
Expand All @@ -46,6 +36,17 @@
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.security.SecurityScheme;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;


@Tag(name = RepositoryAccessResource.TAG_CA)
Expand Down Expand Up @@ -128,7 +129,7 @@ public Response getCa(@PathParam("caUuid") @Parameter(description = "Uuid of the
public Response putCa(@Parameter(description = "CA to put", required = true) ABeanCategoryAssignment bean) {
try {
parentResource.synchronize();
return Response.status(Response.Status.OK).build();
return Response.status(Response.Status.OK).entity(bean).build();
} catch (Exception e) {
return ApiErrorHelper.createInternalErrorResponse(e.getMessage());
}
Expand Down Expand Up @@ -174,14 +175,14 @@ public Response createCa(@PathParam("caUuid") @Parameter(description = "parent u
ActiveConceptHelper helper = new ActiveConceptHelper(parentResource.getEd().getResourceSet().getRepository());
Category category = helper.getCategory(fullQualifiedName);
CategoryAssignment newCa = new CategoryInstantiator().generateInstance(category, null);
newCa.setName(category.getName());

Command createCommand = AddCommand.create(parentResource.getEd(), parentSei, CategoriesPackage.Literals.ICATEGORY_ASSIGNMENT_CONTAINER__CATEGORY_ASSIGNMENTS, newCa);
Command createCommand = AddCommand.create(parentResource.getEd(), parentSei, CategoriesPackage.Literals.ICATEGORY_ASSIGNMENT_CONTAINER__CATEGORY_ASSIGNMENTS, Collections.singletonList(newCa));
ApiErrorHelper.executeCommandIffCanExecute(createCommand, parentResource.getEd(), parentResource.getUser());
IBeanCategoryAssignment newCaBean = new BeanCategoryAssignmentFactory().getInstanceFor(newCa);

parentResource.synchronize();

BeanCategoryAssignment newCaBean = new BeanCategoryAssignment();
newCaBean.setTypeInstance(newCa);

return Response.ok(newCaBean).build();
} catch (IllegalArgumentException e) {
return Response.status(Response.Status.FORBIDDEN).entity("Forbidden").build();
Expand Down