log.info("Start import " + new Date());
// foreach researcher element in xml
for (int i = 0; i < researchers.size(); i++)
{
log.info("Number " + i + " of " + researchers.size());
ResearcherPage researcher = null;
try
{
Element node = researchers.get(i);
// check if staffNo and rpid exists as attribute
// String nodeId = (String) xpath.evaluate(XPATH_RULES[1], node,
// XPathConstants.STRING);
// String rpId = (String) xpath.evaluate(XPATH_RULES[3], node,
// XPathConstants.STRING);
String nodeId = node
.getAttribute(UtilsXML.NAMEATTRIBUTE_STAFF_NO);
String rpId = node.getAttribute(UtilsXML.NAMEATTRIBUTE_RPID);
ResearcherPage clone = null;
// use dto to fill dynamic metadata
AnagraficaObjectDTO dto = new AnagraficaObjectDTO();
AnagraficaObjectDTO clonedto = new AnagraficaObjectDTO();
boolean update = false; // if update a true then set field to
// null
// on case of empty element
if (nodeId == null || nodeId.isEmpty())
{
log.error("Researcher discarded ( staffNo not founded) [position researcher: "
+ i + "]");
throw new RuntimeException(
"Researcher discarded (staffNo not founded whilst rpId is on xml) [position researcher: "
+ i + "]");
}
else
{
// if there is rpid then try to get researcher by staffNo
// and
// set to null all structural metadata lists
log.info("Researcher staffNo : " + nodeId
+ " / rp identifier : " + rpId);
if (rpId != null && !rpId.isEmpty())
{
researcher = applicationService
.getResearcherPageByStaffNo(nodeId);
if (researcher == null)
{
log.error("Researcher discarded (staffNo not founded whilst rpId is on xml) [position researcher: "
+ i + "]");
;
throw new RuntimeException(
"Researcher discarded (staffNo not founded whilst rpId is on xml) [position researcher: "
+ i + "]");
}
else
{
if (!rpId.equals(ResearcherPageUtils
.getPersistentIdentifier(researcher)))
{
log.error("Researcher discarded (rpId don't match persistent identifier) [position researcher: "
+ i + "]");
throw new RuntimeException(
"Researcher discarded (staffNo not founded whilst rpId is on xml) [position researcher: "
+ i + "]");
}
}
// clone dynamic data and structural on dto
clone = (ResearcherPage) researcher.clone();
RPAdditionalFieldStorage additionalTemp = new RPAdditionalFieldStorage();
clone.setDynamicField(additionalTemp);
additionalTemp.duplicaAnagrafica(researcher
.getDynamicField());
update = true;
}
else
{
// here there is perhaps a new researcher
researcher = applicationService
.getResearcherPageByStaffNo(nodeId);
if (researcher == null)
{
researcher = new ResearcherPage();
researcher.setSourceID(nodeId);
// added by Allen: all newly added researchers are
// inactive by default
// use -active in command line to change default
// status to active.
researcher.setStatus(status);
clone = (ResearcherPage) researcher.clone();
RPAdditionalFieldStorage additionalTemp = new RPAdditionalFieldStorage();
clone.setDynamicField(additionalTemp);
additionalTemp.duplicaAnagrafica(researcher
.getDynamicField());
}
else
{
log.error("Researcher discarded (staffNo " + nodeId
+ " already exist) [position researcher: "
+ i + "]");
throw new RuntimeException(
"Researcher discarded (staffNo "
+ nodeId
+ " already exist) [position researcher: "
+ i + "]");
}
}
}
AnagraficaUtils.fillDTO(dto, researcher.getDynamicField(),
realFillTPS);
// one-shot fill and reverse to well-format clonedto and clean
// empty
// data
AnagraficaUtils.fillDTO(clonedto, clone.getDynamicField(),
realFillTPS);
AnagraficaUtils.reverseDTO(clonedto, clone.getDynamicField(),
realFillTPS);
AnagraficaUtils.fillDTO(clonedto, clone.getDynamicField(),
realFillTPS);
importDynAXML(applicationService, realFillTPS, node, dto,
clonedto, update);
for (IContainable containable : structuralFillField)