List<ElementToFindBean> arrElmToFind = hashDbToFind.get(dbToFind);
archivioCorrente = dbToFind;
if(userBean.getArchivesMap().get(dbToFind)==null){
continue;
}
Archive archiveBean = userBean.getArchivesMap().get(dbToFind);
String descrArchive = archiveBean.getArchiveDescr();
List<String> listCtrlModAuther = new ArrayList<String>();
if (!archiveBean.getAlias().equals("")) {
for (int a = 0; a < arrElmToFind.size(); a++) {
ModifyAutherBean autherBean = new ModifyAutherBean();
ElementToFindBean elementToFindBean = (ElementToFindBean) arrElmToFind.get(a);
System.out.println("ModifyAuther.execute() elementToFindBean.getStrQuery()" + elementToFindBean.getStrQuery() + "AAAA");
if (elementToFindBean.getStrQuery() != null && !elementToFindBean.getStrQuery().equals("null")) {
String query = "(" + elementToFindBean.getStrQuery() + "=" + codeToFind + ")";
System.out.println("query " + query + "<br>");
System.out.println("archivioCorrente " + archivioCorrente + "<br>");
XWConnection xwconn = null;
try {
xwconn = connectionManager.getConnection(archiveBean);
qr = xwconn.getQRfromPhrase(query);
System.out.println("ModifyAuther.execute() qr " + qr.elements);
} catch (Exception e) {
// throw new Exception("ERRORE NELLA CONNESSIONE CON IL DATABASE " + archiviBean.getTheArch());
} finally {
connectionManager.closeConnection(xwconn);
}
// System.out.println("<span style=\"background:#fff;\"><b>" + archivioCorrente + "</b>" + query + " occorrenze=" + qr.elements + "</span><br>");
autherBean.setArchivioAlias(archivioCorrente);
autherBean.setArchivioDescr(descrArchive);
autherBean.setElementToFindBean(elementToFindBean);
autherBean.setQuery(query);
autherBean.setNumElementi(qr.elements);
// escludere per ArchivioAlias e query
if (!listCtrlModAuther.contains(archivioCorrente + query)) {
modifyAutherBean.addArrModifyAutherBean(autherBean);
listCtrlModAuther.add(archivioCorrente + query);
}
}
}
}
}
modifyAutherBean.setDispatchView(jspDispatchMenu);
} else if (!codeToFind.equals("") && makeAction.equals("true")) {
System.out.println("ModifyAuther.execute() - SONO IN MODIFICA AUTH 1");
Map<String, List<ElementToFindBean>> hashDbToFind = buildElementToFindBean.buildElementToFindBean(theXMLconf, workFlowBean.getAlias());
int modificatiTotali = 0;
int erroriTotali = 0;
int modificatiXPathToChange = 0;
for (Entry<String, List<ElementToFindBean>> entrySet : hashDbToFind.entrySet()) {
System.out.println("ModifyAuther.execute() - SONO IN MODIFICA AUTH 2");
try {
String dbToFind = entrySet.getKey();
List<ElementToFindBean> arrElmToFind = hashDbToFind.get(dbToFind);
// Enumeration elementi = myRequest.getHttpServletRequest().getParameterNames();
boolean processArch = false;
System.out.println("ModifyAuther.execute() - SONO IN MODIFICA AUTH 3");
// while (elementi.hasMoreElements()) {
for (Entry<String, String[]> entry : parameterMap.entrySet()) {
String nome = entry.getKey();
if (nome.indexOf("theArchiveToProcess_") != -1) {
String tmpArch = MyRequest.getParameter(nome, parameterMap);
if (tmpArch.indexOf(dbToFind) != -1) {
// out.println(theArch+"vado a processare i record <br>");
processArch = true;
break;
}
}
}
System.out.println("ModifyAuther.execute() - SONO IN MODIFICA AUTH 3 processArch " + processArch);
if (processArch) {
if(userBean.getArchivesMap().get(dbToFind)==null){
continue;
}
Archive archiveBean = userBean.getArchivesMap().get(dbToFind);
System.out.println("ModifyAuther.execute() - SONO IN MODIFICA AUTH 4 archiviBean " + archiveBean);
String descrArchive = archiveBean.getArchiveDescr();
System.out.println("ModifyAuther.execute() - SONO IN MODIFICA AUTH 5 descrArchive " + descrArchive);
for (int z = 0; z < arrElmToFind.size(); z++) {
ElementToFindBean elementToFindBean = (ElementToFindBean) arrElmToFind.get(z);
String strQuery = elementToFindBean.getStrQuery();
String strPrefix = elementToFindBean.getStrPrefix();
String strCode = elementToFindBean.getStrCode();
String xPathToChange = elementToFindBean.getXPathToChange();
String isTextNode = elementToFindBean.getIsTextNode();
String query = "(" + strQuery + "=" + codeToFind + ")";
System.out.println("ModifyAuther.execute() - SONO IN MODIFICA AUTH 6 strQuery " + strQuery);
System.out.println("ModifyAuther.execute() - SONO IN MODIFICA AUTH su Archivio " + archiveBean.getAlias());
QueryResult qr = null;
XWConnection xwconn = null;
try {
xwconn = connectionManager.getConnection(archiveBean);
qr = xwconn.getQRfromPhrase(query);
if (qr.elements > 0) {
ModifyAutherBean autherBean = new ModifyAutherBean();
for (int a = 0; a < qr.elements; a++) {
boolean modificato = false;
int numDoc = xwconn.getNumDocFromQRElement(qr, a);
XMLBuilder builder = new XMLBuilder(xwconn.getSingleXMLFromNumDoc(numDoc), "ISO-8859-1");
// out.println("strPrefix "+strPrefix+"<br>");
if (elementToFindBean.isAdvEditing()) {
MappingAdv mappingAdv = new MappingAdv();
List<Element> list = mappingAdv.extractMapping(elementToFindBean.getConfigurationXMLReader().getObjects(), null, new HashMap<String, String>());
ArrayList<Element> arrayList = new ArrayList<Element>(list);
for (Element element : arrayList) {
List<Element> arrayListA = new ArrayList<Element>();
arrayListA.add(element);
mappingAdv.buildXML(arrayListA, builder, null, null, new GenericInterface<XMLBuilder>() {
public void invoke(XMLBuilder builder, Element element) {
try {
if (!nameToChange.equals(element.getFieldValue())) {
System.out.println(element.getFieldValue());
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
System.out.println("###############################");
System.out.println("###############################");
System.out.println("###############(elementToFindBean.isAdvEditing()################");
System.out.println("###############################");
System.out.println("###############################");
System.out.println("###############################");
} else {
int countPrefix = builder.contaNodi(strPrefix);
for (int x = 0; x < countPrefix; x++) {
String newXPathToChange = strPrefix + "[" + (x + 1) + "]" + xPathToChange.substring(xPathToChange.indexOf(strPrefix) + strPrefix.length());
String newXpathCode = "";
if (isTextNode.equals("true")) {
newXpathCode = newXPathToChange.substring(0, newXPathToChange.lastIndexOf("/") + 1) + strCode;
} else {
System.out.println("ModifyAuther.execute() CI SONO UN PREFIX strCode.indexOf(strPrefix)!=-1 " + strPrefix.contains(strCode));
System.out.println("ModifyAuther.execute() CI SONO UN PREFIX strPrefix " + strPrefix);
System.out.println("ModifyAuther.execute() CI SONO UN PREFIX strCode " + strCode);
if (strCode.indexOf(strPrefix) != -1) {
System.out.println("ModifyAuther.execute() CI SONO UN PREFIX DIDIDIDIDI");
newXpathCode = strPrefix + "[" + (x + 1) + "]" + StringUtils.difference(strPrefix, strCode);
System.out.println("ModifyAuther.execute() CI SONO UN PREFIX DIDIDIDIDI" + newXpathCode);
// newXpathCode = newXPathToChange.substring(0, newXPathToChange.lastIndexOf("/") + 1) + "@" + strCode;
} else {
if (strCode.indexOf("@") != -1) {
newXpathCode = newXPathToChange.substring(0, newXPathToChange.lastIndexOf("/") + 1) + strCode;
} else {
newXpathCode = newXPathToChange.substring(0, newXPathToChange.lastIndexOf("/") + 1) + "@" + strCode;
}
}
}
System.out.println("ModifyAuther.execute() newXpathCode " + newXpathCode);
String ilValoreCode = builder.valoreNodo(newXpathCode);
System.out.println("ModifyAuther.execute() ilValoreCode " + ilValoreCode);
System.out.println("ModifyAuther.execute() newXpathCode " + newXpathCode);
System.out.println("ModifyAuther.execute() newXpathCode " + newXpathCode);
System.out.println("ModifyAuther.execute() ilValoreCode " + ilValoreCode);
String ilValoreText = builder.valoreNodo(newXPathToChange);
System.out.println("ModifyAuther.execute() ilValoreText " + ilValoreText);
System.out.println("ModifyAuther.execute() ilValoreText " + ilValoreText);
System.out.println("ModifyAuther.execute() ilValoreText " + ilValoreText);
System.out.println("ModifyAuther.execute() ilValoreText " + ilValoreText);
System.out.println("ModifyAuther.execute() ilValoreText " + ilValoreText);
if (ilValoreCode.indexOf(codeToFind) != -1 && !ilValoreText.equals(nameToChange)) {
modificato = true;
builder.insertValueAt(newXPathToChange, nameToChange);
modificatiXPathToChange++;
}
}
if (modificato) {
// String rootElement = (builder.getDomDocument().getDocumentElement()).getNodeName();
// // out.println("rootElement "+rootElement+"<br>");
// if (rootElement.equals("c")) {
// int numProcessInfo = builder.contaNodi("/" + rootElement + "/processinfo/list/item");
// numProcessInfo++;
// builder.insertValueAt("/" + rootElement + "/processinfo/list/item[" + numProcessInfo + "]/persname/text()", myRequest.getParameter(".persona"));
// builder.insertValueAt("/" + rootElement + "/processinfo/list/item[" + numProcessInfo + "]/text()", myRequest.getParameter(".action"));
// builder.insertValueAt("/" + rootElement + "/processinfo/list/item[" + numProcessInfo + "]/date/text()", myRequest.getParameter(".data"));
// } else {
// int numProcessInfo = builder.contaNodi("/" + rootElement + "/eacheader/mainhistory/mainevent");
// numProcessInfo++;
// builder.insertValueAt("/" + rootElement + "/eacheader/mainhistory/mainevent[" + numProcessInfo + "]/name/text()", myRequest.getParameter(".persona"));
// builder.insertValueAt("/" + rootElement + "/eacheader/mainhistory/mainevent[" + numProcessInfo + "]/@maintype", myRequest.getParameter(".action"));
// builder.insertValueAt("/" + rootElement + "/eacheader/mainhistory/mainevent[" + numProcessInfo + "]/maindate/text()", myRequest.getParameter(".data"));
// }
modificatiTotali++;
String docXML = builder.getXML("ISO-8859-1");
docXML = XMLCleaner.clearXwXML(docXML, true);
try {
xwconn.executeUpdateByDocNumber(docXML, numDoc);
} catch (Exception e) {
erroriTotali++;
modifyAutherBean.addErrorMsg("Errore in proietta authority per il documento numero " + numDoc + " in " + descrArchive + " " + e.getMessage());
e.printStackTrace();
}
}
}
}
autherBean.setArchivioAlias(archiveBean.getAlias());
autherBean.setArchivioDescr(descrArchive);
elementToFindBean.setNumTotXPathToChange(modificatiXPathToChange);
autherBean.setElementToFindBean(elementToFindBean);
autherBean.setQuery(query);
autherBean.setNumElementi(qr.elements);