Search in sources :

Example 1 with AcsJCDBRecordDoesNotExistEx

use of alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx in project ACS by ACS-Community.

the class DALImpl method loadRecords.

/**
	 * Returns a xml constructed of all records below given curl
	 * 
	 * @param curl
	 * @param toString
	 * @return
	 * @throws AcsJCDBRecordDoesNotExistEx
	 * @throws AcsJCDBXMLErrorEx
	 */
public XMLHandler loadRecords(String curl, boolean toString) throws AcsJCDBRecordDoesNotExistEx, AcsJCDBXMLErrorEx {
    StopWatch sw = new StopWatch(m_logger);
    try {
        // create hierarchy of all nodes if it is not created yet 
        synchronized (this) {
            if (rootNode == null) {
                //no Error thrown
                rootNode = DALNode.getRoot(m_root);
            }
        }
        //no Error thrown
        String strFileCurl = curl;
        String strNodeCurl = "";
        DALNode curlNode = null;
        boolean isEmbeddedNode = false;
        while (strFileCurl != null) {
            curlNode = rootNode.findNode(strFileCurl);
            if (curlNode == null) {
                // Therefore we must move up toward the root node to find a valid parent xml node.
                if (strFileCurl.lastIndexOf('/') > 0) {
                    strNodeCurl = strFileCurl.substring(strFileCurl.lastIndexOf('/') + 1) + "/" + strNodeCurl;
                    strFileCurl = strFileCurl.substring(0, strFileCurl.lastIndexOf('/'));
                    isEmbeddedNode = true;
                } else {
                    strFileCurl = null;
                }
            } else {
                // curlNode and strFileCurl point to the node that has the relevant XML file 
                break;
            }
        }
        m_logger.log(AcsLogLevel.DEBUG, "loadRecords(curl=" + curl + "), strFileCurl=" + strFileCurl + ", strNodeCurl=" + strNodeCurl);
        // because the "embedded" node data will not be found in other XML files.
        if (strFileCurl == null || (isEmbeddedNode && !curlNode.hasXmlChild())) {
            AcsJCDBRecordDoesNotExistEx recordDoesNotExist = new AcsJCDBRecordDoesNotExistEx();
            recordDoesNotExist.setCurl(curl);
            throw recordDoesNotExist;
        }
        if (curlNode.isSimple()) {
            m_logger.log(AcsLogLevel.DEBUG, "loadRecords(curl=" + curl + "); curlNode '" + curlNode.name + "' is simple.");
            if (curl.equals(strFileCurl)) {
                return loadRecord(strFileCurl, toString);
            } else {
                XMLHandler xmlSolver = loadRecord(strFileCurl, false);
                try {
                    return xmlSolver.getChild(strNodeCurl);
                } catch (AcsJCDBRecordDoesNotExistEx e) {
                    e.setCurl(strFileCurl + e.getCurl());
                    throw e;
                }
            }
        }
        m_logger.log(AcsLogLevel.DEBUG, "loadRecords(curl=" + curl + "), curlNode is Complex");
        XMLHandler xmlSolver;
        try {
            //xmlSolver.startElement(null,null,"curl",new org.xml.sax.helpers.AttributesImpl);
            if (curl.equals(strFileCurl)) {
                xmlSolver = new XMLHandler(toString, m_logger);
                xmlSolver.setAutoCloseStartingElement(false);
                parseNode(curlNode, xmlSolver, "");
                //xmlSolver.closeElement();
                return xmlSolver;
            } else {
                //here we must return the node inside the xmlSolver with curl= strNodeCurl		
                xmlSolver = new XMLHandler(false, m_logger);
                xmlSolver.setMarkArrays(1);
                xmlSolver.setAutoCloseStartingElement(false);
                parseNode(curlNode, xmlSolver, "");
                return xmlSolver.getChild(strNodeCurl);
            }
        } catch (AcsJCDBRecordDoesNotExistEx e) {
            e.setCurl(strFileCurl + e.getCurl());
            throw e;
        } catch (SAXParseException e) {
            AcsJCDBXMLErrorEx cdbxmlErr = new AcsJCDBXMLErrorEx();
            cdbxmlErr.setErrorString("SAXParseException: " + e.getMessage());
            cdbxmlErr.setCurl(curl);
            cdbxmlErr.setFilename(e.getSystemId() + ", line=" + e.getLineNumber());
            throw cdbxmlErr;
        } catch (Throwable thr) {
            AcsJCDBXMLErrorEx cdbxmlErr = new AcsJCDBXMLErrorEx(thr);
            cdbxmlErr.setCurl(curl);
            throw cdbxmlErr;
        }
    } finally {
        long lt = sw.getLapTimeMillis();
        m_logger.finest("Time spent in loadRecords(" + curl + "): " + lt);
    }
}
Also used : SAXParseException(org.xml.sax.SAXParseException) AcsJCDBRecordDoesNotExistEx(alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) StopWatch(alma.acs.util.StopWatch)

