Search in sources :

Example 61 with Attachment

use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project carbon-business-process by wso2.

the class TransformerUtils method transformAttachments.

public static TAttachmentInfo[] transformAttachments(List<AttachmentDAO> attachmentList) {
    TAttachmentInfo[] array = new TAttachmentInfo[attachmentList.size()];
    int counter = 0;
    for (AttachmentDAO attachmentDAO : attachmentList) {
        TAttachmentInfo attachmentInfo = new TAttachmentInfo();
        attachmentInfo.setAccessType(attachmentDAO.getAccessType());
        try {
            log.debug("TAttachmentInfo(DTO) has the contentCategory, but the AttachmentDAO(DAO) doesn't support " + "that attribute. Assume default attachment category as mime: " + HumanTaskConstants.ATTACHMENT_CONTENT_CATEGORY_MIME);
            attachmentInfo.setContentCategory(new URI(HumanTaskConstants.ATTACHMENT_CONTENT_CATEGORY_MIME));
        } catch (URI.MalformedURIException e) {
            log.error(e.getLocalizedMessage(), e);
        }
        try {
            String attachmentURI = attachmentDAO.getValue();
            URI attachmentURL = HumanTaskServerHolder.getInstance().getAttachmentService().getAttachmentService().getAttachmentInfoFromURL(attachmentURI).getUrl();
            attachmentInfo.setIdentifier(attachmentURL);
        } catch (AttachmentMgtException e) {
            log.error(e.getLocalizedMessage(), e);
        }
        attachmentInfo.setContentType(attachmentDAO.getContentType());
        Calendar cal = Calendar.getInstance();
        cal.setTime(attachmentDAO.getAttachedAt());
        attachmentInfo.setAttachedTime(cal);
        TUser user = new TUser();
        user.setTUser(attachmentDAO.getAttachedBy().getName());
        attachmentInfo.setAttachedBy(user);
        attachmentInfo.setName(attachmentDAO.getName());
        array[counter] = attachmentInfo;
        counter++;
    }
    return array;
}
Also used : AttachmentMgtException(org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException) Calendar(java.util.Calendar) URI(org.apache.axis2.databinding.types.URI)

Example 62 with Attachment

use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project carbon-business-process by wso2.

the class TransformerUtils method generateAttachmentDAOFromID.

/**
 * Generate an {@code AttachmentDAO} for a given attachment-id
 *
 * @param task task to be associated with the particular attachment
 * @param attachmentID id of the attachment, so this will be used to extract attachment information from the
 * attachment-mgt OSGi service
 *
 * @return reference to the created {@code AttachmentDAO}
 * @throws HumanTaskException If if was failed to retrieve data from the attachment-mgt OSGi service
 */
public static AttachmentDAO generateAttachmentDAOFromID(TaskDAO task, String attachmentID) throws HumanTaskException {
    try {
        org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment attachment = HumanTaskServerHolder.getInstance().getAttachmentService().getAttachmentService().getAttachmentInfo(attachmentID);
        AttachmentDAO dao = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getDaoConnectionFactory().getConnection().createAttachment();
        // Constructing the attachment DAO from the DTO
        dao.setName(attachment.getName());
        dao.setContentType(attachment.getContentType());
        dao.setTask((Task) task);
        String attachmentURL = attachment.getUrl().toString();
        // Extracting the attachment uri
        String attachmentUniqueID = attachmentURL.substring(attachmentURL.lastIndexOf("/") + 1);
        dao.setValue(attachmentUniqueID);
        dao.setAttachedAt(attachment.getCreatedTime().getTime());
        OrganizationalEntityDAO orgEntityDAO = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getDaoConnectionFactory().getConnection().createNewOrgEntityObject(attachment.getCreatedBy(), OrganizationalEntityDAO.OrganizationalEntityType.USER);
        dao.setAttachedBy((OrganizationalEntity) orgEntityDAO);
        // TODO : "AccessType is not supported by Attachment-Mgt DTOs. So using a dummy value: " + HumanTaskConstants.DEFAULT_ATTACHMENT_ACCESS_TYPE);
        dao.setAccessType(HumanTaskConstants.DEFAULT_ATTACHMENT_ACCESS_TYPE);
        return dao;
    } catch (AttachmentMgtException e) {
        String errorMsg = "Attachment Data retrieval operation failed for attachment id:" + attachmentID + ". " + "Reason:";
        log.error(e.getLocalizedMessage(), e);
        throw new HumanTaskException(errorMsg + e.getLocalizedMessage(), e);
    }
}
Also used : AttachmentMgtException(org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException) org.wso2.carbon.humantask.client.api.types(org.wso2.carbon.humantask.client.api.types) HumanTaskException(org.wso2.carbon.humantask.core.engine.HumanTaskException)

