forked from eclipse-tractusx/puris
-
Notifications
You must be signed in to change notification settings - Fork 1
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 eclipse-tractusx#283 from FraunhoferISST/feat/dtr_…
…materialregistration Feat/dtr materialregistration
- Loading branch information
Showing
22 changed files
with
1,093 additions
and
287 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
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
50 changes: 50 additions & 0 deletions
50
.../java/org/eclipse/tractusx/puris/backend/common/ddtr/domain/model/DigitalTwinMapping.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,50 @@ | ||
/* | ||
* 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.ddtr.domain.model; | ||
|
||
import jakarta.persistence.*; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.*; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Entity | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
@Setter | ||
@ToString | ||
public class DigitalTwinMapping { | ||
|
||
@Id | ||
@NotNull | ||
private String ownMaterialNumber; | ||
|
||
private String productTwinId; | ||
|
||
@ElementCollection | ||
@CollectionTable(name = "suppliersmap", joinColumns = @JoinColumn(name = "own_mat_nbr", referencedColumnName = "ownMaterialNumber")) | ||
@MapKeyColumn(name = "key") | ||
@Column(name = "value") | ||
private Map<String, String> materialSupplierTwinIds = new HashMap<>(); | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
...se/tractusx/puris/backend/common/ddtr/domain/repository/DigitalTwinMappingRepository.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,29 @@ | ||
/* | ||
* 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.ddtr.domain.repository; | ||
|
||
import org.eclipse.tractusx.puris.backend.common.ddtr.domain.model.DigitalTwinMapping; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface DigitalTwinMappingRepository extends JpaRepository<DigitalTwinMapping, String> { | ||
} |
86 changes: 86 additions & 0 deletions
86
.../java/org/eclipse/tractusx/puris/backend/common/ddtr/logic/DigitalTwinMappingService.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) 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.ddtr.logic; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.eclipse.tractusx.puris.backend.common.ddtr.domain.model.DigitalTwinMapping; | ||
import org.eclipse.tractusx.puris.backend.common.ddtr.domain.repository.DigitalTwinMappingRepository; | ||
import org.eclipse.tractusx.puris.backend.masterdata.domain.model.Material; | ||
import org.eclipse.tractusx.puris.backend.masterdata.domain.model.MaterialPartnerRelation; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.UUID; | ||
|
||
@Service | ||
@Slf4j | ||
public class DigitalTwinMappingService { | ||
|
||
@Autowired | ||
private DigitalTwinMappingRepository repository; | ||
|
||
public DigitalTwinMapping create(Material material) { | ||
if(repository.findById(material.getOwnMaterialNumber()).isPresent()) { | ||
log.error("DTR Mapping for " + material.getOwnMaterialNumber() + " already exists"); | ||
return null; | ||
} | ||
DigitalTwinMapping dtm = new DigitalTwinMapping(); | ||
dtm.setOwnMaterialNumber(material.getOwnMaterialNumber()); | ||
if (material.isProductFlag()) { | ||
dtm.setProductTwinId(UUID.randomUUID().toString()); | ||
} | ||
return repository.save(dtm); | ||
} | ||
|
||
public DigitalTwinMapping update(Material material) { | ||
var searchResult = repository.findById(material.getOwnMaterialNumber()); | ||
if (searchResult.isEmpty()) { | ||
log.error("DTR Mapping did not exist. Update failed for " + material.getOwnMaterialNumber()); | ||
return null; | ||
} | ||
var dtm = searchResult.get(); | ||
if (material.isProductFlag()) { | ||
dtm.setProductTwinId(UUID.randomUUID().toString()); | ||
} | ||
return repository.save(dtm); | ||
} | ||
|
||
public DigitalTwinMapping update(MaterialPartnerRelation mpr) { | ||
var searchResult = repository.findById(mpr.getMaterial().getOwnMaterialNumber()); | ||
if (searchResult.isEmpty()) { | ||
log.error("DTR Mapping did not exist. Update failed for " + mpr); | ||
return null; | ||
} | ||
var dtm = searchResult.get(); | ||
if (mpr.getMaterial().isMaterialFlag() && mpr.isPartnerSuppliesMaterial()) { | ||
dtm.getMaterialSupplierTwinIds().put(mpr.getPartner().getBpnl(), mpr.getPartnerCXNumber()); | ||
} | ||
return repository.save(dtm); | ||
} | ||
|
||
public DigitalTwinMapping get(String ownMaterialNumber) { | ||
return repository.findById(ownMaterialNumber).orElse(null); | ||
} | ||
|
||
public DigitalTwinMapping get(Material material) { | ||
return get(material.getOwnMaterialNumber()); | ||
} | ||
} |
Oops, something went wrong.