Révision bf9c3717
Ajouté par Remy Menard il y a environ 11 ans
ALfA/ALfA/src/main/java/fr/unicaen/iota/application/operations/TraceEPC.java | ||
---|---|---|
import fr.unicaen.iota.tau.model.Identity;
|
||
import java.rmi.RemoteException;
|
||
import java.util.*;
|
||
import java.util.Map.Entry;
|
||
import org.apache.commons.logging.Log;
|
||
import org.apache.commons.logging.LogFactory;
|
||
import org.fosstrak.epcis.model.AggregationEventType;
|
||
... | ... | |
return traceEPCAux(EPC, new HashMap<String, String>());
|
||
}
|
||
|
||
public Map<String, List<EPCISEventType>> traceEPCbyEPCIS(String EPC) throws RemoteException {
|
||
log.trace("EPC = " + EPC);
|
||
return traceEPCAuxByEPCIS(EPC, new HashMap<String, String>());
|
||
}
|
||
|
||
public List<EPCISEventType> filteredTrace(String EPC, Map<String, String> filters) throws RemoteException {
|
||
log.trace("Filters = " + filters);
|
||
return traceEPCAux(EPC, filters);
|
||
}
|
||
|
||
public Map<String, List<EPCISEventType>> filteredTracebyEPCIS(String EPC, Map<String, String> filters) throws RemoteException {
|
||
log.trace("Filters = " + filters);
|
||
return traceEPCAuxByEPCIS(EPC, filters);
|
||
}
|
||
|
||
private List<EPCISEventType> traceEPCAux(String EPC, Map<String, String> filters) throws RemoteException {
|
||
log.trace("[TRACE EPC]: " + EPC);
|
||
log.trace("Get Referent ds address");
|
||
... | ... | |
return traceEPC(dsOp, EPC, filters);
|
||
}
|
||
|
||
private Map<String, List<EPCISEventType>> traceEPCAuxByEPCIS(String EPC, Map<String, String> filters) throws RemoteException {
|
||
log.trace("[TRACE EPC BY EPCIS]: " + EPC);
|
||
log.trace("Get Referent ds address");
|
||
String dsAddress = onsOperation.getReferentIDedDS(EPC);
|
||
if (dsAddress == null) {
|
||
log.warn("Unable to retreive referent ds address for this epc code");
|
||
return new HashMap<String, List<EPCISEventType>>();
|
||
} else {
|
||
log.trace("referent ds address found: " + dsAddress);
|
||
}
|
||
log.trace("Start discover");
|
||
DiscoveryOperation dsOp = new DiscoveryOperation(identity, dsAddress, pksFilename, pksPassword, trustPksFilename, trustPksPassword);
|
||
return traceEPCByEPCIS(dsOp, EPC, filters);
|
||
}
|
||
|
||
private List<EPCISEventType> traceEPC(DiscoveryOperation dsOp, String EPC, Map<String, String> filters) throws RemoteException {
|
||
List<EPCISEventType> eventList = new ArrayList<EPCISEventType>();
|
||
for (String EPCIS_SERVICE_ADDRESS : dsOp.discover(EPC)) {
|
||
EpcisOperation epcisOperation = null;
|
||
while (epcisOperation == null) {
|
||
try {
|
||
epcisOperation = new EpcisOperation(identity, EPCIS_SERVICE_ADDRESS, pksFilename, pksPassword, trustPksFilename, trustPksPassword);
|
||
} catch (Exception ex) {
|
||
epcisOperation = null;
|
||
log.warn("Unable to create service proxy port! [RETRYING]", ex);
|
||
}
|
||
try {
|
||
epcisOperation = new EpcisOperation(identity, EPCIS_SERVICE_ADDRESS, pksFilename, pksPassword, trustPksFilename, trustPksPassword);
|
||
} catch (Exception ex) {
|
||
epcisOperation = null;
|
||
String msg = "Unable to create service proxy port";
|
||
log.warn(msg, ex);
|
||
throw new RemoteException(msg, ex);
|
||
}
|
||
Collection<EPCISEventType> list = epcisOperation.getObjectEventFromEPC(EPC, filters);
|
||
eventList.addAll(list);
|
||
... | ... | |
}
|
||
return eventList;
|
||
}
|
||
|
||
private Map<String, List<EPCISEventType>> traceEPCByEPCIS(DiscoveryOperation dsOp, String EPC, Map<String, String> filters) throws RemoteException {
|
||
Map<String, List<EPCISEventType>> eventListByEPCIS = new HashMap<String, List<EPCISEventType>>();
|
||
for (String EPCIS_SERVICE_ADDRESS : dsOp.discover(EPC)) {
|
||
EpcisOperation epcisOperation = null;
|
||
try {
|
||
epcisOperation = new EpcisOperation(identity, EPCIS_SERVICE_ADDRESS, pksFilename, pksPassword, trustPksFilename, trustPksPassword);
|
||
} catch (Exception ex) {
|
||
String msg = "Unable to create service proxy port";
|
||
log.warn(msg, ex);
|
||
throw new RemoteException(msg, ex);
|
||
}
|
||
List<EPCISEventType> list = epcisOperation.getObjectEventFromEPC(EPC, filters);
|
||
addToMap(eventListByEPCIS, EPCIS_SERVICE_ADDRESS, list);
|
||
list = epcisOperation.getQuantityEventFromEPC(EPC, filters);
|
||
addToMap(eventListByEPCIS, EPCIS_SERVICE_ADDRESS, list);
|
||
log.trace("nbr epc events: " + list.size());
|
||
List<EPCISEventType> children = epcisOperation.getAggregationEventFromEPC(EPC, filters);
|
||
addToMap(eventListByEPCIS, EPCIS_SERVICE_ADDRESS, children);
|
||
log.trace("nbr child events: " + children.size());
|
||
for (EPCISEventType o : children) {
|
||
AggregationEventType event = (AggregationEventType) o;
|
||
for (EPC childEpc : event.getChildEPCs().getEpc()) {
|
||
log.trace("new traceEPC: " + childEpc.getValue());
|
||
Map<String, List<EPCISEventType>> agEventMap = traceEPCAuxByEPCIS(childEpc.getValue(), filters);
|
||
addToMap(eventListByEPCIS, agEventMap);
|
||
}
|
||
}
|
||
List<EPCISEventType> trans = epcisOperation.getTransactionEventFromEPC(EPC, filters);
|
||
addToMap(eventListByEPCIS, EPCIS_SERVICE_ADDRESS, trans);
|
||
for (EPCISEventType o : trans) {
|
||
TransactionEventType event = (TransactionEventType) o;
|
||
for (EPC childEpc : event.getEpcList().getEpc()) {
|
||
log.trace("new traceEPC: " + childEpc.getValue());
|
||
Map<String, List<EPCISEventType>> transEventMap = traceEPCAuxByEPCIS(childEpc.getValue(), filters);
|
||
addToMap(eventListByEPCIS, transEventMap);
|
||
}
|
||
}
|
||
}
|
||
return eventListByEPCIS;
|
||
}
|
||
|
||
private void addToMap(Map<String, List<EPCISEventType>> map, String epcisAddress, List<EPCISEventType> listToAdd) {
|
||
if (map.containsKey(epcisAddress)) {
|
||
map.get(epcisAddress).addAll(listToAdd);
|
||
}
|
||
else {
|
||
map.put(epcisAddress, listToAdd);
|
||
}
|
||
}
|
||
|
||
private void addToMap(Map<String, List<EPCISEventType>> map, Map<String, List<EPCISEventType>> mapToAdd) {
|
||
for (Entry<String, List<EPCISEventType>> mapToAddEntry : mapToAdd.entrySet()) {
|
||
String epcisAddress = mapToAddEntry.getKey();
|
||
List<EPCISEventType> eventList = mapToAddEntry.getValue();
|
||
if (map.containsKey(epcisAddress)) {
|
||
map.get(epcisAddress).addAll(eventList);
|
||
} else {
|
||
map.put(epcisAddress, eventList);
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
Formats disponibles : Unified diff
Version 1.99
- a few bugs fixed!
- new testing application to capture events
- new options to the command line to configure the public/private keys
for TLS and for signature
- new method more accurate than "traceEPC": the events are sorted by
EPCIS
- New options added to the command line
- user can be identified by alias, if the DN of his certificate is
incompatible with the LDAP directory
- new shell script to configure the LDAP directory (same
functionnalities as IoTa-Installer)
- installs and configures LaMBDa
- finer certificate mangagement
- EpcILoN correctly subscribe with TLS to ETa
- new figure for LaMBDa
- shows data flows between PHI and YPSilon
- sets DS and DSeTa in different schemas