@Override
protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object object, BindException errors)
throws Exception
{
RPAnagraficaObjectDTO anagraficaObjectDTO = (RPAnagraficaObjectDTO) object;
String exitPage = "redirect:/cris/tools/rp/editDynamicData.htm?id="
+ anagraficaObjectDTO.getParentId();
EditTabResearcherPage editT = getApplicationService().get(
EditTabResearcherPage.class,
anagraficaObjectDTO.getTabId());
if (anagraficaObjectDTO.getNewTabId() != null)
{
exitPage += "&tabId=" + anagraficaObjectDTO.getNewTabId();
}
else
{
exitPage = "redirect:/cris/rp/"
+ ResearcherPageUtils
.getPersistentIdentifier(anagraficaObjectDTO
.getParentId(), ResearcherPage.class) + "/"
+ editT.getShortName().substring(4) + ".html";
}
if (request.getParameter("cancel") != null)
{
return new ModelAndView(exitPage);
}
ResearcherPage researcher = getApplicationService().get(
ResearcherPage.class, anagraficaObjectDTO.getParentId());
RPAdditionalFieldStorage myObject = researcher.getDynamicField();
List<BoxResearcherPage> propertyHolders = new LinkedList<BoxResearcherPage>();
if (editT.getDisplayTab() != null)
{
for (BoxResearcherPage box : editT.getDisplayTab()
.getMask())
{
propertyHolders.add(box);
}
}
else
{
propertyHolders = getApplicationService().findPropertyHolderInTab(
getClazzTab(), anagraficaObjectDTO.getTabId());
}
List<IContainable> tipProprietaInArea = new LinkedList<IContainable>();
for (BoxResearcherPage iph : propertyHolders)
{
tipProprietaInArea
.addAll(getApplicationService()
.<BoxResearcherPage, it.cilea.osd.jdyna.web.Tab<BoxResearcherPage>> findContainableInPropertyHolder(
getClazzBox(), iph.getId()));
}
List<RPPropertiesDefinition> realTPS = new LinkedList<RPPropertiesDefinition>();
List<IContainable> structuralField = new LinkedList<IContainable>();
for (IContainable c : tipProprietaInArea)
{
RPPropertiesDefinition rpPd = getApplicationService()
.findPropertiesDefinitionByShortName(
RPPropertiesDefinition.class, c.getShortName());
if (rpPd != null)
{
realTPS.add(rpPd);
}
else
{
structuralField.add(c);
}
}
AnagraficaUtils.reverseDTO(anagraficaObjectDTO, myObject, realTPS);
myObject.pulisciAnagrafica();
researcher.setSourceID(anagraficaObjectDTO.getSourceID());
researcher.setStatus(anagraficaObjectDTO.getStatus());
researcher.setEpersonID(anagraficaObjectDTO.getEpersonID());
getApplicationService().saveOrUpdate(ResearcherPage.class, researcher);
EditTabResearcherPage area = getApplicationService().get(
getClazzTab(), anagraficaObjectDTO.getTabId());
final String areaTitle = area.getTitle();
saveMessage(
request,
getText("action.anagrafica.edited", new Object[] { areaTitle },
request.getLocale()));