Search in sources :

Example 11 with AttachmentMgtException

use of org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException in project carbon-business-process by wso2.

the class SampleAttachmentMgtClient method getAttachmentInfo.

private static void getAttachmentInfo(String id) throws RemoteException, AttachmentMgtException {
    AttachmentMgtServiceStub stub = new AttachmentMgtServiceStub();
    Options options = new Options();
    options.setTo(new EndpointReference("http://127.0.0.1:9763/services/AttachmentMgtService/"));
    options.setProperty(Constants.Configuration.ENABLE_MTOM, Boolean.TRUE);
    stub._getServiceClient().setOptions(options);
    TAttachment attachment = stub.getAttachmentInfo(id);
    if (log.isDebugEnabled()) {
        log.debug("Attachment details received. Id: " + attachment.getId());
    }
}
Also used : Options(org.apache.axis2.client.Options) TAttachment(org.wso2.carbon.attachment.mgt.stub.types.TAttachment) AttachmentMgtServiceStub(org.wso2.carbon.attachment.mgt.stub.AttachmentMgtServiceStub) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 12 with AttachmentMgtException

use of org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException 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)

Example 13 with AttachmentMgtException

use of org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException in project carbon-business-process by wso2.

the class AttachmentMgtDAOFactoryImpl method removeAttachment.

@Override
public boolean removeAttachment(final String id) throws AttachmentMgtException {
    try {
        boolean isRemoved = false;
        isRemoved = jobExecutor.execTransaction(new Callable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                Query query = entityManager.createQuery("DELETE FROM org.wso2.carbon.attachment.mgt.core.dao.impl" + ".jpa.openjpa.entity.AttachmentDAOImpl x WHERE x.id = " + ":attachmentID");
                query.setParameter("attachmentID", Long.parseLong(id));
                int noOfRowsUpdated = query.executeUpdate();
                // entityManager.remove(getAttachmentInfo(id));
                if (noOfRowsUpdated == 1) {
                    return true;
                } else {
                    return false;
                }
            }
        });
        return isRemoved;
    } catch (Exception e) {
        String errorMsg = "org.wso2.carbon.attachment.mgt.core.dao.impl.jpa.openjpa.AttachmentMgtDAOFactoryImpl.removeAttachment 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) Query(javax.persistence.Query) Callable(java.util.concurrent.Callable) AttachmentMgtException(org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException)

Example 14 with AttachmentMgtException

use of org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException 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 15 with AttachmentMgtException

use of org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException in project carbon-business-process by wso2.

the class SampleAttachmentMgtClient method removeAttachment.

private static void removeAttachment(String id) throws RemoteException, AttachmentMgtException {
    AttachmentMgtServiceStub stub = new AttachmentMgtServiceStub();
    Options options = new Options();
    options.setTo(new EndpointReference("http://127.0.0.1:9763/services/AttachmentMgtService/"));
    options.setProperty(Constants.Configuration.ENABLE_MTOM, Boolean.TRUE);
    stub._getServiceClient().setOptions(options);
    if (log.isDebugEnabled()) {
        log.debug("Attachment removed status:" + stub.remove(id));
    }
}
Also used : Options(org.apache.axis2.client.Options) AttachmentMgtServiceStub(org.wso2.carbon.attachment.mgt.stub.AttachmentMgtServiceStub) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Aggregations

AttachmentMgtException (org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException)11 AttachmentMgtException (org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException)9 TAttachment (org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment)8 AttachmentDAO (org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO)7 DataHandler (javax.activation.DataHandler)4 Query (javax.persistence.Query)4 Attachment (org.wso2.carbon.attachment.mgt.api.attachment.Attachment)4 AttachmentManagerService (org.wso2.carbon.attachment.mgt.core.service.AttachmentManagerService)4 TAttachment (org.wso2.carbon.attachment.mgt.stub.types.TAttachment)4 Calendar (java.util.Calendar)3 EndpointReference (org.apache.axis2.addressing.EndpointReference)3 Options (org.apache.axis2.client.Options)3 AttachmentMgtServiceStub (org.wso2.carbon.attachment.mgt.stub.AttachmentMgtServiceStub)3 List (java.util.List)2 Callable (java.util.concurrent.Callable)2 URI (org.apache.axis2.databinding.types.URI)2 AttachmentDAOImpl (org.wso2.carbon.attachment.mgt.core.dao.impl.jpa.openjpa.entity.AttachmentDAOImpl)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1