Skip to content

Commit

Permalink
EDG-9: support inheriting the parentId and EPCs to subsequent parent/…
Browse files Browse the repository at this point in the history
…epcs.
  • Loading branch information
Aravinda Baliga B committed Mar 20, 2024
1 parent 48f3871 commit d0660b9
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@ public List<String> referencedParentIdentifier(final List<EventIdentifierTracker
.findFirst()
.ifPresent(
t -> parentList.addAll(EventModelUtil.parentIdentifiers(t, epc.getInheritParentCount())));
}else if(epc.getParentNodeId() != 0 && epc.getInheritEPCToParent() != null && epc.getInheritEPCToParent() > 0){
parentTracker.stream()
.filter(i -> i.getEventTypeInfo().getNodeId() == epc.getParentNodeId())
.findFirst()
.ifPresent(
t -> parentList.addAll(EventModelUtil.instanceIdentifiers(t, epc.getInheritEPCToParent())));
}
}
return parentList;
Expand Down Expand Up @@ -285,6 +291,13 @@ public List<String> referencedEpcsIdentifierGenerator(
.findFirst()
.ifPresent(
t -> epcList.addAll(EventModelUtil.instanceIdentifiers(t, epc.getEpcCount())));
}else if(epc.getParentNodeId() != 0 && epc.getInheritParentToEPC() > 0){
//If inheriting the identifiers from ParentID to subsequent ChildEPCS/EPCS then inherit based on getInheritParentToEPC
parentTracker.stream()
.filter(i -> i.getEventTypeInfo().getNodeId() == epc.getParentNodeId())
.findFirst()
.ifPresent(
t -> epcList.addAll(EventModelUtil.segregateParentToEPC(t, epc.getInheritParentToEPC())));
}

//Add the identifiers from ParentID Count only if the inheriting event is ObjectEvent or TransformationEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@
package io.openepcis.testdata.generator.model;

import io.openepcis.model.epcis.*;
import io.openepcis.testdata.generator.reactivestreams.*;
import io.openepcis.testdata.generator.reactivestreams.EPCISEventDownstreamHandler;
import io.openepcis.testdata.generator.reactivestreams.EventIdentifierTracker;
import io.openepcis.testdata.generator.template.*;

import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

