-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implemented days of supply edc integration
- Loading branch information
1 parent
fe53a12
commit 012e16d
Showing
23 changed files
with
887 additions
and
47 deletions.
There are no files selected for viewing
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
28 changes: 28 additions & 0 deletions
28
...g/eclipse/tractusx/puris/backend/common/edc/domain/model/DaysOfSupplyContractMapping.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,28 @@ | ||
/* | ||
* 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. | ||
* | ||
* 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.common.edc.domain.model; | ||
|
||
import jakarta.persistence.Entity; | ||
import lombok.ToString; | ||
|
||
@Entity | ||
@ToString(callSuper = true) | ||
public class DaysOfSupplyContractMapping extends ContractMapping { | ||
} |
32 changes: 32 additions & 0 deletions
32
...usx/puris/backend/common/edc/domain/repository/DaysOfSupplyContractMappingRepository.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,32 @@ | ||
/* | ||
* 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. | ||
* | ||
* 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.common.edc.domain.repository; | ||
|
||
import org.eclipse.tractusx.puris.backend.common.edc.domain.model.ContractMapping; | ||
import org.eclipse.tractusx.puris.backend.common.edc.domain.model.DaysOfSupplyContractMapping; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface DaysOfSupplyContractMappingRepository extends GeneralContractMappingRepository<DaysOfSupplyContractMapping> { | ||
@Override | ||
default Class<? extends ContractMapping> getType() { | ||
return DaysOfSupplyContractMapping.class; | ||
} | ||
} |
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
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
82 changes: 82 additions & 0 deletions
82
...rg/eclipse/tractusx/puris/backend/supply/controller/DaysOfSupplyRequestApiController.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,82 @@ | ||
/* | ||
* Copyright (c) 2023, 2024 Volkswagen AG | ||
* Copyright (c) 2023, 2024 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.supply.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.eclipse.tractusx.puris.backend.common.util.PatternStore; | ||
import org.eclipse.tractusx.puris.backend.stock.logic.dto.itemstocksamm.DirectionCharacteristic; | ||
import org.eclipse.tractusx.puris.backend.supply.logic.dto.daysofsupplysamm.DaysOfSupply; | ||
import org.eclipse.tractusx.puris.backend.supply.logic.service.DaysOfSupplyRequestApiService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
@RestController | ||
@RequestMapping("days-of-supply") | ||
@Slf4j | ||
/** | ||
* This class offers the endpoint for requesting the DaysOfSupply Submodel 1.0.0 | ||
*/ | ||
public class DaysOfSupplyRequestApiController { | ||
|
||
@Autowired | ||
private DaysOfSupplyRequestApiService daysOfSupplyRequestApiService; | ||
|
||
private final Pattern bpnlPattern = PatternStore.BPNL_PATTERN; | ||
|
||
private final Pattern urnPattern = PatternStore.URN_OR_UUID_PATTERN; | ||
|
||
@Operation(summary = "This endpoint receives the DaysOfSupply Submodel 1.0.0 requests") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "Ok"), | ||
@ApiResponse(responseCode = "400", description = "Bad Request"), | ||
@ApiResponse(responseCode = "500", description = "Internal Server Error"), | ||
@ApiResponse(responseCode = "501", description = "Unsupported representation") | ||
}) | ||
@GetMapping("request/{materialnumbercx}/{direction}/{representation}") | ||
public ResponseEntity<DaysOfSupply> getDaysOfSupplyMapping( | ||
@RequestHeader("edc-bpn") String bpnl, | ||
@PathVariable String materialnumbercx, | ||
@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"); | ||
return ResponseEntity.badRequest().build(); | ||
} | ||
if (!"$value".equals(representation)) { | ||
log.warn("Rejecting request at DaysOfSupply Submodel request 1.0.0 endpoint, missing '$value' in request"); | ||
if (!PatternStore.NON_EMPTY_NON_VERTICAL_WHITESPACE_PATTERN.matcher(representation).matches()) { | ||
representation = "<REPLACED_INVALID_REPRESENTATION>"; | ||
} | ||
return ResponseEntity.status(501).build(); | ||
} | ||
var samm = daysOfSupplyRequestApiService.handleDaysOfSupplySubmodelRequest(bpnl, materialnumbercx, direction); | ||
if (samm == null) { | ||
return ResponseEntity.status(500).build(); | ||
} | ||
return ResponseEntity.ok(samm); | ||
} | ||
} |
Oops, something went wrong.