use of alma.cdbErrType.CDBRecordIsReadOnlyEx in project ACS by ACS-Community.
the class CDBLogic method saveTable.
public static void saveTable() {
if (tableChanged) {
Browser.getInstance().display("MESSAGE: Saving values for table " + Browser.getInstance().getPath() + ". ", true);
// -> DV added
try {
// compose short xml of changed fields and send it to the WDAL
// we must find node for DAL since we can be inside inner element i.e. MOUNT/current
boolean isNode = XMLIndexEnabled;
String currentPath = CDBLogic.getKey();
String curl = CDBLogic.getKey();
while (CDBLogic.xmls.get(curl) == null) {
curl = curl.substring(0, curl.lastIndexOf('/'));
}
// TODO find better way for curl finding
// TODO BUG CDBLogic.getKey() must be used because maps are filled with it but it is not synchronized
// with Browser.getInstance().getPath()
String elementName;
if (// in cases when we have element which is not a node i.e. 'current' inside 'TEST_PS_1' then we strip elementName
!currentPath.equals(curl))
elementName = currentPath.substring(curl.length() + 1);
else
elementName = "";
curl = curl.substring("/root/".length());
System.out.println("curl=" + curl + " elem=" + elementName);
//
// send changed values to the WDAL
StringWriter sw = new StringWriter();
sw.write("<?xml version='1.0' encoding='ISO-8859-1'?>\n");
sw.write("<curl ");
if (elementName.length() > 0)
sw.write("><" + elementName + " ");
for (int i = 0; i < selectedTableModel.getRowCount(); i++) {
if (selectedTableModel.resetValue.get(new Integer(i)) != null) {
System.out.println(XMLIndexEnabled + " " + Browser.getInstance().getPath() + " changed is " + selectedTableModel.getValueAt(i, 0) + "=" + selectedTableModel.getValueAt(i, 1));
sw.write(selectedTableModel.getValueAt(i, 0) + "=\"" + selectedTableModel.getValueAt(i, 1) + "\" ");
}
}
if (elementName.length() > 0)
sw.write("/></curl>");
else
sw.write("/>");
if (wdal != null) {
Browser.getInstance().display("Invoking set_DAO for " + curl, true);
wdal.set_DAO(curl, sw.toString());
}
} catch (CDBRecordIsReadOnlyEx e) {
e.printStackTrace();
Browser.getInstance().display("==> ERROR MESSAGE: The file or record is read only: " + e, true);
} catch (Exception e) {
e.printStackTrace();
Browser.getInstance().display("==> ERROR MESSAGE: Exception while saving changes " + e, true);
}
// <-
Browser.getInstance().enableButtons(false);
CDBTree.setEnabled(true);
if (XMLIndexEnabled) {
selectedTabbedPane.setEnabledAt(xmlIndex, true);
XMLIndexEnabled = false;
}
tableChanged = false;
selectedTable.emptyArray();
}
}
use of alma.cdbErrType.CDBRecordIsReadOnlyEx in project ACS by ACS-Community.
the class WDALImpl method remove_node.
/**
* Removes node identified by curl by deleting its file and directory if
* empty.
*
* @param curl uri for the CDB node
*
* @throws CDBRecordDoesNotExistEx
* @throws CDBRecordIsReadOnlyEx
*/
public void remove_node(String curl) throws CDBRecordDoesNotExistEx, CDBRecordIsReadOnlyEx {
dalImpl.totalDALInvocationCounter.incrementAndGet();
logger.log(AcsLogLevel.INFO, "remove_node " + curl);
// check if node exists
if (!nodeExists(curl)) {
logger.log(AcsLogLevel.NOTICE, "Record does not exist: " + curl);
throw new CDBRecordDoesNotExistEx();
}
// if so delete nodes file
File xmlFile = getNodeFile(curl);
boolean deleted = xmlFile.delete();
// if we can't delete it assume that it is read only
if (!deleted) {
throw new CDBRecordIsReadOnlyEx();
}
// also delete directory node but don't care if it is not empty and we actually didn't delete it
xmlFile.getParentFile().delete();
// let other new the node gone
clear_cache(curl);
}
use of alma.cdbErrType.CDBRecordIsReadOnlyEx in project ACS by ACS-Community.
the class WDALImpl method set_DAO.
/**
* Change content of a node identified by curl so given xml is scanned for
* differences which are applied. This function can be invoked with full
* expanded version of the existing xml with some changes or it can be
* invoked by small xml with only changes to be applied. For example to
* change parameter 'Timeot' in Manager we can pass as xml
* <pre>
* <code>
* <?xml version="1.0" encoding="ISO-8859-1"?>
* <Manager Timeout="50.0"/>
* </code>
* </pre>
* and new value will be saved in the xml file.
*
* @param curl uri for the CDB node
* @param xml
*
* @throws CDBRecordDoesNotExistEx
* @throws CDBFieldDoesNotExistEx
* @throws CDBRecordIsReadOnlyEx
* @throws CDBXMLErrorEx
* @throws CDBExceptionEx
*/
public void set_DAO(String curl, String xml) throws CDBRecordDoesNotExistEx, CDBFieldDoesNotExistEx, CDBRecordIsReadOnlyEx, CDBXMLErrorEx, CDBExceptionEx {
dalImpl.totalDALInvocationCounter.incrementAndGet();
logger.log(AcsLogLevel.INFO, "set_DAO " + curl);
// check if node exists
if (!nodeExists(curl)) {
logger.log(AcsLogLevel.NOTICE, "Record does not exist: " + curl);
throw new CDBRecordDoesNotExistEx();
}
File xmlFile = getNodeFile(curl);
if (!xmlFile.canWrite()) {
throw new CDBRecordIsReadOnlyEx();
}
// read given xml and iterate through its content and check if something was changed
DAOImpl daoImp = null;
XMLHandler daoXMLSolver = null;
// get content of the given xml string using parser without any shemas and validation
// since given xml string come from a client that have no shemas and it is full expanded version
// of existing xml or it is smal composed xml of few properties
XMLHandler xmlSolver = new XMLHandler(false, logger);
// TODO markArrays == 2 impl. is a mess... I think lot of code could be removed!
//xmlSolver.setMarkArrays(2);
parseXML(xml, xmlSolver);
// get original xml that we will use to compare
xml = dalImpl.get_DAO(curl);
daoXMLSolver = new XMLHandler(false, logger);
parseXML(xml, daoXMLSolver);
daoImp = new DAOImpl(curl, daoXMLSolver.m_rootNode, poa, logger);
// iterater throuth given xml and put changed attributes in map
LinkedHashMap map = new LinkedHashMap();
try {
checkforChanges("", xmlSolver.m_rootNode, map, daoImp);
saveChanges(curl, map);
} catch (AcsJCDBFieldDoesNotExistEx e) {
throw e.toCDBFieldDoesNotExistEx();
} catch (AcsJCDBXMLErrorEx e) {
throw e.toCDBXMLErrorEx();
} catch (AcsJCDBExceptionEx e) {
throw e.toCDBExceptionEx();
}
}
Aggregations