Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: base64 encoding #512

Merged
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package org.eclipse.tractusx.puris.backend.delivery.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
Expand Down Expand Up @@ -48,6 +49,7 @@
import org.springframework.web.server.ResponseStatusException;

import javax.management.openmbean.KeyAlreadyExistsException;
import java.util.Base64;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
Expand Down Expand Up @@ -92,7 +94,8 @@ public class DeliveryController {
@ResponseBody
@Operation(summary = "Get all planned deliveries for the given Material",
description = "Get all planned deliveries for the given material number. Optionally a bpns and partner bpnl can be provided to filter the deliveries further.")
public List<DeliveryDto> getAllDeliveries(String ownMaterialNumber, Optional<String> bpns, Optional<String> bpnl) {
public List<DeliveryDto> getAllDeliveries(@Parameter(description = "encoded in base64") String ownMaterialNumber, Optional<String> bpns, Optional<String> bpnl) {
ownMaterialNumber = new String(Base64.getDecoder().decode(ownMaterialNumber));
Material material = materialService.findByOwnMaterialNumber(ownMaterialNumber);
if (material == null) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Material does not exist.");
Expand Down Expand Up @@ -179,7 +182,9 @@ public void deleteDelivery(@PathVariable UUID id) {
summary = "Refreshes all reported deliveries",
description = "Refreshes all reported deliveries from the delivery request API."
)
public ResponseEntity<List<PartnerDto>> refreshReportedDeliveries(@RequestParam String ownMaterialNumber) {
public ResponseEntity<List<PartnerDto>> refreshReportedDeliveries(
@RequestParam @Parameter(description = "encoded in base64") String ownMaterialNumber) {
ownMaterialNumber = new String(Base64.getDecoder().decode(ownMaterialNumber));
if (!materialPattern.matcher(ownMaterialNumber).matches()) {
return new ResponseEntity<>(HttpStatusCode.valueOf(400));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ See the NOTICE file(s) distributed with this work for additional
package org.eclipse.tractusx.puris.backend.demand.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
Expand All @@ -46,6 +47,7 @@ See the NOTICE file(s) distributed with this work for additional
import org.springframework.web.server.ResponseStatusException;

import javax.management.openmbean.KeyAlreadyExistsException;
import java.util.Base64;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
Expand Down Expand Up @@ -88,7 +90,8 @@ public class DemandController {
@GetMapping()
@ResponseBody
@Operation(summary = "Get all own demands for the given Material", description = "Get all own demands for the given material number. Optionally the demanding site can be filtered by its bpns.")
public List<DemandDto> getAllDemands(String ownMaterialNumber, Optional<String> site) {
public List<DemandDto> getAllDemands(@Parameter(description = "encoded in base64") String ownMaterialNumber, Optional<String> site) {
ownMaterialNumber = new String(Base64.getDecoder().decode(ownMaterialNumber));
return ownDemandService.findAllByFilters(Optional.of(ownMaterialNumber), Optional.empty(), site, Optional.empty())
.stream().map(this::convertToDto).collect(Collectors.toList());
}
Expand Down Expand Up @@ -167,8 +170,11 @@ public void deleteDemand(@PathVariable UUID id) {
summary = "Get all demands of partners for a material",
description = "Get all demands of partners for a material number. Optionally the partners can be filtered by their bpnl and the demanding site can be filtered by its bpns."
)
public List<DemandDto> getAllDemandsForPartner(String ownMaterialNumber, Optional<String> bpnl,
public List<DemandDto> getAllDemandsForPartner(@Parameter(description = "encoded in base64") String ownMaterialNumber, Optional<String> bpnl,
Optional<String> site) {
if (ownMaterialNumber != null) {
ownMaterialNumber = new String(Base64.getDecoder().decode(ownMaterialNumber));
}
return reportedDemandService.findAllByFilters(Optional.of(ownMaterialNumber), bpnl, site, Optional.empty())
.stream().map(this::convertToDto).collect(Collectors.toList());
}
Expand All @@ -179,7 +185,9 @@ public List<DemandDto> getAllDemandsForPartner(String ownMaterialNumber, Optiona
summary = "Refreshes all reported demands",
description = "Refreshes all reported demands from the demand request API."
)
public ResponseEntity<List<PartnerDto>> refreshReportedProductions(@RequestParam String ownMaterialNumber) {
public ResponseEntity<List<PartnerDto>> refreshReportedProductions(
@RequestParam @Parameter(description = "encoded in base64") String ownMaterialNumber) {
ownMaterialNumber = new String(Base64.getDecoder().decode(ownMaterialNumber));
if (!materialPattern.matcher(ownMaterialNumber).matches()) {
return new ResponseEntity<>(HttpStatusCode.valueOf(400));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Base64;
import java.util.Date;
import java.util.UUID;

Expand Down Expand Up @@ -71,10 +72,12 @@ public class ErpAdapterController {
@PostMapping("/trigger")
public ResponseEntity<?> scheduleErpUpdate(
@RequestParam("partner-bpnl") String bpnl,
@RequestParam("own-materialnumber") String materialNumber,
@RequestParam("own-materialnumber")
@Parameter(description = "encoded in base64") String materialNumber,
@RequestParam("asset-type") AssetType assetType,
@RequestParam(required = false, value = "direction") DirectionCharacteristic directionCharacteristic
) {
materialNumber = new String(Base64.getDecoder().decode(materialNumber));
boolean valid = BPNL_PATTERN.matcher(bpnl).matches()
&& NON_EMPTY_NON_VERTICAL_WHITESPACE_PATTERN.matcher(materialNumber).matches();
if (valid && mprService.find(bpnl, materialNumber) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Base64;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -135,8 +136,9 @@ public ResponseEntity<?> updateMaterial(@RequestBody MaterialEntityDto materialD
@ApiResponse(responseCode = "404", description = "Requested Material was not found.", content = @Content)
})
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) {
description = "The Material Number that is used in your own company to identify the Material, encoded in base64"
) @RequestParam String ownMaterialNumber) {
ownMaterialNumber = new String(Base64.getDecoder().decode(ownMaterialNumber));
if(!materialPattern.matcher(ownMaterialNumber).matches()) {
return new ResponseEntity<>(HttpStatusCode.valueOf(400));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Base64;
import java.util.regex.Pattern;

@RestController
Expand Down Expand Up @@ -70,12 +71,12 @@ public class MaterialPartnerRelationsController {
@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 Material Number that is used in your own company to identify the Material, "+
"encoded in base64") @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 = "The Material Number that this Partner is using in his own company to identify the Material, "
+ "encoded in base64") @RequestParam String partnerMaterialNumber,
@Parameter(description = "The CatenaX Number that this Partner uses",
example = "860fb504-b884-4009-9313-c6fb6cdc776b") @RequestParam(required = false) String partnerCXNumber,
@Parameter(description = "The informal name that this Partner uses",
Expand All @@ -85,6 +86,8 @@ public ResponseEntity<?> createMaterialPartnerRelation(
@Parameter(description = "This boolean flag indicates whether this Partner is a potential customer of this Material.",
example = "true") @RequestParam boolean partnerBuys) {

ownMaterialNumber = new String(Base64.getDecoder().decode(ownMaterialNumber));
partnerMaterialNumber = new String(Base64.getDecoder().decode(partnerMaterialNumber));
if (!materialPattern.matcher(ownMaterialNumber).matches() || !materialPattern.matcher(partnerMaterialNumber).matches()
|| !bpnlPattern.matcher(partnerBpnl).matches()) {
log.warn("Rejected message parameters. ");
Expand Down Expand Up @@ -129,12 +132,12 @@ public ResponseEntity<?> createMaterialPartnerRelation(
@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 Material Number that is used in your own company to identify the Material, " +
"encoded in base64") @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 = "The Material Number that this Partner is using in his own company to identify the Material, "
+ "encoded in base64") @RequestParam(required = false) String partnerMaterialNumber,
@Parameter(description = "The CatenaX Number that this Partner uses",
example = "860fb504-b884-4009-9313-c6fb6cdc776b") @RequestParam(required = false) String partnerCXNumber,
@Parameter(description = "The informal name that this Partner uses",
Expand All @@ -143,6 +146,7 @@ public ResponseEntity<?> updateMaterialPartnerRelation(
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) {
ownMaterialNumber = new String(Base64.getDecoder().decode(ownMaterialNumber));
MaterialPartnerRelation existingRelation = null;

if (!bpnlPattern.matcher(partnerBpnl).matches() || !materialPattern.matcher(ownMaterialNumber).matches() ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package org.eclipse.tractusx.puris.backend.production.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
Expand All @@ -47,6 +48,7 @@
import org.springframework.web.server.ResponseStatusException;

import javax.management.openmbean.KeyAlreadyExistsException;
import java.util.Base64;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
Expand Down Expand Up @@ -89,7 +91,10 @@ public class ProductionController {
@GetMapping()
@ResponseBody
@Operation(summary = "Get all planned productions for the given Material", description = "Get all planned productions for the given material number. Optionally the production site can be filtered by its bpns.")
public List<ProductionDto> getAllProductions(String ownMaterialNumber, Optional<String> site) {
public List<ProductionDto> getAllProductions(@Parameter(description = "encoded in base64") String ownMaterialNumber, Optional<String> site) {
if (ownMaterialNumber != null) {
ownMaterialNumber = new String(Base64.getDecoder().decode(ownMaterialNumber));
}
return ownProductionService.findAllByFilters(Optional.of(ownMaterialNumber), Optional.empty(), site, Optional.empty())
.stream().map(this::convertToDto).collect(Collectors.toList());
}
Expand Down Expand Up @@ -204,8 +209,11 @@ public void deleteProduction(@PathVariable UUID id) {
summary = "Get all productions of partners for a material",
description = "Get all productions of partners for a material number. Optionally the partners can be filtered by their bpnl and the production site can be filtered by its bpns."
)
public List<ProductionDto> getAllProductionsForPartner(String ownMaterialNumber, Optional<String> bpnl,
public List<ProductionDto> getAllProductionsForPartner(@Parameter(description = "encoded in base64") String ownMaterialNumber, Optional<String> bpnl,
Optional<String> site) {
if (ownMaterialNumber != null) {
ownMaterialNumber = new String(Base64.getDecoder().decode(ownMaterialNumber));
}
return reportedProductionService.findAllByFilters(Optional.of(ownMaterialNumber), bpnl, site, Optional.empty())
.stream().map(this::convertToDto).collect(Collectors.toList());
}
Expand All @@ -216,7 +224,8 @@ public List<ProductionDto> getAllProductionsForPartner(String ownMaterialNumber,
summary = "Refreshes all reported productions",
description = "Refreshes all reported productions from the production request API."
)
public ResponseEntity<List<PartnerDto>> refreshReportedProductions(@RequestParam String ownMaterialNumber) {
public ResponseEntity<List<PartnerDto>> refreshReportedProductions(
@RequestParam @Parameter(description = "encoded in base64") String ownMaterialNumber) {
if (!materialPattern.matcher(ownMaterialNumber).matches()) {
return new ResponseEntity<>(HttpStatusCode.valueOf(400));
}
Expand Down
Loading
Loading