Example usage for org.springframework.dao DataAccessException getMessage

List of usage examples for org.springframework.dao DataAccessException getMessage

Introduction

In this page you can find the example usage for org.springframework.dao DataAccessException getMessage.

Prototype

@Override
@Nullable
public String getMessage() 

Source Link

Document

Return the detail message, including the message from the nested exception if there is one.

Usage

From source file:edu.mit.isda.permitservice.dataobjects.HibernateAuthorizationMgr.java

/**
* Select Criteria Qualifiers for which userName is authorized. 
*
* @param userName user's kerberos Id//from  w  ww.  j  a  v a2  s  .  com
* @param functionName funtion name
* @param qualifierType Qualifer Type
* @throws  InvalidInputException if qualifier type code is NULL or if the code is more than 4 characters long
* @throws  ObjectNotFoundException If no Qualifier is found 
* @throws  AuthorizationException  in case of hibernate error   
*/
public String getQualifierXMLForCriteriaQuery(String userName, String functionName, String qualifierType)
        throws InvalidInputException, PermissionException, AuthorizationException {
    if (null == userName || ((null == functionName) && (null == qualifierType)))
        throw new InvalidInputException();

    StringBuffer xmlBuff = new StringBuffer();
    Iterator qIt = null;
    Qualifier xmlqual = null;
    String pname = userName.trim().toUpperCase();
    String fname = "";
    String qtype = "";
    if (null != functionName) {
        fname = functionName.trim().toUpperCase();
    }
    if (null != qualifierType) {
        qtype = qualifierType.trim().toUpperCase();
    }
    // String qtype = "ZLEVELS_" + qualifier_type.trim().toUpperCase();

    total_qualifiers = 0;

    if (pname.length() <= 0 || (fname.length() <= 0 && qtype.length() <= 0))
        throw new InvalidInputException();

    HibernateTemplate t = getHibernateTemplate();
    Collection<Qualifier> quals = null;

    try {
        if (qtype.length() > 0) {
            quals = t.findByNamedQuery("QUALIFIER_ROOT_LIST", new String[] { qtype });

        } else {
            quals = t.findByNamedQuery("QUALIFIER_LIST_FOR_CRITERIA_LIST", new String[] { fname });
        }
        //System.out.println(t.toString());
        t.initialize(quals);
    }

    catch (DataAccessException e) {
        Exception re = (Exception) e.getCause();
        e.printStackTrace();

        SQLException se = null;
        if (re instanceof org.hibernate.exception.SQLGrammarException) {
            se = ((org.hibernate.exception.SQLGrammarException) re).getSQLException();
        } else if (e.getCause() instanceof SQLException) {
            se = (SQLException) e.getCause();
        }
        if (null != se) {
            int i = se.getErrorCode();
            String msg = se.getMessage();
            String errorMessage = se.getMessage() + " Error Code: " + se.getErrorCode();

            int index = msg.indexOf("\n");
            if (index > 0)
                msg = msg.substring(0, index);
            if (i == InvalidInputException.FunctionCategoryInvalidLength
                    || i == InvalidInputException.FunctionNameInvalidLength
                    || i == InvalidInputException.NeedKerberosName
                    || i == InvalidInputException.NeedFunctionCategory
                    || i == InvalidInputException.InvalidFunction
                    || i == InvalidInputException.QualifierTypeInvalidLength)
                throw new InvalidInputException(errorMessage, i);

            else if (i == PermissionException.ProxyNotAuthorized
                    || i == PermissionException.ServerNotAuthorized)
                throw new PermissionException(errorMessage, i);
            else
                throw new AuthorizationException(errorMessage);
        } else
            throw new AuthorizationException(e.getMessage());
    }

    xmlBuff.append("<qualifiers>");

    if (quals == null)
        throw new AuthorizationException("error retrieving qualifiers for user " + userName);

    //Set<PickableQualifier> qualSet = new HashSet<PickableQualifier>(quals);
    //System.out.println(quals.size());
    //System.out.println(qualSet.size());

    //qIt = qualSet.iterator();
    qIt = quals.iterator();

    while (qIt.hasNext()) {
        total_qualifiers++;
        //System.out.println("Total = " + total_qualifiers);
        xmlqual = (Qualifier) qIt.next();
        xmlBuff.append("<qualifier>");
        xmlBuff.append("<qid>");
        xmlBuff.append(xmlqual.getId());
        xmlBuff.append("</qid>");
        xmlBuff.append("<expanded>");
        xmlBuff.append("true");
        xmlBuff.append("</expanded>");
        xmlBuff.append("<qcode>");
        xmlBuff.append(cleanup(xmlqual.getCode(), false));
        xmlBuff.append("</qcode>");
        xmlBuff.append("<qname>");
        xmlBuff.append(cleanup(xmlqual.getName(), false));
        xmlBuff.append("</qname>");
        xmlBuff.append("<hasChild>");
        xmlBuff.append(cleanup(xmlqual.getHasChild().toString(), false));
        xmlBuff.append("</hasChild>");
        // Get children only for non DEPT qualifyers
        if (xmlqual.getHasChild()) {
            xmlBuff.append("<qchildren>");
            xmlBuff.append(getChildrenXML(xmlqual.getId().toString(), 1, 1));
            xmlBuff.append("</qchildren>");
        }
        xmlBuff.append("</qualifier>");
    }

    xmlBuff.append("</qualifiers>");
    //System.out.println("Final Buffer = " + xmlBuff.toString());
    return xmlBuff.toString();
}