public class EventModelUtil {

Expand Down Expand Up @@ -123,23 +127,40 @@ public static List<String> parentIdentifiers(
// Public method which will be invoked during the Class Identifier creation if the Class
// Identifiers need to be inherited from the Parent event node
public static List<QuantityList> classIdentifiers(
final EventIdentifierTracker parentTracker, final int quantityCount, final Float quantity) {
final EventIdentifierTracker parentTracker, final int quantityCount, final Float quantity) {
return segregateClassIdentifiers(parentTracker, quantityCount, quantity);
}

//Method to segregate the parentIDs for subsequent EPCs/ChildEPCs inheritance mainly for Aggregation/Transaction/TransformationEvent
public static List<String> segregateParentToEPC(final EventIdentifierTracker parentTracker, final int inheritParentCount) {
List<String> inheritParentList = new ArrayList<>();

if (parentTracker.getEvent() instanceof AggregationEvent aggregationEvent && aggregationEvent.getParentID() != null) {
// For AggregationEvent add the parentIDs
inheritParentList.add(aggregationEvent.getParentID());
} else if (parentTracker.getEvent() instanceof TransactionEvent transactionEvent && transactionEvent.getParentID() != null) {
// For TransactionEvent add the parentIDs
inheritParentList.add(transactionEvent.getParentID());
} else if (parentTracker.getEvent() instanceof AssociationEvent associationEvent && associationEvent.getParentID() != null) {
// For TransactionEvent add the parentIDs
inheritParentList.add(associationEvent.getParentID());
}
return inheritParentList;
}

// Private method which will segregate the Instance identifier from the Parent Event based on the
// type of the event
private static List<String> segregateInstanceIdentifiers(
final EventIdentifierTracker parentTracker, final int epcCount) {
final EventIdentifierTracker parentTracker, final int epcCount) {

// List to store all the instance identifiers from parent
List<String> instanceIdentifiersList = new ArrayList<>();

// Based on the Event Type add the respective Instance Identifiers into the
// instanceIdentifiersList
if (parentTracker.getEvent() instanceof ObjectEvent objectEvent
&& objectEvent.getEpcList() != null
&& !objectEvent.getEpcList().isEmpty()) {
&& objectEvent.getEpcList() != null
&& !objectEvent.getEpcList().isEmpty()) {
// For ObjectEvent add the EPCList
instanceIdentifiersList.addAll(objectEvent.getEpcList());
} else if (parentTracker.getEvent() instanceof AggregationEvent aggregationEvent
Expand Down Expand Up @@ -197,16 +218,13 @@ private static List<String> segregateParentIdentifiers(
if (parentTracker.getEvent() instanceof AggregationEvent aggregationEvent) {
// For AggregationEvent add the Parent-Ids/Child EPCs if value exists
parentIdentifiersList.add( aggregationEvent.getParentID() != null && !aggregationEvent.getParentID().isEmpty() ? aggregationEvent.getParentID() : null); //add parent id
parentIdentifiersList.addAll(aggregationEvent.getChildEPCs() != null && !aggregationEvent.getChildEPCs().isEmpty() ? aggregationEvent.getChildEPCs() : Collections.emptyList()); //add child epcs
} else if (parentTracker.getEvent() instanceof TransactionEvent transactionEvent) {
// For TransactionEvent add the Parent-Ids/EPC list if value exists
parentIdentifiersList.add( transactionEvent.getParentID() != null && !transactionEvent.getParentID().isEmpty() ? transactionEvent.getParentID() : null); //add parent id
parentIdentifiersList.addAll(transactionEvent.getEpcList() != null && !transactionEvent.getEpcList().isEmpty() ? transactionEvent.getEpcList() : Collections.emptyList()); //add child epcs
} else if (parentTracker.getEvent() instanceof AssociationEvent associationEvent) {
// For AssociationEvent add the Parent-Ids
parentIdentifiersList.add(associationEvent.getParentID() != null && !associationEvent.getParentID().isEmpty() ? associationEvent.getParentID() : null); //add parent id
parentIdentifiersList.addAll(associationEvent.getChildEPCs() != null && !associationEvent.getChildEPCs().isEmpty() ? associationEvent.getChildEPCs() : Collections.emptyList()); //add child epcs
}else if(parentTracker.getEvent() instanceof ObjectEvent objectEvent && objectEvent.getEpcList() != null && !objectEvent.getEpcList().isEmpty()){
} else if(parentTracker.getEvent() instanceof ObjectEvent objectEvent && objectEvent.getEpcList() != null && !objectEvent.getEpcList().isEmpty()){
//For objectEvent inherit from EPCS
parentIdentifiersList.addAll(objectEvent.getEpcList());
}else if(parentTracker.getEvent() instanceof TransformationEvent transformationEvent && transformationEvent.getOutputEPCList() != null && !transformationEvent.getOutputEPCList().isEmpty()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,14 @@ public class ReferencedIdentifier implements Serializable {
type = SchemaType.NUMBER,
description = "Number of parent identifiers inherited from parent node to child node")
private Integer inheritParentCount;

@Schema(
type = SchemaType.NUMBER,
description = "Number of parent identifiers inherited from parent node to subsequent child nodes EPCs/ChildEPCs application events Aggregation/Transaction/Association")
private Integer inheritParentToEPC;

@Schema(
type = SchemaType.NUMBER,
description = "Number of EPCs/ChildEPCs inherited from parent node to subsequent child nodes ParentID application events Aggregation/Transaction/Association")
private Integer inheritEPCToParent;
}

0 comments on commit d0660b9

Please sign in to comment.