Search in sources :

Example 31 with Operation

use of org.wso2.carbon.apimgt.api.doc.model.Operation 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 32 with Operation

use of org.wso2.carbon.apimgt.api.doc.model.Operation 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 33 with Operation

use of org.wso2.carbon.apimgt.api.doc.model.Operation 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 34 with Operation

use of org.wso2.carbon.apimgt.api.doc.model.Operation 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 35 with Operation

use of org.wso2.carbon.apimgt.api.doc.model.Operation in project carbon-business-process by wso2.

the class BaseHistoricVariableInstanceService method addVariables.

protected void addVariables(HistoricVariableInstanceQuery variableInstanceQuery, List<QueryVariable> variables) {
    for (QueryVariable variable : variables) {
        if (variable.getVariableOperation() == null) {
            throw new ActivitiIllegalArgumentException("Variable operation is missing for variable: " + variable.getName());
        }
        if (variable.getValue() == null) {
            throw new ActivitiIllegalArgumentException("Variable value is missing for variable: " + variable.getName());
        }
        boolean nameLess = variable.getName() == null;
        Object actualValue = new RestResponseFactory().getVariableValue(variable);
        // A value-only query is only possible using equals-operator
        if (nameLess) {
            throw new ActivitiIllegalArgumentException("Value-only query (without a variable-name) is not supported");
        }
        switch(variable.getVariableOperation()) {
            case EQUALS:
                variableInstanceQuery.variableValueEquals(variable.getName(), actualValue);
                break;
            default:
                throw new ActivitiIllegalArgumentException("Unsupported variable query operation: " + variable.getVariableOperation());
        }
    }
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) QueryVariable(org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)79 HashMap (java.util.HashMap)55 ArrayList (java.util.ArrayList)43 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)42 Test (org.testng.annotations.Test)34 URITemplate (org.wso2.carbon.apimgt.api.model.URITemplate)29 HttpResponse (org.wso2.carbon.automation.test.utils.http.client.HttpResponse)29 Map (java.util.Map)28 IOException (java.io.IOException)23 API (org.wso2.carbon.apimgt.api.model.API)22 List (java.util.List)20 JSONObject (org.json.simple.JSONObject)20 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)20 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)19 LinkedHashMap (java.util.LinkedHashMap)18 FaultGatewaysException (org.wso2.carbon.apimgt.api.FaultGatewaysException)18 OperationPolicyData (org.wso2.carbon.apimgt.api.model.OperationPolicyData)18 APIInfo (org.wso2.carbon.apimgt.api.model.APIInfo)17 Connection (java.sql.Connection)16 PreparedStatement (java.sql.PreparedStatement)16