From source file:edu.mit.isda.permitservice.dataobjects.HibernateAuthorizationMgr.java

/**
 * Select Qualifiers for which userName is authorized. 
 *
 * @param userName user's kerberos Id/*from  w  w  w  . j  a  v  a2  s .  c  o  m*/
 * @param function_name funtion name
 * @throws  InvalidInputException if qualifier type code is NULL or if the code is more than 4 characters long
 * @throws  ObjectNotFoundException If no Qualifier is found 
 * @throws  AuthorizationException  in case of hibernate error   
 */
public String getQualifierXML(String root_id, Boolean rbool, String qualifier_type)
        throws InvalidInputException, PermissionException, AuthorizationException {
    if (null == root_id)
        throw new InvalidInputException();

    StringBuffer xmlBuff = new StringBuffer();
    Iterator qIt = null;
    QualRoot xmlqual = null;
    String root = root_id.trim().toUpperCase();
    String qtype = "ZLEVELS_" + qualifier_type.trim().toUpperCase();

    total_qualifiers = 0;

    if (root.length() <= 0)
        throw new InvalidInputException();

    HibernateTemplate t1 = getHibernateTemplate();
    Collection<LevelCount> lc = null;

    try {
        lc = t1.findByNamedQuery("GET_LEVEL_FOR_QUAL_TYPE", new String[] { qtype, qtype });
        //System.out.println(t1.toString());
        t1.initialize(lc);
    }

    catch (DataAccessException e) {
        Exception re = (Exception) e.getCause();

        SQLException se = null;
        if (re instanceof org.hibernate.exception.SQLGrammarException) {
            se = ((org.hibernate.exception.SQLGrammarException) re).getSQLException();
        } else if (e.getCause() instanceof SQLException) {
            se = (SQLException) e.getCause();
        }
        if (null != se) {
            int i = se.getErrorCode();
            String msg = se.getMessage();
            String errorMessage = se.getMessage() + " Error Code: " + se.getErrorCode();

            int index = msg.indexOf("\n");
            if (index > 0)
                msg = msg.substring(0, index);
            if (i == InvalidInputException.FunctionCategoryInvalidLength
                    || i == InvalidInputException.FunctionNameInvalidLength
                    || i == InvalidInputException.NeedKerberosName
                    || i == InvalidInputException.NeedFunctionCategory
                    || i == InvalidInputException.InvalidFunction
                    || i == InvalidInputException.QualifierTypeInvalidLength)
                throw new InvalidInputException(errorMessage, i);

            else if (i == PermissionException.ProxyNotAuthorized
                    || i == PermissionException.ServerNotAuthorized)
                throw new PermissionException(errorMessage, i);
            else
                throw new AuthorizationException(errorMessage);
        } else
            throw new AuthorizationException(e.getMessage());
    }

    int val = Integer.parseInt(lc.iterator().next().getValue()) - 1;
    //System.out.println("Level = " + val);

    HibernateTemplate t = getHibernateTemplate();
    Collection<QualRoot> quals = null;
    try {
        quals = t.findByNamedQuery("GET_QUALIFIER_FOR_ROOT", root);
        t.initialize(quals);
    }

    catch (DataAccessException e) {
        Exception re = (Exception) e.getCause();

        SQLException se = null;
        if (re instanceof org.hibernate.exception.SQLGrammarException) {
            se = ((org.hibernate.exception.SQLGrammarException) re).getSQLException();
        } else if (e.getCause() instanceof SQLException) {
            se = (SQLException) e.getCause();
        }
        if (null != se) {
            int i = se.getErrorCode();
            String msg = se.getMessage();
            String errorMessage = se.getMessage() + " Error Code: " + se.getErrorCode();

            int index = msg.indexOf("\n");
            if (index > 0)
                msg = msg.substring(0, index);
            if (i == InvalidInputException.FunctionCategoryInvalidLength
                    || i == InvalidInputException.FunctionNameInvalidLength
                    || i == InvalidInputException.NeedKerberosName
                    || i == InvalidInputException.NeedFunctionCategory
                    || i == InvalidInputException.InvalidFunction
                    || i == InvalidInputException.QualifierTypeInvalidLength)
                throw new InvalidInputException(errorMessage, i);

            else if (i == PermissionException.ProxyNotAuthorized
                    || i == PermissionException.ServerNotAuthorized)
                throw new PermissionException(errorMessage, i);
            else
                throw new AuthorizationException(errorMessage);
        } else
            throw new AuthorizationException(e.getMessage());
    }
    xmlBuff.append("<qualifiers>");

    if (quals == null)
        throw new AuthorizationException("error retrieving root qualifier with id " + root_id);

    qIt = quals.iterator();
    if (rbool.booleanValue()) {
        while (qIt.hasNext()) {
            total_qualifiers++;
            xmlqual = (QualRoot) qIt.next();
            xmlBuff.append("<qualifier>");
            xmlBuff.append("<qid>");
            xmlBuff.append(xmlqual.getId());
            xmlBuff.append("</qid>");
            xmlBuff.append("<expanded>");
            xmlBuff.append("true");
            xmlBuff.append("</expanded>");
            xmlBuff.append("<qcode>");
            xmlBuff.append(cleanup(xmlqual.getCode(), false));
            xmlBuff.append("</qcode>");
            xmlBuff.append("<qname>");
            xmlBuff.append(cleanup(xmlqual.getName(), false));
            xmlBuff.append("</qname>");
            xmlBuff.append("<hasChild>");
            xmlBuff.append(cleanup(xmlqual.getHasChild().toString(), false));
            xmlBuff.append("</hasChild>");
            if (xmlqual.getHasChild() && total_qualifiers < 500) {
                xmlBuff.append("<qchildren>");
                xmlBuff.append(getChildrenXML(xmlqual.getId().toString(), 1, val));
                xmlBuff.append("</qchildren>");
            }
            xmlBuff.append("</qualifier>");
        }
    } else {
        while (qIt.hasNext()) {
            total_qualifiers++;
            xmlqual = (QualRoot) qIt.next();
            if (xmlqual.getHasChild() && total_qualifiers < 500) {
                xmlBuff.append(getChildrenXML(xmlqual.getId().toString(), 1, 1));
            }
        }
    }

    xmlBuff.append("</qualifiers>");
    return xmlBuff.toString();
}