Example 63 with Attachment

use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project carbon-business-process by wso2.

the class TransformerUtils method transformTask.

/**
 * Transform a TaskDAO object to a TTaskAbstract object.
 *
 * @param task           : The TaskDAO object to be transformed.
 * @param callerUserName : The user name of the caller.
 * @return : The transformed TTaskAbstract object.
 */
public static TTaskAbstract transformTask(final TaskDAO task, final String callerUserName) {
    TTaskAbstract taskAbstract = new TTaskAbstract();
    // Set the task Id
    try {
        taskAbstract.setId(new URI(task.getId().toString()));
    } catch (URI.MalformedURIException e) {
        log.warn("Invalid task Id found");
    }
    taskAbstract.setName(QName.valueOf(task.getDefinitionName()));
    taskAbstract.setRenderingMethodExists(true);
    // Set the created time
    Calendar calCreatedOn = Calendar.getInstance();
    calCreatedOn.setTime(task.getCreatedOn());
    taskAbstract.setCreatedTime(calCreatedOn);
    if (task.getUpdatedOn() != null) {
        Calendar updatedTime = Calendar.getInstance();
        updatedTime.setTime(task.getUpdatedOn());
        taskAbstract.setUpdatedTime(updatedTime);
    }
    // Set the activation time if exists.
    if (task.getActivationTime() != null) {
        Calendar calActivationTime = Calendar.getInstance();
        calActivationTime.setTime(task.getActivationTime());
        taskAbstract.setActivationTime(calActivationTime);
    }
    // Set the expiration time if exists.
    if (task.getExpirationTime() != null) {
        Calendar expirationTime = Calendar.getInstance();
        expirationTime.setTime(task.getExpirationTime());
        taskAbstract.setExpirationTime(expirationTime);
    }
    if (task.getStartByTime() != null) {
        taskAbstract.setStartByTimeExists(true);
    } else {
        taskAbstract.setStartByTimeExists(false);
    }
    if (task.getCompleteByTime() != null) {
        taskAbstract.setCompleteByTimeExists(true);
    } else {
        taskAbstract.setCompleteByTimeExists(false);
    }
    taskAbstract.setTaskType(task.getType().toString());
    taskAbstract.setHasSubTasks(CommonTaskUtil.hasSubTasks(task));
    taskAbstract.setHasComments(CommonTaskUtil.hasComments(task));
    taskAbstract.setHasAttachments(CommonTaskUtil.hasAttachments(task));
    taskAbstract.setHasFault(CommonTaskUtil.hasFault(task));
    taskAbstract.setHasOutput(CommonTaskUtil.hasOutput(task));
    taskAbstract.setEscalated(task.isEscalated());
    taskAbstract.setIsSkipable(task.isSkipable());
    taskAbstract.setStatus(transformStatus(task.getStatus()));
    taskAbstract.setPriority(transformPriority(task.getPriority()));
    taskAbstract.setPreviousStatus(transformStatus(task.getStatusBeforeSuspension()));
    taskAbstract.setHasPotentialOwners(CommonTaskUtil.hasPotentialOwners(task));
    if (CommonTaskUtil.getUserEntityForRole(task, GenericHumanRoleDAO.GenericHumanRoleType.ACTUAL_OWNER) != null) {
        taskAbstract.setActualOwner(createTUser(CommonTaskUtil.getUserEntityForRole(task, GenericHumanRoleDAO.GenericHumanRoleType.ACTUAL_OWNER)));
    }
    taskAbstract.setPotentialOwners(transformOrganizationalEntityList(CommonTaskUtil.getOrgEntitiesForRole(task, GenericHumanRoleDAO.GenericHumanRoleType.POTENTIAL_OWNERS)));
    taskAbstract.setBusinessAdministrators(transformOrganizationalEntityList(CommonTaskUtil.getOrgEntitiesForRole(task, GenericHumanRoleDAO.GenericHumanRoleType.BUSINESS_ADMINISTRATORS)));
    taskAbstract.setNotificationRecipients(transformOrganizationalEntityList(CommonTaskUtil.getOrgEntitiesForRole(task, GenericHumanRoleDAO.GenericHumanRoleType.NOTIFICATION_RECIPIENTS)));
    taskAbstract.setTaskStakeholders(transformOrganizationalEntityList(CommonTaskUtil.getOrgEntitiesForRole(task, GenericHumanRoleDAO.GenericHumanRoleType.STAKEHOLDERS)));
    taskAbstract.setTaskInitiator(createTUser(CommonTaskUtil.getUserEntityForRole(task, GenericHumanRoleDAO.GenericHumanRoleType.TASK_INITIATOR)));
    HumanTaskBaseConfiguration baseConfiguration = CommonTaskUtil.getTaskConfiguration(task);
    if (baseConfiguration == null) {
        throw new HumanTaskRuntimeException("There's not matching task configuration for " + "task" + task.getName());
    }
    // Set the versioned package name
    taskAbstract.setPackageName(baseConfiguration.getPackageName() + "-" + baseConfiguration.getVersion());
    taskAbstract.setTenantId(task.getTenantId());
    // If this is a task set the response operation and the port type.
    if (TaskType.TASK.equals(task.getType())) {
        TaskConfiguration taskConfig = (TaskConfiguration) baseConfiguration;
        taskAbstract.setResponseOperationName(taskConfig.getResponseOperation());
        taskAbstract.setResponseServiceName(taskConfig.getResponsePortType().toString());
    }
    taskAbstract.setPresentationName(transformPresentationName(CommonTaskUtil.getDefaultPresentationName(task)));
    taskAbstract.setPresentationSubject(transformPresentationSubject(CommonTaskUtil.getDefaultPresentationSubject(task)));
    taskAbstract.setPresentationDescription(transformPresentationDescription(CommonTaskUtil.getDefaultPresentationDescription(task)));
    // Setting attachment specific information
    taskAbstract.setHasAttachments(!task.getAttachments().isEmpty());
    taskAbstract.setNumberOfAttachments(task.getAttachments().size());
    return taskAbstract;
}
Also used : Calendar(java.util.Calendar) TaskConfiguration(org.wso2.carbon.humantask.core.store.TaskConfiguration) HumanTaskBaseConfiguration(org.wso2.carbon.humantask.core.store.HumanTaskBaseConfiguration) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException) URI(org.apache.axis2.databinding.types.URI)

