-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #323 from bci-oss/feature/286-implement-crud-acces…
…s-management-api__05-implement-mappers feat: Implementation of CRUD API for Access management APIs - Implement mappers
- Loading branch information
Showing
5 changed files
with
425 additions
and
7 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
93 changes: 93 additions & 0 deletions
93
...va/org/eclipse/tractusx/semantics/accesscontrol/sql/model/converter/AccessRuleMapper.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,93 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Robert Bosch Manufacturing Solutions GmbH and others | ||
* | ||
* 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.semantics.accesscontrol.sql.model.converter; | ||
|
||
import org.eclipse.tractusx.semantics.accesscontrol.sql.model.AccessRule; | ||
import org.eclipse.tractusx.semantics.accesscontrol.sql.model.policy.PolicyOperator; | ||
import org.eclipse.tractusx.semantics.accesscontrol.sql.rest.model.CreateAccessRule; | ||
import org.eclipse.tractusx.semantics.accesscontrol.sql.rest.model.OperatorType; | ||
import org.eclipse.tractusx.semantics.accesscontrol.sql.rest.model.ReadUpdateAccessRule; | ||
import org.mapstruct.InjectionStrategy; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
import org.mapstruct.Mappings; | ||
import org.mapstruct.NullValuePropertyMappingStrategy; | ||
import org.mapstruct.ValueMapping; | ||
import org.mapstruct.ValueMappings; | ||
|
||
@Mapper( uses = { CustomAccessRuleMapper.class }, | ||
componentModel = "spring", | ||
injectionStrategy = InjectionStrategy.CONSTRUCTOR, | ||
nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE ) | ||
public interface AccessRuleMapper { | ||
@Mappings( { | ||
@Mapping( target = "id", ignore = true ), | ||
@Mapping( target = "tid", ignore = true ), | ||
@Mapping( target = "targetTenant", ignore = true ), | ||
@Mapping( target = "policyType", source = "policyType" ), | ||
@Mapping( target = "policy", source = "policy" ), | ||
@Mapping( target = "description", source = "description" ), | ||
@Mapping( target = "validFrom", | ||
expression = "java( java.util.Optional.ofNullable( source.getValidFrom() ).map( java.time.OffsetDateTime::toInstant ).orElse( null ) )" ), | ||
@Mapping( target = "validTo", | ||
expression = "java( java.util.Optional.ofNullable( source.getValidTo() ).map( java.time.OffsetDateTime::toInstant ).orElse( null ) )" ) | ||
} ) | ||
AccessRule map( CreateAccessRule source ); | ||
|
||
@Mappings( { | ||
@Mapping( target = "id", source = "id" ), | ||
@Mapping( target = "tid", source = "tid" ), | ||
@Mapping( target = "targetTenant", ignore = true ), | ||
@Mapping( target = "policyType", source = "policyType" ), | ||
@Mapping( target = "policy", source = "policy" ), | ||
@Mapping( target = "description", source = "description" ), | ||
@Mapping( target = "validFrom", | ||
expression = "java( java.util.Optional.ofNullable( source.getValidFrom() ).map( java.time.OffsetDateTime::toInstant ).orElse( null ) )" ), | ||
@Mapping( target = "validTo", | ||
expression = "java( java.util.Optional.ofNullable( source.getValidTo() ).map( java.time.OffsetDateTime::toInstant ).orElse( null ) )" ) | ||
} ) | ||
AccessRule map( ReadUpdateAccessRule source ); | ||
|
||
@Mappings( { | ||
@Mapping( target = "id", source = "id" ), | ||
@Mapping( target = "tid", source = "tid" ), | ||
@Mapping( target = "policyType", source = "policyType" ), | ||
@Mapping( target = "policy", source = "policy" ), | ||
@Mapping( target = "description", source = "description" ), | ||
@Mapping( target = "validFrom", | ||
expression = "java( java.util.Optional.ofNullable( source.getValidFrom() ).map( i -> i.atOffset( java.time.ZoneOffset.UTC ) ).orElse( null ) )" ), | ||
@Mapping( target = "validTo", | ||
expression = "java( java.util.Optional.ofNullable( source.getValidTo() ).map( i -> i.atOffset( java.time.ZoneOffset.UTC ) ).orElse( null ) )" ) | ||
} ) | ||
ReadUpdateAccessRule map( AccessRule source ); | ||
|
||
@ValueMappings( { | ||
@ValueMapping( target = "EQUALS", source = "EQ" ), | ||
@ValueMapping( target = "INCLUDES", source = "INCLUDES" ) | ||
} ) | ||
PolicyOperator map( OperatorType source ); | ||
|
||
@ValueMappings( { | ||
@ValueMapping( target = "EQ", source = "EQUALS" ), | ||
@ValueMapping( target = "INCLUDES", source = "INCLUDES" ) | ||
} ) | ||
OperatorType map( PolicyOperator source ); | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
.../eclipse/tractusx/semantics/accesscontrol/sql/model/converter/CustomAccessRuleMapper.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,34 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Robert Bosch Manufacturing Solutions GmbH and others | ||
* | ||
* 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.semantics.accesscontrol.sql.model.converter; | ||
|
||
import org.eclipse.tractusx.semantics.accesscontrol.sql.model.AccessRule; | ||
import org.mapstruct.AfterMapping; | ||
import org.mapstruct.MappingTarget; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class CustomAccessRuleMapper { | ||
|
||
@AfterMapping | ||
public void calledWithSourceAndTarget(Object anySource, @MappingTarget AccessRule target) { | ||
target.setTargetTenant( target.getPolicy().getBpn() ); | ||
} | ||
} |
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.