From source file:edu.mit.isda.permitservice.dataobjects.HibernateAuthorizationMgr.java

/**
 * Select categories which username is authorized to view. 
 *
 * @param userName user's kerberos Id/*from  www .  j  ava 2 s. c om*/
 * @throws  InvalidInputException if qualifier type code is NULL or if the code is more than 4 characters long
 * @throws  ObjectNotFoundException If no Qualifier is found 
 * @throws  AuthorizationException  in case of hibernate error   
 */
public Collection<ViewableCategory> getViewableCategory(String userName)
        throws InvalidInputException, PermissionException, AuthorizationException {
    if (null == userName)
        throw new InvalidInputException();

    Iterator vIt = null;
    ViewableCategory cat = null;
    String name = userName.trim().toUpperCase();

    if (name.length() <= 0)
        throw new InvalidInputException();

    HibernateTemplate t = getHibernateTemplate();
    Collection<ViewableCategory> cats = null;
    try {
        cats = t.findByNamedQuery("VIEWABLE_CATEGORY_LIST", name);
        //System.out.println(t.toString());
        t.initialize(cats);
    }

    catch (DataAccessException e) {
        Exception re = (Exception) e.getCause();

        SQLException se = null;
        if (re instanceof org.hibernate.exception.SQLGrammarException) {
            se = ((org.hibernate.exception.SQLGrammarException) re).getSQLException();
        } else if (e.getCause() instanceof SQLException) {
            se = (SQLException) e.getCause();
        }
        if (null != se) {
            int i = se.getErrorCode();
            String msg = se.getMessage();
            String errorMessage = se.getMessage() + " Error Code: " + se.getErrorCode();

            int index = msg.indexOf("\n");
            if (index > 0)
                msg = msg.substring(0, index);
            if (i == InvalidInputException.FunctionCategoryInvalidLength
                    || i == InvalidInputException.FunctionNameInvalidLength
                    || i == InvalidInputException.NeedKerberosName
                    || i == InvalidInputException.NeedFunctionCategory
                    || i == InvalidInputException.InvalidFunction
                    || i == InvalidInputException.QualifierTypeInvalidLength)
                throw new InvalidInputException(errorMessage, i);

            else if (i == PermissionException.ProxyNotAuthorized
                    || i == PermissionException.ServerNotAuthorized)
                throw new PermissionException(errorMessage, i);
            else
                throw new AuthorizationException(errorMessage);
        } else
            throw new AuthorizationException(e.getMessage());
    }

    if (cats == null)
        throw new AuthorizationException("error retrieving viewable categories");

    return cats;
}

