use of alma.cdbErrType.CDBRecordDoesNotExistEx in project ACS by ACS-Community.
the class ACSAlarmDAOImpl method getReductionRules.
public alma.alarmsystem.alarmmessage.generated.ReductionDefinitions getReductionRules() {
if (conf == null)
throw new IllegalStateException("null configuration accessor");
alma.alarmsystem.alarmmessage.generated.ReductionDefinitions rds;
String xml;
try {
xml = conf.getConfiguration(REDUCTION_DEFINITION_PATH);
} catch (CDBRecordDoesNotExistEx e) {
rds = new alma.alarmsystem.alarmmessage.generated.ReductionDefinitions();
ReductionLinkDefinitionListType rld = new ReductionLinkDefinitionListType();
rld.setReductionLink(new alma.alarmsystem.alarmmessage.generated.ReductionLinkType[0]);
rds.setLinksToCreate(rld);
alma.alarmsystem.alarmmessage.generated.Thresholds ths = new alma.alarmsystem.alarmmessage.generated.Thresholds();
ths.setThreshold(new alma.alarmsystem.alarmmessage.generated.Threshold[0]);
rds.setThresholds(ths);
return rds;
} catch (Exception e) {
e.printStackTrace();
return null;
}
StringReader FFReader = new StringReader(xml);
Unmarshaller FF_unmarshaller = new Unmarshaller(alma.alarmsystem.alarmmessage.generated.ReductionDefinitions.class);
FF_unmarshaller.setValidation(false);
try {
rds = (alma.alarmsystem.alarmmessage.generated.ReductionDefinitions) FF_unmarshaller.unmarshal(FFReader);
} catch (MarshalException e) {
e.printStackTrace();
return null;
} catch (ValidationException e) {
e.printStackTrace();
return null;
}
try {
rds.validate();
} catch (ValidationException e) {
e.printStackTrace();
}
return rds;
}
use of alma.cdbErrType.CDBRecordDoesNotExistEx in project ACS by ACS-Community.
the class ACSCategoryDAOImpl method getCategories.
public Categories getCategories() {
if (conf == null || !conf.isWriteable())
throw new IllegalStateException("no writable configuration accessor");
Categories cats;
String xml;
try {
xml = conf.getConfiguration(CATEGORY_DEFINITION_PATH);
} catch (CDBRecordDoesNotExistEx e) {
cats = new Categories();
return cats;
} catch (Exception e1) {
e1.printStackTrace();
return null;
}
StringReader FFReader = new StringReader(xml);
Unmarshaller FF_unmarshaller = new Unmarshaller(Categories.class);
FF_unmarshaller.setValidation(false);
try {
cats = (Categories) FF_unmarshaller.unmarshal(FFReader);
} catch (MarshalException e1) {
e1.printStackTrace();
return null;
} catch (ValidationException e1) {
e1.printStackTrace();
return null;
}
try {
cats.validate();
} catch (ValidationException e1) {
e1.printStackTrace();
}
return cats;
}
use of alma.cdbErrType.CDBRecordDoesNotExistEx 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.CDBRecordDoesNotExistEx 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();
}
}
use of alma.cdbErrType.CDBRecordDoesNotExistEx in project ACS by ACS-Community.
the class ACSAlarmDAOImpl method getReductionDefinitions.
public ReductionDefinitions getReductionDefinitions() {
if (conf == null) {
throw new IllegalStateException("Missing dal");
}
String xml;
try {
xml = conf.getConfiguration(REDUCTION_DEFINITION_PATH);
} catch (CDBRecordDoesNotExistEx cdbEx) {
// No reduction rules defined in CDB
logger.log(AcsLogLevel.WARNING, "No reduction rules defined in CDB");
return null;
} catch (Exception e) {
throw new RuntimeException("Couldn't read " + REDUCTION_DEFINITION_PATH, e);
}
ReductionDefinitions rds = null;
try {
rds = (ReductionDefinitions) ReductionDefinitions.unmarshalReductionDefinitions(new StringReader(xml));
} catch (Exception e) {
throw new RuntimeException("Couldn't parse " + REDUCTION_DEFINITION_PATH, e);
}
return rds;
}
Aggregations