-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/improve_samm_mapping
# Conflicts: # DEPENDENCIES_BACKEND # backend/DEPENDENCIES
- Loading branch information
Showing
23 changed files
with
951 additions
and
213 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
backend/src/main/java/org/eclipse/tractusx/puris/backend/controller/MaterialController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/* | ||
* Copyright (c) 2023 Volkswagen AG | ||
* Copyright (c) 2023 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. | ||
* (represented by Fraunhofer ISST) | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.eclipse.tractusx.puris.backend.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import org.eclipse.tractusx.puris.backend.masterdata.domain.model.Material; | ||
import org.eclipse.tractusx.puris.backend.masterdata.logic.dto.MaterialEntityDto; | ||
import org.eclipse.tractusx.puris.backend.masterdata.logic.service.MaterialService; | ||
import org.modelmapper.ModelMapper; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatusCode; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@RestController | ||
@RequestMapping("materials") | ||
public class MaterialController { | ||
|
||
@Autowired | ||
private MaterialService materialService; | ||
private ModelMapper modelMapper = new ModelMapper(); | ||
|
||
@PostMapping | ||
@CrossOrigin | ||
@Operation(description = "Creates a new Material entity with the data given in the request body. As a bare minimum, " + | ||
"it must contain a new, unique ownMaterialNumber.") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "Successfully created a new Material entity."), | ||
@ApiResponse(responseCode = "400", description = "Malformed request body."), | ||
@ApiResponse(responseCode = "409", description = "Material with the given ownMaterialNumber already exists."), | ||
@ApiResponse(responseCode = "500", description = "Internal Server error.") | ||
}) | ||
public ResponseEntity<?> createMaterial(@RequestBody MaterialEntityDto materialDto) { | ||
if (materialDto.getOwnMaterialNumber() == null || materialDto.getOwnMaterialNumber().isEmpty()) { | ||
// Cannot create material without ownMaterialNumber | ||
return new ResponseEntity<>(HttpStatusCode.valueOf(400)); | ||
} | ||
if (materialService.findByOwnMaterialNumber(materialDto.getOwnMaterialNumber()) != null) { | ||
// Cannot create material, ownMaterialNumber is already assigned | ||
return new ResponseEntity<>(HttpStatusCode.valueOf(409)); | ||
} | ||
Material createdMaterial; | ||
try { | ||
createdMaterial = modelMapper.map(materialDto, Material.class); | ||
} catch (Exception e) { | ||
return new ResponseEntity<>(HttpStatusCode.valueOf(400)); | ||
} | ||
|
||
createdMaterial = materialService.create(createdMaterial); | ||
if (createdMaterial == null) { | ||
return new ResponseEntity<>(HttpStatusCode.valueOf(500)); | ||
} | ||
|
||
return new ResponseEntity<>(HttpStatusCode.valueOf(200)); | ||
} | ||
|
||
@PutMapping | ||
@CrossOrigin | ||
@Operation(description = "Updates an existing Material entity with the data given in the request body.") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "Update was accepted."), | ||
@ApiResponse(responseCode = "400", description = "Malformed request body."), | ||
@ApiResponse(responseCode = "404", description = "No existing Material Entity found, no update was performed."), | ||
@ApiResponse(responseCode = "500", description = "Internal Server Error.") | ||
}) | ||
public ResponseEntity<?> updateMaterial(@RequestBody MaterialEntityDto materialDto) { | ||
if (materialDto.getOwnMaterialNumber() == null || materialDto.getOwnMaterialNumber().isEmpty()) { | ||
// Cannot update material without ownMaterialNumber | ||
return new ResponseEntity<>(HttpStatusCode.valueOf(400)); | ||
} | ||
Material existingMaterial = materialService.findByOwnMaterialNumber(materialDto.getOwnMaterialNumber()); | ||
if (existingMaterial == null) { | ||
// Cannot update non-existent Material | ||
return new ResponseEntity<>(HttpStatusCode.valueOf(404)); | ||
} | ||
Material updatedMaterial; | ||
try { | ||
updatedMaterial = modelMapper.map(materialDto, Material.class); | ||
} catch (Exception e) { | ||
return new ResponseEntity<>(HttpStatusCode.valueOf(400)); | ||
} | ||
updatedMaterial = materialService.update(updatedMaterial); | ||
if (updatedMaterial == null) { | ||
return new ResponseEntity<>(HttpStatusCode.valueOf(500)); | ||
} | ||
|
||
return new ResponseEntity<>(HttpStatusCode.valueOf(200)); | ||
} | ||
|
||
@GetMapping | ||
@CrossOrigin | ||
@Operation(description = "Returns the requested Material dto, specified by the given ownMaterialNumber.") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "Returns the requested Material."), | ||
@ApiResponse(responseCode = "404", description = "Requested Material was not found.") | ||
}) | ||
public ResponseEntity<MaterialEntityDto> getMaterial(@Parameter(name = "ownMaterialNumber", | ||
description = "The Material Number that is used in your own company to identify the Material.", | ||
example = "MNR-7307-AU340474.002") @RequestParam String ownMaterialNumber) { | ||
Material foundMaterial = materialService.findByOwnMaterialNumber(ownMaterialNumber); | ||
if (foundMaterial == null) { | ||
return new ResponseEntity<>(HttpStatusCode.valueOf(404)); | ||
} | ||
|
||
MaterialEntityDto dto = modelMapper.map(foundMaterial, MaterialEntityDto.class); | ||
return new ResponseEntity<>(dto, HttpStatusCode.valueOf(200)); | ||
} | ||
|
||
@CrossOrigin | ||
@GetMapping("/all") | ||
@Operation(description = "Returns a list of all Materials and Products.") | ||
public ResponseEntity<List<MaterialEntityDto>> listMaterials() { | ||
return new ResponseEntity<>(materialService.findAll(). | ||
stream().map(x -> modelMapper.map(x, MaterialEntityDto.class)).collect(Collectors.toList()), | ||
HttpStatusCode.valueOf(200)); | ||
} | ||
} |
148 changes: 148 additions & 0 deletions
148
...ava/org/eclipse/tractusx/puris/backend/controller/MaterialPartnerRelationsController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/* | ||
* Copyright (c) 2023 Volkswagen AG | ||
* Copyright (c) 2023 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. | ||
* (represented by Fraunhofer ISST) | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.eclipse.tractusx.puris.backend.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import org.eclipse.tractusx.puris.backend.masterdata.domain.model.Material; | ||
import org.eclipse.tractusx.puris.backend.masterdata.domain.model.MaterialPartnerRelation; | ||
import org.eclipse.tractusx.puris.backend.masterdata.domain.model.Partner; | ||
import org.eclipse.tractusx.puris.backend.masterdata.logic.service.MaterialPartnerRelationService; | ||
import org.eclipse.tractusx.puris.backend.masterdata.logic.service.MaterialService; | ||
import org.eclipse.tractusx.puris.backend.masterdata.logic.service.PartnerService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatusCode; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.UUID; | ||
|
||
@RestController | ||
@RequestMapping("materialpartnerrelations") | ||
public class MaterialPartnerRelationsController { | ||
|
||
|
||
@Autowired | ||
private MaterialService materialService; | ||
|
||
@Autowired | ||
private PartnerService partnerService; | ||
|
||
@Autowired | ||
private MaterialPartnerRelationService mprService; | ||
|
||
@PostMapping | ||
@CrossOrigin | ||
@Operation(description = "Creates a new MaterialPartnerRelation with the given parameter data. " + | ||
"Please note that this is only possible, if the designated Material " + | ||
"and Partner entities have already been created before this request. ") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "Successfully created a new MaterialPartnerRelationEntity."), | ||
@ApiResponse(responseCode = "400", description = "Material and/or Partner do not exist."), | ||
@ApiResponse(responseCode = "409", description = "Relation for given Material and Partner does already exist."), | ||
@ApiResponse(responseCode = "500", description = "Internal Server Error.") | ||
}) | ||
public ResponseEntity<?> createMaterialPartnerRelation( | ||
@Parameter(description = "The Material Number that is used in your own company to identify the Material.", | ||
example = "MNR-7307-AU340474.002") @RequestParam String ownMaterialNumber, | ||
@Parameter(description = "The unique BPNL that was assigned to that Partner.", | ||
example = "BPNL2222222222RR") @RequestParam() String partnerBpnl, | ||
@Parameter(description = "The Material Number that this Partner is using in his own company to identify the Material.", | ||
example = "MNR-8101-ID146955.001") @RequestParam String partnerMaterialNumber, | ||
@Parameter(description = "This boolean flag indicates whether this Partner is a potential supplier of the given Material.", | ||
example = "true") @RequestParam boolean partnerSupplies, | ||
@Parameter(description = "This boolean flag indicates whether this Partner is a potential customer of this Material.", | ||
example = "true") @RequestParam boolean partnerBuys) { | ||
Material material = materialService.findByOwnMaterialNumber(ownMaterialNumber); | ||
if (material == null || partnerBpnl == null) { | ||
return new ResponseEntity<>(HttpStatusCode.valueOf(400)); | ||
} | ||
Partner partner = null; | ||
if (partnerBpnl != null) { | ||
partner = partnerService.findByBpnl(partnerBpnl); | ||
} | ||
if (partner == null) { | ||
return new ResponseEntity<>(HttpStatusCode.valueOf(400)); | ||
} | ||
|
||
if (mprService.find(material, partner) != null) { | ||
return new ResponseEntity<>(HttpStatusCode.valueOf(409)); | ||
} | ||
MaterialPartnerRelation newMpr = new MaterialPartnerRelation(material, partner, partnerMaterialNumber, partnerSupplies, partnerBuys); | ||
|
||
newMpr = mprService.create(newMpr); | ||
if (newMpr == null) { | ||
return new ResponseEntity<>(HttpStatusCode.valueOf(500)); | ||
} | ||
|
||
return new ResponseEntity<>(HttpStatusCode.valueOf(200)); | ||
} | ||
|
||
@PutMapping | ||
@CrossOrigin | ||
@Operation(description = "Updates an existing MaterialPartnerRelation. You have to specify the ownMaterialNumber and " + | ||
"the partnerBpnl. The other three parameters are genuinely optional. Provide them only if you want to change their values. ") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "Update was accepted."), | ||
@ApiResponse(responseCode = "404", description = "No existing entity was found."), | ||
@ApiResponse(responseCode = "500", description = "Internal Server Error.") | ||
}) | ||
public ResponseEntity<?> updateMaterialPartnerRelation( | ||
@Parameter(description = "The Material Number that is used in your own company to identify the Material.", | ||
example = "MNR-7307-AU340474.002") @RequestParam String ownMaterialNumber, | ||
@Parameter(description = "The unique BPNL that was assigned to that Partner.", | ||
example = "BPNL2222222222RR") @RequestParam() String partnerBpnl, | ||
@Parameter(description = "The Material Number that this Partner is using in his own company to identify the Material.", | ||
example = "MNR-8101-ID146955.001") @RequestParam(required = false) String partnerMaterialNumber, | ||
@Parameter(description = "This boolean flag indicates whether this Partner is a potential supplier of the given Material.", | ||
example = "true") @RequestParam(required = false) Boolean partnerSupplies, | ||
@Parameter(description = "This boolean flag indicates whether this Partner is a potential customer of this Material.", | ||
example = "true") @RequestParam(required = false) Boolean partnerBuys) { | ||
MaterialPartnerRelation existingRelation = null; | ||
Partner partner = partnerService.findByBpnl(partnerBpnl); | ||
Material material = materialService.findByOwnMaterialNumber(ownMaterialNumber); | ||
if (partner != null && material != null) { | ||
existingRelation = mprService.find(material, partner); | ||
} | ||
if (existingRelation == null) { | ||
return new ResponseEntity<>(HttpStatusCode.valueOf(404)); | ||
} | ||
if (partnerSupplies != null) { | ||
existingRelation.setPartnerSuppliesMaterial(partnerSupplies); | ||
} | ||
if (partnerBuys != null) { | ||
existingRelation.setPartnerBuysMaterial(partnerBuys); | ||
} | ||
if (partnerMaterialNumber != null) { | ||
existingRelation.setPartnerMaterialNumber(partnerMaterialNumber); | ||
} | ||
existingRelation = mprService.update(existingRelation); | ||
if (existingRelation == null) { | ||
return new ResponseEntity<>(HttpStatusCode.valueOf(500)); | ||
} | ||
|
||
return new ResponseEntity<>(HttpStatusCode.valueOf(200)); | ||
} | ||
|
||
} |
Oops, something went wrong.