From source file:edu.mit.isda.permitservice.dataobjects.HibernateAuthorizationMgr.java

public Collection<ViewableFunction> getViewableFunctionByCategory(String category)
        throws InvalidInputException, PermissionException, AuthorizationException {
    if (null == category)
        throw new InvalidInputException();

    Iterator vIt = null;/*from ww w.j  a  va2s  . c  o m*/
    ViewableFunction func = null;
    String cat = category.trim().toUpperCase();

    if (cat.length() <= 0)
        throw new InvalidInputException();

    HibernateTemplate t = getHibernateTemplate();
    Collection<ViewableFunction> funcs = null;
    try {
        funcs = t.findByNamedQuery("ALL_FUNCTIONS_FOR_CAT", cat);
        t.initialize(funcs);
    }

    catch (DataAccessException e) {
        Exception re = (Exception) e.getCause();

        SQLException se = null;
        if (re instanceof org.hibernate.exception.SQLGrammarException) {
            se = ((org.hibernate.exception.SQLGrammarException) re).getSQLException();
        } else if (e.getCause() instanceof SQLException) {
            se = (SQLException) e.getCause();
        }
        if (null != se) {
            int i = se.getErrorCode();
            String msg = se.getMessage();
            String errorMessage = se.getMessage() + " Error Code: " + se.getErrorCode();

            int index = msg.indexOf("\n");
            if (index > 0)
                msg = msg.substring(0, index);
            if (i == InvalidInputException.FunctionCategoryInvalidLength
                    || i == InvalidInputException.FunctionNameInvalidLength
                    || i == InvalidInputException.NeedKerberosName
                    || i == InvalidInputException.NeedFunctionCategory
                    || i == InvalidInputException.InvalidFunction
                    || i == InvalidInputException.QualifierTypeInvalidLength)
                throw new InvalidInputException(errorMessage, i);

            else if (i == PermissionException.ProxyNotAuthorized
                    || i == PermissionException.ServerNotAuthorized)
                throw new PermissionException(errorMessage, i);
            else
                throw new AuthorizationException(errorMessage);
        } else
            throw new AuthorizationException(e.getMessage());
    }

    if (funcs == null)
        throw new AuthorizationException("error retrieving viewable categories");

    return funcs;
}

