Skip to content

Commit

Permalink
Merge pull request #108 from FraunhoferISST/feat/itemstock
Browse files Browse the repository at this point in the history
Feat/itemstock
  • Loading branch information
tom-rm-meyer-ISST authored Dec 20, 2023
2 parents 2aca97c + 7299ab9 commit f02bd91
Show file tree
Hide file tree
Showing 25 changed files with 1,523 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@
import org.eclipse.tractusx.puris.backend.stock.domain.model.*;
import org.eclipse.tractusx.puris.backend.stock.domain.model.measurement.MeasurementUnit;
import org.eclipse.tractusx.puris.backend.stock.logic.adapter.ProductStockSammMapper;
import org.eclipse.tractusx.puris.backend.stock.logic.dto.itemstocksamm.ItemUnitEnumeration;
import org.eclipse.tractusx.puris.backend.stock.logic.dto.samm.LocationIdTypeEnum;
import org.eclipse.tractusx.puris.backend.stock.logic.dto.samm.ProductStockSammDto;
import org.eclipse.tractusx.puris.backend.stock.logic.service.MaterialStockService;
import org.eclipse.tractusx.puris.backend.stock.logic.service.PartnerProductStockService;
import org.eclipse.tractusx.puris.backend.stock.logic.service.ProductStockRequestService;
import org.eclipse.tractusx.puris.backend.stock.logic.service.ProductStockService;
import org.eclipse.tractusx.puris.backend.stock.logic.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -70,6 +68,11 @@ public class DataInjectionCommandLineRunner implements CommandLineRunner {
@Autowired
private ProductStockService productStockService;

@Autowired
private MaterialItemStockService materialItemStockService;
@Autowired
private ReportedMaterialItemStockService reportedMaterialItemStockService;

@Autowired
private PartnerProductStockService partnerProductStockService;

Expand Down Expand Up @@ -113,7 +116,7 @@ public void run(String... args) throws Exception {
*/
private void createOwnPartnerEntity() {
Partner mySelf;
if(variablesService.getOwnDefaultBpns()!= null && variablesService.getOwnDefaultBpns().length()!=0) {
if (variablesService.getOwnDefaultBpns() != null && variablesService.getOwnDefaultBpns().length() != 0) {
mySelf = new Partner(variablesService.getOwnName(),
variablesService.getEdcProtocolUrl(),
variablesService.getOwnBpnl(),
Expand All @@ -135,7 +138,7 @@ private void createOwnPartnerEntity() {
}
mySelf = partnerService.create(mySelf);
log.info("Successfully created own Partner Entity: " + (partnerService.findByBpnl(mySelf.getBpnl()) != null));
if(mySelf != null) {
if (mySelf != null) {
log.info(mySelf.toString());
}
}
Expand Down Expand Up @@ -219,6 +222,34 @@ private void setupCustomerRole() throws JsonProcessingException {
log.info("SAMM-DTO:\n" + objectMapper.writeValueAsString(productStockSammDto));

log.info("Own Street and Number: " + variablesService.getOwnDefaultStreetAndNumber());
Partner mySelf = partnerService.getOwnPartnerEntity();
var builder = MaterialItemStock.builder();
var materialItemStock = builder.partner(supplierPartner)
.material(semiconductorMaterial)
.lastUpdatedOnDateTime(new Date())
.locationBpna(mySelf.getSites().first().getAddresses().first().getBpna())
.locationBpns(mySelf.getSites().first().getBpns())
.measurementUnit(ItemUnitEnumeration.UNIT_PIECE)
.quantity(20)
.build();
var createdMaterialItemStock = materialItemStockService.create(materialItemStock);
log.info("Created MaterialItemStock: \n" + createdMaterialItemStock.toString());

var builder2 = ReportedMaterialItemStock.builder();
var reportedMaterialItemStock =
builder2
.material(semiconductorMaterial)
.partner(supplierPartner)
.lastUpdatedOnDateTime(new Date())
.locationBpns(supplierPartner.getSites().first().getBpns())
.locationBpna(supplierPartner.getSites().first().getAddresses().first().getBpna())
.measurementUnit(ItemUnitEnumeration.UNIT_PIECE)
.quantity(50)
.build();

var createdReportedMaterialItemStock = reportedMaterialItemStockService.create(reportedMaterialItemStock);
log.info("Created ReportedMaterialItemStock: \n" + createdReportedMaterialItemStock);

}

/**
Expand Down Expand Up @@ -266,7 +297,6 @@ private void setupSupplierRole() {
"bpnl: %s", foundProductStocks));
}


/**
* creates a new customer Partner entity, stores it to
* the database and returns this entity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@
@ToString
public class Address implements Comparable<Address> {

public static final String BPNA_REGEX = "^BPNA[0-9a-zA-Z]{12}$";
/**
* The BPNA of this Address.
*/
@Pattern(regexp = "^BPNA[0-9a-zA-Z]{12}$")
@Pattern(regexp = BPNA_REGEX)
private String bpna;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@
@Setter
@ToString
public class Site implements Comparable<Site> {

public static final String BPNS_REGEX = "^BPNS[0-9a-zA-Z]{12}$";
@Id
@NotNull
/**
* The BPNS of this Site.
*/
@Pattern(regexp = "^BPNS[0-9a-zA-Z]{12}$")
@Pattern(regexp = BPNS_REGEX)
private String bpns;
/**
* A human-readable, distinctive name of this site.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Copyright (c) 2023 Volkswagen AG
* Copyright (c) 2023 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.stock.domain.model;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import lombok.*;
import lombok.experimental.SuperBuilder;
import org.eclipse.tractusx.puris.backend.masterdata.domain.model.Address;
import org.eclipse.tractusx.puris.backend.masterdata.domain.model.Material;
import org.eclipse.tractusx.puris.backend.masterdata.domain.model.Partner;
import org.eclipse.tractusx.puris.backend.masterdata.domain.model.Site;
import org.eclipse.tractusx.puris.backend.stock.logic.dto.itemstocksamm.ItemUnitEnumeration;

import java.util.Date;
import java.util.UUID;

@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@SuperBuilder
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Entity
@ToString
public abstract class ItemStock {

static final String ORDER_ID_REGEX = "^[a-zA-Z0-9\\-\\.]{1,255}$";

@Id
@GeneratedValue
protected UUID uuid;

@ManyToOne()
@JoinColumn(name = "partner_uuid")
@ToString.Exclude
@NotNull
protected Partner partner;
@ManyToOne()
@JoinColumn(name = "material_ownMaterialNumber")
@ToString.Exclude
@NotNull
protected Material material;

protected double quantity;
@NotNull
protected ItemUnitEnumeration measurementUnit;
@NotNull
@Pattern(regexp = Address.BPNA_REGEX)
protected String locationBpna;
@NotNull
@Pattern(regexp = Site.BPNS_REGEX)
protected String locationBpns;
@NotNull
protected Date lastUpdatedOnDateTime;

protected boolean isBlocked;
@Pattern(regexp = ORDER_ID_REGEX)
protected String supplierOrderId;
@Pattern(regexp = ORDER_ID_REGEX)
protected String customerOrderId;
@Pattern(regexp = ORDER_ID_REGEX)
protected String customerOrderPositionId;

@ToString.Include
private String material_ownMaterialNumber(){
return material.getOwnMaterialNumber();
}

@ToString.Include
private String partner_partnerBpnl(){
return partner.getBpnl();
}

}



Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2023 Volkswagen AG
* Copyright (c) 2023 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.stock.domain.model;

import jakarta.persistence.Entity;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;

@Entity
@SuperBuilder
@NoArgsConstructor
@ToString(callSuper = true)
public class MaterialItemStock extends ItemStock {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2023 Volkswagen AG
* Copyright (c) 2023 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.stock.domain.model;

import jakarta.persistence.Entity;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;

@Entity
@SuperBuilder
@NoArgsConstructor
@ToString(callSuper = true)
public class ProductItemStock extends ItemStock {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2023 Volkswagen AG
* Copyright (c) 2023 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.stock.domain.model;

import jakarta.persistence.Entity;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;

@Entity
@SuperBuilder
@NoArgsConstructor
@ToString(callSuper = true)
public class ReportedMaterialItemStock extends ItemStock {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2023 Volkswagen AG
* Copyright (c) 2023 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.stock.domain.model;

import jakarta.persistence.Entity;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;

@Entity
@SuperBuilder
@NoArgsConstructor
@ToString(callSuper = true)
public class ReportedProductItemStock extends ItemStock {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2023 Volkswagen AG
* Copyright (c) 2023 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.stock.domain.repository;

import org.eclipse.tractusx.puris.backend.stock.domain.model.MaterialItemStock;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.UUID;
@Repository
public interface MaterialItemStockRepository extends JpaRepository<MaterialItemStock, UUID> {
}
Loading

0 comments on commit f02bd91

Please sign in to comment.