Example 2 with AcsJCDBRecordDoesNotExistEx

use of alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx in project ACS by ACS-Community.

the class DALImpl method loadRecord.

private XMLHandler loadRecord(String curl, boolean toString) throws AcsJCDBRecordDoesNotExistEx, AcsJCDBXMLErrorEx {
    String xmlPath = getRecordPath(curl);
    File xmlFile = new File(xmlPath);
    if (!xmlFile.exists()) {
        AcsJCDBRecordDoesNotExistEx recordDoesNotExist = new AcsJCDBRecordDoesNotExistEx();
        recordDoesNotExist.setCurl(curl);
        throw recordDoesNotExist;
    }
    XMLHandler xmlSolver = new XMLHandler(toString, m_logger);
    xmlSolver.setMarkArrays(1);
    try {
        m_logger.log(AcsLogLevel.DEBUG, "Parsing xmlFile=" + xmlFile);
        saxParser.parse(xmlFile, xmlSolver);
        if (xmlSolver.m_errorString != null) {
            String info = "XML parser error: " + xmlSolver.m_errorString;
            //CDBXMLError xmlErr = new CDBXMLError(info);
            AcsJCDBXMLErrorEx cdbxmlErr = new AcsJCDBXMLErrorEx();
            cdbxmlErr.setFilename(xmlPath);
            cdbxmlErr.setCurl(curl);
            cdbxmlErr.setErrorString(info);
            throw cdbxmlErr;
        }
        return xmlSolver;
    } catch (AcsJCDBXMLErrorEx cdbxmlErr) {
        throw cdbxmlErr;
    } catch (Throwable t) {
        String info = "SAXException " + t;
        //CDBXMLError xmlErr = new CDBXMLError(info);
        AcsJCDBXMLErrorEx cdbxmlErr = new AcsJCDBXMLErrorEx(t);
        cdbxmlErr.setCurl(curl);
        cdbxmlErr.setErrorString(info);
        throw cdbxmlErr;
    }
}
Also used : AcsJCDBRecordDoesNotExistEx(alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) File(java.io.File)

Example 3 with AcsJCDBRecordDoesNotExistEx

use of alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx in project ACS by ACS-Community.

the class HibernateWDALImpl method saveChanges.

/**
	 * Save changes given by map to the node identified by curl
	 *
	 * @param curl
	 * @param propertyMap
	 *
	 * @throws CDBXMLErrorEx
	 * @throws CDBExceptionEx
	 * @throws CDBFieldDoesNotExistEx
	 */
