Search in sources :

Example 1 with AttachmentDAO

use of org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO in project carbon-business-process by wso2.

the class AttachmentMgtDAOFactoryImpl method getAttachmentInfoFromURL.

@Override
public AttachmentDAO getAttachmentInfoFromURL(final String attachmentURI) throws AttachmentMgtException {
    try {
        AttachmentDAO resultantDAO = jobExecutor.execTransaction(new Callable<AttachmentDAO>() {

            @Override
            public AttachmentDAO call() throws Exception {
                Query query = entityManager.createQuery("SELECT x FROM org.wso2.carbon.attachment.mgt.core.dao.impl.jpa.openjpa.entity.AttachmentDAOImpl AS x WHERE x.url = :attachmentURI");
                query.setParameter("attachmentURI", attachmentURI);
                List<AttachmentDAO> daoList = query.getResultList();
                if (daoList.isEmpty()) {
                    throw new AttachmentMgtException("Attachment not found for the uri:" + attachmentURI);
                } else if (daoList.size() != 1) {
                    String errorMsg = "There exist more than one attachment for the attachment URI:" + attachmentURI + ". org" + ".wso2.carbon.attachment.mgt.util.URLGeneratorUtil.generateURL method has generated " + "similar uris for different attachments. This has caused a major inconsistency for " + "attachment management.";
                    log.fatal(errorMsg);
                    throw new AttachmentMgtException(errorMsg);
                } else {
                    return daoList.get(0);
                }
            }
        });
        return resultantDAO;
    } catch (Exception e) {
        String errorMsg = "org.wso2.carbon.attachment.mgt.core.dao.impl.hibernate.AttachmentMgtDAOFactoryImpl.getAttachmentInfoFromURL operation failed. " + "Reason: " + e.getLocalizedMessage();
        log.error(errorMsg, e);
        throw new AttachmentMgtException(errorMsg, e);
    }
}
Also used : AttachmentMgtException(org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException) AttachmentDAO(org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO) Query(javax.persistence.Query) List(java.util.List) AttachmentMgtException(org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException)

Example 2 with AttachmentDAO

use of org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO in project carbon-business-process by wso2.

the class AttachmentMgtDAOTransformerFactoryImpl method convertAttachment.

@Override
public AttachmentDAO convertAttachment(Attachment attachment) throws AttachmentMgtException {
    AttachmentDAO attachmentDAO = new AttachmentDAOImpl();
    attachmentDAO.setName(attachment.getName());
    attachmentDAO.setCreatedBy(attachment.getCreatedBy());
    attachmentDAO.setContent(attachment.getContent());
    attachmentDAO.setContentType(attachment.getContentType());
    return attachmentDAO;
}
Also used : AttachmentDAO(org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO) AttachmentDAOImpl(org.wso2.carbon.attachment.mgt.core.dao.impl.jpa.openjpa.entity.AttachmentDAOImpl)

Example 3 with AttachmentDAO

use of org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO in project carbon-business-process by wso2.

the class AttachmentManagerService method getAttachmentInfoFromURL.

/**
 * {@inheritDoc}
 */
@Override
public TAttachment getAttachmentInfoFromURL(final String attachmentURL) throws AttachmentMgtException {
    try {
        // Extracting the attachment uri
        String attachmentUniqueID = attachmentURL.substring(attachmentURL.lastIndexOf("/") + 1);
        AttachmentDAO attachmentDAO = getDaoConnectionFactory().getDAOConnection().getAttachmentMgtDAOFactory().getAttachmentInfoFromURL(attachmentUniqueID);
        Attachment attachment = getDaoTransformFactory().convertAttachment(attachmentDAO);
        return TransformerUtil.convertAttachment(attachment);
    } catch (org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException e) {
        String errorMsg = "org.wso2.carbon.attachment.mgt.core.service.AttachmentManagerService.getAttachmentInfoFromURL operation failed. " + "Reason:" + e.getLocalizedMessage();
        log.error(errorMsg, e);
        throw new AttachmentMgtException(errorMsg, e);
    }
}
Also used : AttachmentMgtException(org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException) AttachmentDAO(org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO) TAttachment(org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment) Attachment(org.wso2.carbon.attachment.mgt.api.attachment.Attachment)