Example 64 with Attachment

use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project kubernetes by ballerinax.

the class KubernetesAnnotationProcessor method processDeployment.

/**
 * Process annotations and create deployment model object.
 *
 * @param attachmentNode annotation attachment node.
 * @return Deployment model object
 */
DeploymentModel processDeployment(AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
    DeploymentModel deploymentModel = new DeploymentModel();
    List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getKeyValuePairs();
    for (BLangRecordLiteral.BLangRecordKeyValue keyValue : keyValues) {
        DeploymentConfiguration deploymentConfiguration = DeploymentConfiguration.valueOf(keyValue.getKey().toString());
        String annotationValue = resolveValue(keyValue.getValue().toString());
        switch(deploymentConfiguration) {
            case name:
                deploymentModel.setName(getValidName(annotationValue));
                break;
            case labels:
                deploymentModel.setLabels(getMap(((BLangRecordLiteral) keyValue.valueExpr).keyValuePairs));
                break;
            case enableLiveness:
                deploymentModel.setEnableLiveness(annotationValue);
                break;
            case livenessPort:
                deploymentModel.setLivenessPort(Integer.parseInt(annotationValue));
                break;
            case initialDelaySeconds:
                deploymentModel.setInitialDelaySeconds(Integer.parseInt(annotationValue));
                break;
            case periodSeconds:
                deploymentModel.setPeriodSeconds(Integer.parseInt(annotationValue));
                break;
            case username:
                deploymentModel.setUsername(annotationValue);
                break;
            case env:
                deploymentModel.setEnv(getMap(((BLangRecordLiteral) keyValue.valueExpr).keyValuePairs));
                break;
            case password:
                deploymentModel.setPassword(annotationValue);
                break;
            case baseImage:
                deploymentModel.setBaseImage(annotationValue);
                break;
            case push:
                deploymentModel.setPush(Boolean.valueOf(annotationValue));
                break;
            case buildImage:
                deploymentModel.setBuildImage(Boolean.valueOf(annotationValue));
                break;
            case image:
                deploymentModel.setImage(annotationValue);
                break;
            case dockerHost:
                deploymentModel.setDockerHost(annotationValue);
                break;
            case dockerCertPath:
                deploymentModel.setDockerCertPath(annotationValue);
                break;
            case imagePullPolicy:
                deploymentModel.setImagePullPolicy(annotationValue);
                break;
            case replicas:
                deploymentModel.setReplicas(Integer.parseInt(annotationValue));
                break;
            default:
                break;
        }
    }
    return deploymentModel;
}
Also used : DeploymentModel(org.ballerinax.kubernetes.models.DeploymentModel) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)