public void saveChanges(String curl, Map propertyMap) throws CDBXMLErrorEx, CDBExceptionEx, CDBFieldDoesNotExistEx, CDBRecordDoesNotExistEx {
    Object node = curl.length() == 0 ? rootNode : DOMJavaClassIntrospector.getNode(curl, rootNode);
    if (node == null || DOMJavaClassIntrospector.isPrimitive(node.getClass())) {
        AcsJCDBRecordDoesNotExistEx ex = new AcsJCDBRecordDoesNotExistEx();
        ex.setCurl(curl);
        m_logger.log(AcsLogLevel.NOTICE, "WDAL::saveChanges " + ex.getShortDescription());
        throw ex.toCDBRecordDoesNotExistEx();
    }
    boolean commit = false;
    Transaction tr = mainSession.beginTransaction();
    try {
        HibernateWDAOImpl wdao = new HibernateWDAOImpl(mainSession, curl, node, poa, m_logger, false, false);
        for (Object key : propertyMap.keySet()) {
            String propertyName = key.toString();
            wdao.set_field_data(propertyName, propertyMap.get(propertyName).toString());
        }
        commit = true;
    } catch (CDBFieldIsReadOnlyEx fne) {
        AcsJCDBExceptionEx cdbex = new AcsJCDBExceptionEx(fne);
        throw cdbex.toCDBExceptionEx();
    } catch (WrongCDBDataTypeEx fne) {
        AcsJCDBExceptionEx cdbex = new AcsJCDBExceptionEx(fne);
        throw cdbex.toCDBExceptionEx();
    } finally {
        if (commit)
            tr.commit();
        else
            tr.rollback();
    }
/// TODO revert memory state?!!!
}
Also used : AcsJCDBExceptionEx(alma.cdbErrType.wrappers.AcsJCDBExceptionEx) Transaction(org.hibernate.Transaction) CDBFieldIsReadOnlyEx(alma.cdbErrType.CDBFieldIsReadOnlyEx) AcsJCDBRecordDoesNotExistEx(alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx) AcsJWrongCDBDataTypeEx(alma.cdbErrType.wrappers.AcsJWrongCDBDataTypeEx) WrongCDBDataTypeEx(alma.cdbErrType.WrongCDBDataTypeEx)

Example 4 with AcsJCDBRecordDoesNotExistEx

use of alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx in project ACS by ACS-Community.

the class DOMConfigurationAccessor method getConfiguration.

/* (non-Javadoc)
	 * @see com.cosylab.acs.laser.dao.ConfigurationAccessor#getConfiguration(java.lang.String)
	 */
@Override
public String getConfiguration(String curl) throws Exception {
    Object obj = objectMap.get(curl);
    if (obj == null) {
        AcsJCDBRecordDoesNotExistEx ex = new AcsJCDBRecordDoesNotExistEx();
        ex.setCurl(curl);
        throw ex.toCDBRecordDoesNotExistEx();
    }
    if (obj instanceof String)
        return (String) obj;
    // get node name only
    String name;
    int pos = curl.lastIndexOf('/');
    if (pos == -1)
        name = curl;
    else
        name = curl.substring(pos + 1, curl.length());
    // root
    if (name.length() == 0)
        name = "root";
    return "<?xml version='1.0' encoding='ISO-8859-1'?>" + DOMJavaClassIntrospector.toXML(DOMJavaClassIntrospector.getNodeXMLName(name, obj), obj);
}
Also used : AcsJCDBRecordDoesNotExistEx(alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx)

Example 5 with AcsJCDBRecordDoesNotExistEx

use of alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx in project ACS by ACS-Community.

the class DALRead method main.