From source file:edu.mit.isda.permitservice.dataobjects.HibernateAuthorizationMgr.java

/**
 * retrieve a set of Authorizations by a person's kerberosId, optinally filtering by function_name and function_id
 *
 * @param userName user's kerberos Id/*from ww w .  ja va 2s. c  o m*/
 * @param category Authorization Category code, such as "SAP"
 * @param isActive if you are only interested in authorizations that are currently active, use Boolean.TRUE, otherwise, use Boolean.FALSE
 * @param willExpand if you want to expand the qualifier to get the implicit authorization or not 
 * @param proxyUserName  the user who is executing this query
 * @param function_name a function to filter the results by
 * @param function_id a function id to filter the results by
 * @return a set of {@link Authorization} matching the specified criteria
 * @throws  InvalidInputException   If any of the parameters is NULL
 * @throws  ObjectNotFoundException If no authorizations is found matching the criteria
 * @throws  AuthorizationException  in case of hibernate error   
 */
@SuppressWarnings("unchecked")
public Collection<Authorization> getUserAuthorizations(String userName, String category, String function_name,
        String function_id, Boolean isActive, Boolean willExpand, String applicationName, String proxyUserName)
        throws InvalidInputException, ObjectNotFoundException, PermissionException, AuthorizationException {

    if (userName == null || category == null || isActive == null || willExpand == null
            || applicationName == null || proxyUserName == null)
        throw new InvalidInputException();

    String pname = userName.trim().toUpperCase();
    String categoryCode = category.trim().toUpperCase();
    String aname = applicationName.trim().toUpperCase();
    String pUser = proxyUserName.trim().toUpperCase();
    String fname = null;
    String fid = null;

    if (null != function_name) {
        fname = function_name.trim().toUpperCase();
        if (fname.length() <= 0) {
            fname = null;
        }
    }
    if (null != function_id) {
        fid = function_id.trim().toUpperCase();
        if (fid.length() <= 0) {
            fid = null;
        }
    }

    if (pname.length() <= 0 || aname.length() <= 0 || pUser.length() <= 0)
        throw new InvalidInputException();

    if (categoryCode.length() > 0) {
        while (categoryCode.length() < 4) {
            categoryCode += " ";
        }
    }
    String active = isActive ? "Y" : "N";
    String expand = willExpand ? "Y" : "N";
    HibernateTemplate t = getHibernateTemplate();

    Collection authorizations = null;
    try {
        authorizations = t.findByNamedQuery("GET_USERAUTH_SP",
                new String[] { aname, pUser, pname, categoryCode, expand, active, fname, fid });
        t.initialize(authorizations);
    }

    catch (DataAccessException e) {
        Exception re = (Exception) e.getCause();

        SQLException se = null;
        if (re instanceof org.hibernate.exception.SQLGrammarException) {
            se = ((org.hibernate.exception.SQLGrammarException) re).getSQLException();
        } else if (e.getCause() instanceof SQLException) {
            se = (SQLException) e.getCause();
        }
        if (null != se) {
            int i = se.getErrorCode();
            String msg = se.getMessage();
            String errorMessage = se.getMessage() + " Error Code: " + se.getErrorCode();

            int index = msg.indexOf("\n");
            if (index > 0)
                msg = msg.substring(0, index);
            if (i == InvalidInputException.FunctionCategoryInvalidLength
                    || i == InvalidInputException.FunctionNameInvalidLength
                    || i == InvalidInputException.NeedKerberosName
                    || i == InvalidInputException.NeedFunctionCategory
                    || i == InvalidInputException.InvalidFunction
                    || i == InvalidInputException.QualifierTypeInvalidLength)
                throw new InvalidInputException(errorMessage, i);

            else if (i == PermissionException.ProxyNotAuthorized
                    || i == PermissionException.ServerNotAuthorized)
                throw new PermissionException(errorMessage, i);
            else
                throw new AuthorizationException(errorMessage);
        } else
            throw new AuthorizationException(e.getMessage());
    }

    if (authorizations == null)
        throw new AuthorizationException("error retrieving authorizations for user " + userName);

    return authorizations;
}

