Skip to content

Commit

Permalink
Merge branch 'main' into feat/improve_samm_mapping
Browse files Browse the repository at this point in the history
# Conflicts:
#	DEPENDENCIES_BACKEND
#	backend/DEPENDENCIES
  • Loading branch information
eschrewe committed Oct 12, 2023
2 parents 8d8080a + 83f8fab commit 69ab001
Show file tree
Hide file tree
Showing 23 changed files with 951 additions and 213 deletions.
171 changes: 85 additions & 86 deletions DEPENDENCIES_BACKEND

Large diffs are not rendered by default.

171 changes: 85 additions & 86 deletions backend/DEPENDENCIES

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions backend/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ mvn install

# run for demo or development puroposes
# customer role
mvn spring-boot:run -Dspring-boot.run.arguments=--spring.profiles.active=customer
mvn spring-boot:run -Dspring-boot.run.arguments=--spring.config.location="./src/main/resources/application-customer.properties"

# supplier role
mvn spring-boot:run -Dspring-boot.run.arguments=--spring.profiles.active=supplier
mvn spring-boot:run -Dspring-boot.run.arguments=--spring.config.location="./src/main/resources/application-supplier.properties"
```
5. Done! The Swagger UI should be available at
- (Java & Docker) `http://YOURIP:8081/catena/swagger-ui/index.html`
Expand Down
Empty file modified backend/mvnw
100644 → 100755
Empty file.
29 changes: 14 additions & 15 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.2</version>
<version>3.1.4</version>
<relativePath/>
</parent>
<groupId>org.eclipse.tractusx.puris</groupId>
Expand All @@ -41,6 +41,7 @@
<springdoc.version>2.1.0</springdoc.version>
<okhttp3.version>2.7.5</okhttp3.version>
<hibernate-validator.version>8.0.0.Final</hibernate-validator.version>
<snakeyaml.version>2.2</snakeyaml.version>
</properties>
<dependencies>
<dependency>
Expand All @@ -59,12 +60,6 @@
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
Expand Down Expand Up @@ -116,21 +111,25 @@
</dependencies>

<pluginRepositories>
<pluginRepository>
<id>dash-licenses-snapshots</id>
<url>https://repo.eclipse.org/content/repositories/dash-licenses-snapshots/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<!-- <pluginRepository>-->
<!-- <id>dash-licenses-snapshots</id>-->
<!-- <url>https://repo.eclipse.org/content/repositories/dash-licenses-snapshots/</url>-->
<!-- <snapshots>-->
<!-- <enabled>true</enabled>-->
<!-- </snapshots>-->
<!-- </pluginRepository>-->
<pluginRepository>
<id>dash-licenses</id>
<url>https://repo.eclipse.org/content/repositories/dash-licenses</url>
</pluginRepository>
</pluginRepositories>

<build>
<plugins>
<plugin>
<groupId>org.eclipse.dash</groupId>
<artifactId>license-tool-plugin</artifactId>
<version>1.0.3-SNAPSHOT</version>
<version>1.0.2</version>
<configuration>
<projectId>automotive.tractusx</projectId>
<!-- name of dependencies file -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,12 @@ private Partner createAndGetSupplierPartner() {
private Partner createAndGetNonScenarioCustomer() {
Partner nonScenarioCustomer = new Partner(
"Non-Scenario Customer",
"(None Provided!)>",
"http://nonscenario-customer.com/api/v1/ids",
"BPNL2222222222RR",
"BPNS2222222222XZ",
"Zentraleinkaufsabteilung",
"BPNA2222222222HH",
"54.321N, 8.7654E"
"BPNA2222222222XZ",
"Fichtenweg 23",
"65432 Waldhausen",
"Germany"
);
nonScenarioCustomer = partnerService.create(nonScenarioCustomer);
log.info(String.format("Created non-scenario customer partner: %s", nonScenarioCustomer));
Expand Down
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));
}
}
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));
}

}
Loading

0 comments on commit 69ab001

Please sign in to comment.