Example 4 with AttachmentDAO

use of org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO in project carbon-business-process by wso2.

the class AttachmentManagerService method getAttachmentInfo.

/**
 * {@inheritDoc}
 */
@Override
public TAttachment getAttachmentInfo(final String id) throws AttachmentMgtException {
    try {
        AttachmentDAO attachmentDAO = getDaoConnectionFactory().getDAOConnection().getAttachmentMgtDAOFactory().getAttachmentInfo(id);
        Attachment attachment = getDaoTransformFactory().convertAttachment(attachmentDAO);
        return TransformerUtil.convertAttachment(attachment);
    } catch (org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException e) {
        String errorMsg = "org.wso2.carbon.attachment.mgt.core.service" + ".AttachmentManagerService.getAttachmentInfo operation failed. " + "Reason:" + e.getLocalizedMessage();
        log.error(errorMsg, e);
        throw new AttachmentMgtException(errorMsg, e);
    }
}
Also used : AttachmentMgtException(org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException) AttachmentDAO(org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO) TAttachment(org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment) Attachment(org.wso2.carbon.attachment.mgt.api.attachment.Attachment)

Example 5 with AttachmentDAO

use of org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO in project carbon-business-process by wso2.

the class AttachmentMgtDAOFactoryImpl method getAttachmentInfoFromURL.

@Override
public AttachmentDAO getAttachmentInfoFromURL(final String attachmentURI) throws AttachmentMgtException {
    try {
        AttachmentDAO resultantDAO = jobExecutor.execTransaction(new Callable<AttachmentDAO>() {

            @Override
            public AttachmentDAO call() throws Exception {
                Query query = entityManager.createQuery("SELECT x FROM org.wso2.carbon.attachment.mgt.core.dao.impl.jpa.openjpa.entity.AttachmentDAOImpl AS x WHERE x.url = :attachmentURI");
                query.setParameter("attachmentURI", attachmentURI);
                List<AttachmentDAO> daoList = query.getResultList();
                if (daoList.isEmpty()) {
                    throw new AttachmentMgtException("Attachment not found for the uri:" + attachmentURI);
                } else if (daoList.size() != 1) {
                    String errorMsg = "There exist more than one attachment for the attachment URI:" + attachmentURI + ". org" + ".wso2.carbon.attachment.mgt.util.URLGeneratorUtil.generateURL method has generated " + "similar uris for different attachments. This has caused a major inconsistency for " + "attachment management.";
                    log.fatal(errorMsg);
                    throw new AttachmentMgtException(errorMsg);
                } else {
                    return daoList.get(0);
                }
            }
        });
        return resultantDAO;
    } catch (Exception e) {
        String errorMsg = "org.wso2.carbon.attachment.mgt.core.dao.impl.jpa.openjpa.AttachmentMgtDAOFactoryImpl.getAttachmentInfoFromURL operation failed. " + "Reason: " + e.getLocalizedMessage();
        log.error(errorMsg, e);
        throw new AttachmentMgtException(errorMsg, e);
    }
}
Also used : AttachmentMgtException(org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException) AttachmentDAO(org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO) Query(javax.persistence.Query) List(java.util.List) AttachmentMgtException(org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException)

Aggregations

AttachmentDAO (org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO)7 AttachmentMgtException (org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException)5 Attachment (org.wso2.carbon.attachment.mgt.api.attachment.Attachment)3 TAttachment (org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment)3 List (java.util.List)2 Query (javax.persistence.Query)2 AttachmentDAOImpl (org.wso2.carbon.attachment.mgt.core.dao.impl.jpa.openjpa.entity.AttachmentDAOImpl)2 AttachmentMgtException (org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException)2 Calendar (java.util.Calendar)1 URI (org.apache.axis2.databinding.types.URI)1 org.wso2.carbon.humantask.client.api.types (org.wso2.carbon.humantask.client.api.types)1 HumanTaskException (org.wso2.carbon.humantask.core.engine.HumanTaskException)1