From source file:edu.mit.isda.permitservice.dataobjects.HibernateAuthorizationMgr.java

/**
 * retrieves a selection list by certificate username.
 *
 * @param   username/*from  www .  j  a  v a2  s. c  o m*/
 * @param   functionName
 * @param   qualifierCode
 * @return  {@link Category} matching the category code
 * @throws  InvalidInputException   If the category code is NULL or more than 4 characters long
 * @throws  ObjectNotFoundException If no category is found in the database matching the category code
 * @throws  AuthorizationException  in case of hibernate error   
 */
public String getAuthEditPermissions(String userName, String functionName, String qualifierCode)
        throws InvalidInputException, ObjectNotFoundException, AuthorizationException {
    if (null == userName)
        throw new InvalidInputException();

    String name = userName.trim().toUpperCase();

    if (name.length() <= 0)
        throw new InvalidInputException();

    HibernateTemplate t = getHibernateTemplate();
    try {
        List resp = t.findByNamedQuery("CAN_CREATE_AUTH", new String[] { name, functionName, qualifierCode });
        //t.initialize(resp);

        if (null != resp && resp.size() > 0) {
            String s = (String) resp.get(0);
            return s;

        }
    }

    catch (DataAccessException e) {
        Exception re = (Exception) e.getCause();

        SQLException se = null;
        if (re instanceof org.hibernate.exception.SQLGrammarException) {
            se = ((org.hibernate.exception.SQLGrammarException) re).getSQLException();
        } else if (e.getCause() instanceof SQLException) {
            se = (SQLException) e.getCause();
        }
        if (null != se) {
            int i = se.getErrorCode();
            String msg = se.getMessage();
            String errorMessage = se.getMessage() + " Error Code: " + se.getErrorCode();

            int index = msg.indexOf("\n");
            if (index > 0)
                msg = msg.substring(0, index);
            if (i == InvalidInputException.FunctionCategoryInvalidLength
                    || i == InvalidInputException.FunctionNameInvalidLength
                    || i == InvalidInputException.NeedKerberosName
                    || i == InvalidInputException.NeedFunctionCategory
                    || i == InvalidInputException.InvalidFunction
                    || i == InvalidInputException.QualifierTypeInvalidLength)
                throw new InvalidInputException(errorMessage, i);

            else
                throw new AuthorizationException(errorMessage);
        } else
            throw new AuthorizationException(e.getMessage());
    }

    return "N";
}

From source file:gov.nih.nci.ncicb.tcga.dcc.common.dao.UUIDDAOImpl.java

/**
 * Adds an entry in the UUID table in database for the given UUID
 *
 * @param uuidDetailList list of UUIDs to be added to the database
 * @return number of rows affected/*from   www. j av  a2  s  . c  om*/
 */

@Transactional
@Secured({ "ROLE_UUID_CREATOR" })
@Override
public int addUUID(final List<UUIDDetail> uuidDetailList) throws UUIDException {
    String currentUuid = "";
    try {
        for (final UUIDDetail uuidDetail : uuidDetailList) {
            currentUuid = uuidDetail.getUuid();
            jdbcTemplate.update(SQL_UUID_INSERT, currentUuid, uuidDetail.getCreationDate(),
                    uuidDetail.getCenter().getCenterId(), uuidDetail.getGenerationMethod().getMethodNumber(),
                    uuidDetail.getCreatedBy());
        }
    } catch (DataAccessException exception) {
        StringBuilder errorMsg = new StringBuilder("Error while adding following UUIDs to the database : ");
        errorMsg.append(currentUuid);
        errorMsg.append(exception.getMessage());
        throw new UUIDException(errorMsg.toString(), exception);
    }
    return uuidDetailList.size();
}

