Skip to content

Commit

Permalink
Merge pull request eclipse-tractusx#283 from FraunhoferISST/feat/dtr_…
Browse files Browse the repository at this point in the history
…materialregistration

Feat/dtr materialregistration
  • Loading branch information
mhellmeier authored Mar 13, 2024
2 parents fa2ef45 + f30c142 commit 863d066
Show file tree
Hide file tree
Showing 22 changed files with 1,093 additions and 287 deletions.
6 changes: 3 additions & 3 deletions DEPENDENCIES_BACKEND
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ maven/mavencentral/io.swagger.core.v3/swagger-core-jakarta/2.2.19, Apache-2.0, a
maven/mavencentral/io.swagger.core.v3/swagger-models-jakarta/2.2.19, Apache-2.0, approved, #5919
maven/mavencentral/jakarta.activation/jakarta.activation-api/2.1.2, EPL-2.0 OR BSD-3-Clause OR GPL-2.0-only with Classpath-exception-2.0, approved, ee4j.jaf
maven/mavencentral/jakarta.annotation/jakarta.annotation-api/2.1.1, EPL-2.0 OR GPL-2.0-only with Classpath-exception-2.0, approved, ee4j.ca
maven/mavencentral/jakarta.inject/jakarta.inject-api/2.0.1, Apache-2.0, approved, clearlydefined
maven/mavencentral/jakarta.persistence/jakarta.persistence-api/3.1.0, EPL-2.0 OR BSD-3-Clause AND (EPL-2.0 OR BSD-3-Clause AND BSD-3-Clause), approved, #7696
maven/mavencentral/jakarta.transaction/jakarta.transaction-api/2.0.1, EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0, approved, #7697
maven/mavencentral/jakarta.inject/jakarta.inject-api/2.0.1, Apache-2.0, approved, ee4j.cdi
maven/mavencentral/jakarta.persistence/jakarta.persistence-api/3.1.0, EPL-2.0 OR BSD-3-Clause, approved, ee4j.jpa
maven/mavencentral/jakarta.transaction/jakarta.transaction-api/2.0.1, EPL-2.0 OR GPL-2.0-only with Classpath-exception-2.0, approved, ee4j.jta
maven/mavencentral/jakarta.validation/jakarta.validation-api/3.0.2, Apache-2.0, approved, ee4j.validation
maven/mavencentral/jakarta.xml.bind/jakarta.xml.bind-api/4.0.1, BSD-3-Clause, approved, ee4j.jaxb
maven/mavencentral/net.bytebuddy/byte-buddy-agent/1.14.11, Apache-2.0, approved, #7164
Expand Down
6 changes: 3 additions & 3 deletions backend/DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ maven/mavencentral/io.swagger.core.v3/swagger-core-jakarta/2.2.19, Apache-2.0, a
maven/mavencentral/io.swagger.core.v3/swagger-models-jakarta/2.2.19, Apache-2.0, approved, #5919
maven/mavencentral/jakarta.activation/jakarta.activation-api/2.1.2, EPL-2.0 OR BSD-3-Clause OR GPL-2.0-only with Classpath-exception-2.0, approved, ee4j.jaf
maven/mavencentral/jakarta.annotation/jakarta.annotation-api/2.1.1, EPL-2.0 OR GPL-2.0-only with Classpath-exception-2.0, approved, ee4j.ca
maven/mavencentral/jakarta.inject/jakarta.inject-api/2.0.1, Apache-2.0, approved, clearlydefined
maven/mavencentral/jakarta.persistence/jakarta.persistence-api/3.1.0, EPL-2.0 OR BSD-3-Clause AND (EPL-2.0 OR BSD-3-Clause AND BSD-3-Clause), approved, #7696
maven/mavencentral/jakarta.transaction/jakarta.transaction-api/2.0.1, EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0, approved, #7697
maven/mavencentral/jakarta.inject/jakarta.inject-api/2.0.1, Apache-2.0, approved, ee4j.cdi
maven/mavencentral/jakarta.persistence/jakarta.persistence-api/3.1.0, EPL-2.0 OR BSD-3-Clause, approved, ee4j.jpa
maven/mavencentral/jakarta.transaction/jakarta.transaction-api/2.0.1, EPL-2.0 OR GPL-2.0-only with Classpath-exception-2.0, approved, ee4j.jta
maven/mavencentral/jakarta.validation/jakarta.validation-api/3.0.2, Apache-2.0, approved, ee4j.validation
maven/mavencentral/jakarta.xml.bind/jakarta.xml.bind-api/4.0.1, BSD-3-Clause, approved, ee4j.jaxb
maven/mavencentral/net.bytebuddy/byte-buddy-agent/1.14.11, Apache-2.0, approved, #7164
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ private void setupCustomerRole() throws JsonProcessingException {

MaterialPartnerRelation semiconductorPartnerRelation = new MaterialPartnerRelation(semiconductorMaterial,
supplierPartner, semiconductorMatNbrSupplier, true, false);
semiconductorPartnerRelation.setPartnerCXNumber(semiconductorMatNbrCatenaX);
mprService.create(semiconductorPartnerRelation);
semiconductorPartnerRelation = mprService.find(semiconductorMaterial, supplierPartner);
log.info("Found Relation: " + semiconductorPartnerRelation);
Expand All @@ -174,6 +175,7 @@ private void setupCustomerRole() throws JsonProcessingException {

MaterialPartnerRelation ccuPartnerRelation = new MaterialPartnerRelation(centralControlUnitEntity,
nonScenarioCustomer, "MNR-4177-C", false, true);
ccuPartnerRelation.setPartnerCXNumber("89f9c477-7e6e-4899-9b4b-d2c1081455ec");
ccuPartnerRelation = mprService.create(ccuPartnerRelation);
log.info("Found Relation: " + ccuPartnerRelation);

Expand Down Expand Up @@ -246,6 +248,7 @@ private void setupSupplierRole() {

MaterialPartnerRelation semiconductorPartnerRelation = new MaterialPartnerRelation(semiconductorMaterial,
customerPartner, semiconductorMatNbrCustomer, false, true);
semiconductorPartnerRelation.setPartnerCXNumber(semiconductorMatNbrCatenaX);
semiconductorPartnerRelation = mprService.create(semiconductorPartnerRelation);

log.info("Created Relation " + semiconductorPartnerRelation);
Expand Down
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<>();

}
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> {
}
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());
}
}
Loading

0 comments on commit 863d066

Please sign in to comment.