-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…structure Feature/#249 policy controller enchancements
- Loading branch information
Showing
9 changed files
with
483 additions
and
296 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
31 changes: 31 additions & 0 deletions
31
irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/models/Context.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,31 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2022,2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* Copyright (c) 2021,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.irs.policystore.models; | ||
|
||
/** | ||
* Context representation for get all policies response | ||
*/ | ||
public record Context(String odrl) { | ||
private static final String ODRL_VALUE = "http://www.w3.org/ns/odrl/2/"; | ||
|
||
public static Context getDefault() { | ||
return new Context(ODRL_VALUE); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/models/Payload.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,36 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2022,2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* Copyright (c) 2021,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.irs.policystore.models; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Builder; | ||
import org.eclipse.tractusx.irs.edc.client.policy.Policy; | ||
|
||
/** | ||
* Payload representation for get all policies response | ||
*/ | ||
@Builder | ||
public record Payload( | ||
@JsonProperty("@context") Context context, | ||
@JsonProperty("@id") String policyId, | ||
Policy policy | ||
) { | ||
|
||
} |
86 changes: 86 additions & 0 deletions
86
...olicy-store/src/main/java/org/eclipse/tractusx/irs/policystore/models/PolicyResponse.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,86 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2022,2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* Copyright (c) 2021,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.irs.policystore.models; | ||
|
||
import java.time.OffsetDateTime; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Builder; | ||
import org.eclipse.tractusx.irs.edc.client.policy.Policy; | ||
|
||
/** | ||
* Policy representation for get all policies response | ||
*/ | ||
@Builder | ||
@Schema(example = PolicyResponse.EXAMPLE_PAYLOAD) | ||
public record PolicyResponse(OffsetDateTime validUntil, Payload payload) { | ||
|
||
@SuppressWarnings({"FileTabCharacter", "java:S2479"}) | ||
// required to show correctly example payload in open-api | ||
public static final String EXAMPLE_PAYLOAD = """ | ||
[ | ||
{ | ||
"validUntil": "2025-12-12T23:59:59.999Z", | ||
"payload": { | ||
"@context": { | ||
"odrl": "http://www.w3.org/ns/odrl/2/" | ||
}, | ||
"@id": "policy-id", | ||
"policy": { | ||
"odrl:permission": [ | ||
{ | ||
"odrl:action": "USE", | ||
"odrl:constraint": { | ||
"odrl:and": [ | ||
{ | ||
"odrl:leftOperand": "Membership", | ||
"odrl:operator": { | ||
"@id": "odrl:eq" | ||
}, | ||
"odrl:rightOperand": "active" | ||
}, | ||
{ | ||
"odrl:leftOperand": "PURPOSE", | ||
"odrl:operator": { | ||
"@id": "odrl:eq" | ||
}, | ||
"odrl:rightOperand": "ID 3.1 Trace" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
] | ||
"""; | ||
|
||
public static PolicyResponse fromPolicy(final Policy policy) { | ||
return PolicyResponse.builder() | ||
.validUntil(policy.getValidUntil()) | ||
.payload(Payload.builder() | ||
.policyId(policy.getPolicyId()) | ||
.context(Context.getDefault()) | ||
.policy(policy) | ||
.build()) | ||
.build(); | ||
} | ||
} |
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
Oops, something went wrong.