Example 65 with Attachment

use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project kubernetes by ballerinax.

the class KubernetesAnnotationProcessor method processIngressAnnotation.

/**
 * Process annotations and create Ingress model object.
 *
 * @param serviceName    Ballerina service name
 * @param attachmentNode annotation attachment node.
 * @return Ingress model object
 */
IngressModel processIngressAnnotation(String serviceName, AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
    IngressModel ingressModel = new IngressModel();
    List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getKeyValuePairs();
    for (BLangRecordLiteral.BLangRecordKeyValue keyValue : keyValues) {
        IngressConfiguration ingressConfiguration = IngressConfiguration.valueOf(keyValue.getKey().toString());
        String annotationValue = resolveValue(keyValue.getValue().toString());
        switch(ingressConfiguration) {
            case name:
                ingressModel.setName(getValidName(annotationValue));
                break;
            case labels:
                ingressModel.setLabels(getMap(((BLangRecordLiteral) keyValue.valueExpr).keyValuePairs));
                break;
            case path:
                ingressModel.setPath(annotationValue);
                break;
            case targetPath:
                ingressModel.setTargetPath(annotationValue);
                break;
            case hostname:
                ingressModel.setHostname(annotationValue);
                break;
            case ingressClass:
                ingressModel.setIngressClass(annotationValue);
                break;
            case enableTLS:
                ingressModel.setEnableTLS(Boolean.parseBoolean(annotationValue));
                break;
            default:
                break;
        }
    }
    if (ingressModel.getName() == null || ingressModel.getName().length() == 0) {
        ingressModel.setName(getValidName(serviceName) + INGRESS_POSTFIX);
    }
    if (ingressModel.getHostname() == null || ingressModel.getHostname().length() == 0) {
        ingressModel.setHostname(getValidName(serviceName) + INGRESS_HOSTNAME_POSTFIX);
    }
    return ingressModel;
}
Also used : IngressModel(org.ballerinax.kubernetes.models.IngressModel) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)

Aggregations

HashMap (java.util.HashMap)11 AttachmentMgtException (org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException)11 TAttachment (org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment)10 DataHandler (javax.activation.DataHandler)9 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)9 ArrayList (java.util.ArrayList)8 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)8 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)8 File (java.io.File)7 Response (javax.ws.rs.core.Response)7 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)7 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)7 TopLevelNode (org.ballerinalang.model.tree.TopLevelNode)6 AttachmentDAO (org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO)6 BaseTaskService (org.wso2.carbon.bpmn.rest.service.base.BaseTaskService)5 IOException (java.io.IOException)4 List (java.util.List)4 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)4 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)4 Attachment (org.wso2.carbon.attachment.mgt.api.attachment.Attachment)4