From source file:gov.nih.nci.ncicb.tcga.dcc.common.dao.UUIDDAOImpl.java

/**
 * Use to add a new barcode_history record in database and sets this barcode_id as the latest barcode for the uuid
 *
 * @param barcode details of the barcode history record to be added in database
 * @throws UUIDException exception thrown while saving data to database
 *//*from  w  w w .jav  a2s  . c  om*/
@Override
public void addBarcode(final Barcode barcode) throws UUIDException {
    final Tumor disease = barcode.getDisease();
    final String itemType = commonBarcodeAndUUIDValidator.getItemType(barcode.getBarcode());
    final Long itemTypeId = uuidTypeQueries.getUUIDTypeID(itemType);
    barcode.setItemTypeId(itemTypeId);

    String existingUUID = getUUIDForBarcode(barcode.getBarcode());
    if (existingUUID != null) {
        if (existingUUID.equals(barcode.getUuid())) {
            // is this UUID already linked to the barcode as the CURRENT barcode for the UUID?  If so, do nothing
            final String latestBarcodeForUUID = getLatestBarcodeForUUID(existingUUID);
            if (latestBarcodeForUUID != null && latestBarcodeForUUID.equals(barcode.getBarcode())) {
                return;
            }
        } else {
            // already linked to a different UUID -- error!
            throw new UUIDException(new StringBuilder().append("Barcode '").append(barcode.getBarcode())
                    .append("' is already associated with UUID '").append(existingUUID)
                    .append("'.  It cannot be associated with the UUID '").append(barcode.getUuid())
                    .append("'.").toString());
        }
    }
    long newId;
    try {
        newId = jdbcTemplate.queryForLong("Select barcode_seq.NEXTVAL from DUAL");
        barcode.setBarcodeId(newId);
        jdbcTemplate.update(SQL_INSERT_BARCODE, newId, barcode.getBarcode(), barcode.getUuid(),
                disease.getTumorId(), barcode.getEffectiveDate(), barcode.getItemTypeId());
    } catch (DataAccessException exception) {
        // this will happen if the UUID is not already in the uuid table 
        final StringBuilder errorMsg = new StringBuilder(
                "Error while adding barcode_history to the database for ");
        errorMsg.append(barcode.getBarcode()).append(": [").append(barcode.getBarcode()).append(",")
                .append(barcode.getUuid()).append(".").append(disease.getTumorId())
                .append(barcode.getEffectiveDate()).append(barcode.getItemTypeId()).append("]")
                .append(exception.getMessage());
        throw new UUIDException(errorMsg.toString(), exception);
    }

    try {
        jdbcTemplate.update(SQL_UPDATE_UUID, newId, barcode.getUuid());
    } catch (DataAccessException exception) {
        final StringBuilder errorMsg = new StringBuilder(
                "Error while updating uuid latest_barcode_id for UUID: ");
        errorMsg.append(barcode.getUuid());
        throw new UUIDException(errorMsg.toString(), exception);
    }
}

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.action.ArchiveDeployer.java

protected Archive doWork(final Archive archive, final QcContext context) throws ProcessorException {
    context.setArchive(archive);//from   w  w w .j  a v a 2 s .  com
    try {
        final String originalDeployLocation = archive.getDeployLocation();
        final Visibility archiveVisibility = visibilityQueries.getVisibilityForArchive(archive);
        final File deployDirectory = getDeployDirectory(archive);
        deployArchiveToDirectory(archive, deployDirectory, false);

        if (Archive.TYPE_MAGE_TAB.equals(archive.getArchiveType()) && !archiveVisibility.isIdentifiable()) {
            archive.setSecondaryDeployLocation(originalDeployLocation);
            deployMageTabToSecondaryLocation(archive, context);
        }

        // Set archive deploy status to Deployed. Once all the archives for the given experiment is deployed then
        // the archive deploy status will be set to Available.
        archive.setDeployStatus(Archive.STATUS_DEPLOYED);
        return archive;

    } catch (DataAccessException e) {
        archive.setDeployStatus(Archive.STATUS_IN_REVIEW);
        throw new ProcessorException("Unexpected error while deploying archive: " + e.getMessage(), e);
    }
}

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.action.MafFileProcessor.java

