Search in sources :

Example 1 with CDBRecordDoesNotExistEx

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;
}
Also used : Thresholds(alma.alarmsystem.alarmmessage.generated.Thresholds) MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) Thresholds(alma.alarmsystem.alarmmessage.generated.Thresholds) ReductionDefinitions(alma.alarmsystem.alarmmessage.generated.ReductionDefinitions) ReductionDefinitions(alma.alarmsystem.alarmmessage.generated.ReductionDefinitions) LaserObjectNotFoundException(cern.laser.business.LaserObjectNotFoundException) PatternSyntaxException(java.util.regex.PatternSyntaxException) ValidationException(org.exolab.castor.xml.ValidationException) MarshalException(org.exolab.castor.xml.MarshalException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) CDBRecordDoesNotExistEx(alma.cdbErrType.CDBRecordDoesNotExistEx) ReductionLinkType(alma.alarmsystem.alarmmessage.generated.ReductionLinkType) StringReader(java.io.StringReader) Unmarshaller(org.exolab.castor.xml.Unmarshaller) ReductionLinkDefinitionListType(alma.alarmsystem.alarmmessage.generated.ReductionLinkDefinitionListType) Threshold(alma.alarmsystem.alarmmessage.generated.Threshold)

Example 2 with CDBRecordDoesNotExistEx

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;
}
Also used : MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) Categories(alma.acs.alarmsystem.generated.Categories) StringReader(java.io.StringReader) Unmarshaller(org.exolab.castor.xml.Unmarshaller) LaserObjectNotFoundException(cern.laser.business.LaserObjectNotFoundException) ValidationException(org.exolab.castor.xml.ValidationException) MarshalException(org.exolab.castor.xml.MarshalException) IOException(java.io.IOException) CDBRecordDoesNotExistEx(alma.cdbErrType.CDBRecordDoesNotExistEx)

Example 3 with CDBRecordDoesNotExistEx

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);
}
Also used : CDBRecordIsReadOnlyEx(alma.cdbErrType.CDBRecordIsReadOnlyEx) File(java.io.File) CDBRecordDoesNotExistEx(alma.cdbErrType.CDBRecordDoesNotExistEx)

Example 4 with CDBRecordDoesNotExistEx

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();
    }
}
Also used : AcsJCDBExceptionEx(alma.cdbErrType.wrappers.AcsJCDBExceptionEx) AcsJCDBFieldDoesNotExistEx(alma.cdbErrType.wrappers.AcsJCDBFieldDoesNotExistEx) CDBRecordIsReadOnlyEx(alma.cdbErrType.CDBRecordIsReadOnlyEx) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) File(java.io.File) CDBRecordDoesNotExistEx(alma.cdbErrType.CDBRecordDoesNotExistEx) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with CDBRecordDoesNotExistEx

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;
}
Also used : StringReader(java.io.StringReader) ReductionDefinitions(alma.alarmsystem.alarmmessage.generated.ReductionDefinitions) LaserObjectNotFoundException(cern.laser.business.LaserObjectNotFoundException) MalformedURLException(java.net.MalformedURLException) CDBRecordDoesNotExistEx(alma.cdbErrType.CDBRecordDoesNotExistEx)

Aggregations

CDBRecordDoesNotExistEx (alma.cdbErrType.CDBRecordDoesNotExistEx)14 IOException (java.io.IOException)6 StringReader (java.io.StringReader)6 MarshalException (org.exolab.castor.xml.MarshalException)6 ValidationException (org.exolab.castor.xml.ValidationException)6 LaserObjectNotFoundException (cern.laser.business.LaserObjectNotFoundException)5 MalformedURLException (java.net.MalformedURLException)4 ReductionDefinitions (alma.alarmsystem.alarmmessage.generated.ReductionDefinitions)3 AcsJCDBRecordDoesNotExistEx (alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx)3 StringWriter (java.io.StringWriter)3 PatternSyntaxException (java.util.regex.PatternSyntaxException)3 CDBFieldDoesNotExistEx (alma.cdbErrType.CDBFieldDoesNotExistEx)2 CDBRecordIsReadOnlyEx (alma.cdbErrType.CDBRecordIsReadOnlyEx)2 CDBXMLErrorEx (alma.cdbErrType.CDBXMLErrorEx)2 File (java.io.File)2 Marshaller (org.exolab.castor.xml.Marshaller)2 Unmarshaller (org.exolab.castor.xml.Unmarshaller)2 BACIPropertyType (alma.TMCDB.baci.BACIPropertyType)1 EmptyStringHandlerBACIPropertyType (alma.TMCDB.baci.EmptyStringHandlerBACIPropertyType)1 Categories (alma.acs.alarmsystem.generated.Categories)1