Skip to content

Commit

Permalink
fix: submodel version and validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ReneSchroederLJ committed Dec 20, 2024
1 parent f905fde commit e394e94
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public enum AssetType {
DEMAND_SUBMODEL("urn:samm:io.catenax.short_term_material_demand:1.0.0#ShortTermMaterialDemand", "$value", "ShortTermMaterialDemand", "1.0"),
DELIVERY_SUBMODEL("urn:samm:io.catenax.delivery_information:2.0.0#DeliveryInformation", "$value", "DeliveryInformation", "2.0"),
NOTIFICATION("urn:samm:io.catenax.demand_and_capacity_notification:2.0.0#DemandAndCapacityNotification", "none", "none", "2.0"),
DAYS_OF_SUPPLY("urn:samm:io.catenax.days_of_supply:1.0.0#DaysOfSupply", "$value", "DaysOfSupply", "1.0"),
DAYS_OF_SUPPLY("urn:samm:io.catenax.days_of_supply:2.0.0#DaysOfSupply", "$value", "DaysOfSupply", "1.0"),
PART_TYPE_INFORMATION_SUBMODEL("urn:samm:io.catenax.part_type_information:1.0.0#PartTypeInformation", "$value", "none", "1.0");

public final String URN_SEMANTIC_ID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public boolean registerAssetsInitially() {
variablesService.getNotificationApiAssetId(),
variablesService.getNotificationEndpoint()
)));
log.info("Registration of Days of Supply 1.0.0 submodel successful {}", (assetRegistration = registerSubmodelAsset(
log.info("Registration of Days of Supply 2.0.0 submodel successful {}", (assetRegistration = registerSubmodelAsset(
variablesService.getDaysOfSupplySubmodelApiAssetId(),
variablesService.getDaysOfSupplySubmodelEndpoint(),
AssetType.DAYS_OF_SUPPLY.URN_SEMANTIC_ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,13 @@ public String getNotificationEndpoint() {
*/
private String notificationAssetId;

@Value("${puris.baseurl}" + "catena/days-of-supply/request")
/**
* The url under which this application's request endpoint can
* be reached by external machines.
*/
private String daysOfSupplySubmodelEndpoint;
public String getDaysOfSupplySubmodelEndpoint() {
return getPurisBaseUrl() + getContextPath() + "days-of-supply/request";
}

@Value("${puris.daysofsupplysubmodel.apiassetid}")
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public class DemandController {
@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(@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())
return ownDemandService.findAllByFilters(Optional.of(ownMaterialNumber), Optional.empty(), site)
.stream().map(this::convertToDto).collect(Collectors.toList());
}

Expand Down Expand Up @@ -175,7 +175,7 @@ public List<DemandDto> getAllDemandsForPartner(@Parameter(description = "encoded
if (ownMaterialNumber != null) {
ownMaterialNumber = new String(Base64.getDecoder().decode(ownMaterialNumber));
}
return reportedDemandService.findAllByFilters(Optional.of(ownMaterialNumber), bpnl, site, Optional.empty())
return reportedDemandService.findAllByFilters(Optional.of(ownMaterialNumber), bpnl, site)
.stream().map(this::convertToDto).collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public ShortTermMaterialDemand handleDemandSubmodelRequest(String bpnl, String m
return null;
}

var currentDemands = ownDemandService.findAllByFilters(Optional.of(material.getOwnMaterialNumber()), Optional.of(partner.getBpnl()), Optional.empty(), Optional.empty());
var currentDemands = ownDemandService.findAllByFilters(Optional.of(material.getOwnMaterialNumber()), Optional.of(partner.getBpnl()), Optional.empty());
return sammMapper.ownDemandToSamm(currentDemands, partner, material);
}

Expand All @@ -109,7 +109,7 @@ public void doReportedDemandRequest(Partner partner, Material material) {
}
}
// delete older data:
var oldDemands = reportedDemandService.findAllByFilters(Optional.of(material.getOwnMaterialNumber()), Optional.of(partner.getBpnl()), Optional.empty(), Optional.empty());
var oldDemands = reportedDemandService.findAllByFilters(Optional.of(material.getOwnMaterialNumber()), Optional.of(partner.getBpnl()), Optional.empty());
for (var oldDemand : oldDemands) {
reportedDemandService.delete(oldDemand.getUuid());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ public final List<TEntity> findAllByOwnMaterialNumber(String ownMaterialNumber)
public final List<TEntity> findAllByFilters(
Optional<String> ownMaterialNumber,
Optional<String> bpnl,
Optional<String> demandLocationBpns,
Optional<Date> day) {
Optional<String> demandLocationBpns) {
var stream = repository.findAll().stream();
if (ownMaterialNumber.isPresent()) {
stream = stream.filter(demand -> demand.getMaterial().getOwnMaterialNumber().equals(ownMaterialNumber.get()));
Expand All @@ -82,17 +81,6 @@ public final List<TEntity> findAllByFilters(
if (demandLocationBpns.isPresent()) {
stream = stream.filter(demand -> demand.getDemandLocationBpns().equals(demandLocationBpns.get()));
}
if (day.isPresent()) {
LocalDate localDayDate = Instant.ofEpochMilli(day.get().getTime())
.atOffset(ZoneOffset.UTC)
.toLocalDate();
stream = stream.filter(demand -> {
LocalDate demandDayDate = Instant.ofEpochMilli(demand.getDay().getTime())
.atOffset(ZoneOffset.UTC)
.toLocalDate();
return demandDayDate.getDayOfMonth() == localDayDate.getDayOfMonth();
});
}
return stream.toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public OwnDemandService(OwnDemandRepository repository, PartnerService partnerSe
public final List<Double> getQuantityForDays(String material, String partnerBpnl, String siteBpns, int numberOfDays) {
List<Double> quantities = new ArrayList<>();
LocalDate localDate = LocalDate.now();
List<OwnDemand> demands = findAllByFilters(Optional.of(material), Optional.of(partnerBpnl), Optional.of(siteBpns), Optional.empty());
List<OwnDemand> demands = findAllByFilters(Optional.of(material), Optional.of(partnerBpnl), Optional.of(siteBpns));
for (int i = 0; i < numberOfDays; i++) {
Date date = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
LocalDate localDayDate = Instant.ofEpochMilli(date.getTime()).atOffset(ZoneOffset.UTC).toLocalDate();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2023, 2024 Volkswagen AG
* Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation
* Copyright (c) 2024 Volkswagen AG
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -38,7 +38,7 @@
@RequestMapping("days-of-supply")
@Slf4j
/**
* This class offers the endpoint for requesting the DaysOfSupply Submodel 1.0.0
* This class offers the endpoint for requesting the DaysOfSupply Submodel 2.0.0
*/
public class DaysOfSupplyRequestApiController {

Expand All @@ -49,7 +49,7 @@ public class DaysOfSupplyRequestApiController {

private final Pattern urnPattern = PatternStore.URN_OR_UUID_PATTERN;

@Operation(summary = "This endpoint receives the DaysOfSupply Submodel 1.0.0 requests")
@Operation(summary = "This endpoint receives the DaysOfSupply Submodel 2.0.0 requests")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Ok"),
@ApiResponse(responseCode = "400", description = "Bad Request"),
Expand All @@ -63,11 +63,11 @@ public ResponseEntity<DaysOfSupply> getDaysOfSupplyMapping(
@PathVariable DirectionCharacteristic direction,
@PathVariable String representation) {
if (!bpnlPattern.matcher(bpnl).matches() || !urnPattern.matcher(materialnumbercx).matches()) {
log.warn("Rejecting request at DaysOfSupply Submodel request 1.0.0 endpoint");
log.warn("Rejecting request at DaysOfSupply Submodel request 2.0.0 endpoint");
return ResponseEntity.badRequest().build();
}
if (!"$value".equals(representation)) {
log.warn("Rejecting request at DaysOfSupply Submodel request 1.0.0 endpoint, missing '$value' in request");
log.warn("Rejecting request at DaysOfSupply Submodel request 2.0.0 endpoint, missing '$value' in request");
if (!PatternStore.NON_EMPTY_NON_VERTICAL_WHITESPACE_PATTERN.matcher(representation).matches()) {
representation = "<REPLACED_INVALID_REPRESENTATION>";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ public boolean validate(ReportedCustomerSupply daysOfSupply) {
daysOfSupply.getMaterial() != null &&
daysOfSupply.getDate() != null &&
daysOfSupply.getStockLocationBPNS() != null &&
daysOfSupply.getStockLocationBPNA() != null &&
daysOfSupply.getPartner() != partnerService.getOwnPartnerEntity() &&
daysOfSupply.getPartner().getSites().stream().anyMatch(site -> site.getBpns().equals(daysOfSupply.getStockLocationBPNS()));
daysOfSupply.getPartner().getSites().stream().anyMatch(site ->
site.getBpns().equals(daysOfSupply.getStockLocationBPNS()) &&
site.getAddresses().stream().anyMatch(address -> address.getBpna().equals(daysOfSupply.getStockLocationBPNA()))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ public boolean validate(ReportedSupplierSupply daysOfSupply) {
daysOfSupply.getMaterial() != null &&
daysOfSupply.getDate() != null &&
daysOfSupply.getStockLocationBPNS() != null &&
daysOfSupply.getStockLocationBPNA() != null &&
daysOfSupply.getPartner() != partnerService.getOwnPartnerEntity() &&
daysOfSupply.getPartner().getSites().stream().anyMatch(site -> site.getBpns().equals(daysOfSupply.getStockLocationBPNS()));
daysOfSupply.getPartner().getSites().stream().anyMatch(site ->
site.getBpns().equals(daysOfSupply.getStockLocationBPNS()) &&
site.getAddresses().stream().anyMatch(address -> address.getBpna().equals(daysOfSupply.getStockLocationBPNA()))
);
}
}
2 changes: 1 addition & 1 deletion charts/puris/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies:
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 2.8.0
version: 2.7.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down

0 comments on commit e394e94

Please sign in to comment.