@Override
protected File doWork(final File mafFile, final QcContext context) throws ProcessorException {
    // make sure the disease is set
    if (context.getArchive() != null) {
        DiseaseContextHolder.setDisease(context.getArchive().getTumorType());
    }// w w w  . j  av a2 s . c  o  m

    FileReader fileReader = null;
    BufferedReader bufferedReader = null;

    try {
        // open file
        fileReader = new FileReader(mafFile);
        bufferedReader = new BufferedReader(fileReader);

        int lineNum = 0;

        // find first non-blank line not starting with #, this is the header
        String headerLine = bufferedReader.readLine();
        lineNum++;
        while (StringUtils.isEmpty(headerLine.trim())
                || StringUtils.startsWith(headerLine, COMMENT_LINE_TOKEN)) {
            headerLine = bufferedReader.readLine();
            lineNum++;
        }

        final List<String> headers = Arrays.asList(headerLine.split("\\t"));

        context.setFile(mafFile);
        final Map<String, Integer> fieldOrder = mapFieldOrder(headers);
        // need to find out the file id for this maf file
        final Long mafFileId = fileInfoQueries.getFileId(mafFile.getName(), context.getArchive().getId());
        if (mafFileId == null || mafFileId == -1) {
            context.getArchive().setDeployStatus(Archive.STATUS_IN_REVIEW);
            throw new ProcessorException(new StringBuilder().append("File '").append(mafFile.getName())
                    .append("' was not found in the database").toString());
        }
        if (isAddMafInfo(mafFileId)) {
            HashMap<String, BCRID> biospecimens = new HashMap<String, BCRID>();
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                lineNum++;
                if (!StringUtils.isBlank(line.trim()) && !StringUtils.startsWith(line, COMMENT_LINE_TOKEN)) {
                    final String[] row = line.split("\\t");

                    try {
                        processRow(row, fieldOrder, mafFileId, biospecimens, context, mafFile, lineNum);
                        //  If exceeds batch size store it in the database
                        if (biospecimens.size() >= getBatchSize()) {
                            try {
                                insertBiospecimenToFileRelationships(biospecimens, context, mafFile);
                            } catch (UUIDException ue) {
                                throw new ProcessorException(ue.getMessage(), ue);
                            }
                            biospecimens.clear();
                        }
                    } catch (DataAccessException e) {
                        // catch DB errors per line
                        context.getArchive().setDeployStatus(Archive.STATUS_IN_REVIEW);
                        context.addError(MessageFormat.format(MessagePropertyType.MAF_FILE_PROCESSING_ERROR,
                                mafFile.getName(),
                                new StringBuilder().append("Mutation information from file at line '")
                                        .append(lineNum).append("' was not successfully added. Root cause: ")
                                        .append(e.getMessage()).toString()));
                    }
                }
            }
            // process remaining biospecimens
            if (biospecimens.size() > 0) {
                try {
                    insertBiospecimenToFileRelationships(biospecimens, context, mafFile);
                } catch (UUIDException ue) {
                    context.getArchive().setDeployStatus(Archive.STATUS_IN_REVIEW);
                    throw new ProcessorException(ue.getMessage(), ue);
                } catch (DataAccessException e) {
                    context.getArchive().setDeployStatus(Archive.STATUS_IN_REVIEW);
                    throw new ProcessorException(e.getMessage(), e);
                }
                biospecimens.clear();
            }
        }
    } catch (IOException e) {
        context.getArchive().setDeployStatus(Archive.STATUS_IN_REVIEW);
        throw new ProcessorException(
                new StringBuilder().append("Error reading maf file ").append(mafFile.getName()).toString());
    } finally {
        if (bufferedReader != null) {
            try {
                bufferedReader.close();
            } catch (IOException e) {
                // ignore
            }
        }

        if (fileReader != null) {
            try {
                fileReader.close();
            } catch (IOException e) {
                // ignore
            }
        }
    }

    return mafFile;
}