public static void main(String[] args) {
    Logger m_logger = ClientLogManager.getAcsLogManager().getLoggerForApplication("DALRead", false);
    try {
        String curl;
        String strIOR = null;
        boolean rawOutput = false;
        if (args.length < 1) {
            System.out.println("Usage: cmd curl [-d ior -raw -h]");
            return;
        }
        curl = args[0];
        // test for IOR in cmd line
        for (int i = 0; i < args.length; i++) {
            if (args[i].equals("-d")) {
                if (i < args.length - 1) {
                    strIOR = args[++i];
                }
            }
            if (args[i].equals("-raw")) {
                rawOutput = true;
            }
            if (args[i].equals("-h")) {
                System.out.println("Usage: cmd curl [-d ior -raw -h]");
                return;
            }
        }
        if (strIOR == null) {
            // use default
            strIOR = "corbaloc::" + InetAddress.getLocalHost().getHostName() + ":" + ACSPorts.getCDBPort() + "/CDB";
        }
        // create and initialize the ORB
        ORB orb = ORB.init(args, null);
        DAL dal = DALHelper.narrow(orb.string_to_object(strIOR));
        String xml = dal.get_DAO(curl);
        if (rawOutput) {
            m_logger.log(AcsLogLevel.INFO, "Curl data:\n" + xml);
            return;
        }
        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser saxParser = factory.newSAXParser();
        XMLHandler xmlSolver = new XMLHandler(false, m_logger);
        saxParser.parse(new InputSource(new StringReader(xml)), xmlSolver);
        if (xmlSolver.m_errorString != null) {
            String info = "XML parser error: " + xmlSolver.m_errorString;
            AcsJCDBXMLErrorEx xmlErr = new AcsJCDBXMLErrorEx();
            System.err.println(info);
            throw xmlErr;
        }
        System.out.println("Env " + System.getProperty("HOMEPATH"));
        // dump contents
        System.out.println("________________________________________________________");
        walk(xmlSolver.m_rootNode);
        System.out.println("________________________________________________________");
    } catch (AcsJCDBXMLErrorEx e) {
        e.printStackTrace();
        e.log(m_logger);
    } catch (CDBXMLErrorEx e) {
        AcsJCDBXMLErrorEx je = AcsJCDBXMLErrorEx.fromCDBXMLErrorEx(e);
        String smsg = "XML Error \tCURL='" + je.getCurl() + "'\n\t\tFilename='" + je.getFilename() + "'\n\t\tNodename='" + je.getNodename() + "'\n\t\tMSG='" + je.getErrorString() + "'";
        je.log(m_logger);
        m_logger.log(AcsLogLevel.NOTICE, smsg, je);
    } catch (CDBRecordDoesNotExistEx e) {
        AcsJCDBRecordDoesNotExistEx je = AcsJCDBRecordDoesNotExistEx.fromCDBRecordDoesNotExistEx(e);
        String smsg = "Record does not exist \tCURL='" + je.getCurl() + "'";
        je.log(m_logger);
        m_logger.log(AcsLogLevel.NOTICE, smsg, je);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : XMLHandler(com.cosylab.cdb.jdal.XMLHandler) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) CDBXMLErrorEx(alma.cdbErrType.CDBXMLErrorEx) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) Logger(java.util.logging.Logger) CDBRecordDoesNotExistEx(alma.cdbErrType.CDBRecordDoesNotExistEx) AcsJCDBRecordDoesNotExistEx(alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx) AcsJCDBRecordDoesNotExistEx(alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx)

Aggregations

AcsJCDBRecordDoesNotExistEx (alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx)11 AcsJCDBXMLErrorEx (alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx)8 AcsJCDBExceptionEx (alma.cdbErrType.wrappers.AcsJCDBExceptionEx)2 DAO (com.cosylab.CDB.DAO)2 DAOPOATie (com.cosylab.CDB.DAOPOATie)2 WDAO (com.cosylab.CDB.WDAO)2 WDAOPOA (com.cosylab.CDB.WDAOPOA)2 WDAOPOATie (com.cosylab.CDB.WDAOPOATie)2 Transaction (org.hibernate.Transaction)2 StopWatch (alma.acs.util.StopWatch)1 CDBFieldIsReadOnlyEx (alma.cdbErrType.CDBFieldIsReadOnlyEx)1 CDBRecordDoesNotExistEx (alma.cdbErrType.CDBRecordDoesNotExistEx)1 CDBXMLErrorEx (alma.cdbErrType.CDBXMLErrorEx)1 WrongCDBDataTypeEx (alma.cdbErrType.WrongCDBDataTypeEx)1 AcsJCDBFieldDoesNotExistEx (alma.cdbErrType.wrappers.AcsJCDBFieldDoesNotExistEx)1 AcsJWrongCDBDataTypeEx (alma.cdbErrType.wrappers.AcsJWrongCDBDataTypeEx)1 DAOOperations (com.cosylab.CDB.DAOOperations)1 DAOPOA (com.cosylab.CDB.DAOPOA)1 XMLHandler (com.cosylab.cdb.jdal.XMLHandler)1 XMLSaver (com.cosylab.cdb.jdal.hibernate.DOMJavaClassIntrospector.XMLSaver)1