Search in sources :

Example 71 with Server

use of org.wso2.broker.amqp.Server in project charon by wso2.

the class UserResourceManager method create.

/*
     * Returns SCIMResponse based on the sucess or failure of the create user operation
     *
     * @param scimObjectString -raw string containing user info
     * @return usermanager - usermanager instance defined by the external implementor of charon
     */
public SCIMResponse create(String scimObjectString, UserManager userManager, String attributes, String excludeAttributes) {
    JSONEncoder encoder = null;
    try {
        // obtain the json encoder
        encoder = getEncoder();
        // obtain the json decoder
        JSONDecoder decoder = getDecoder();
        // obtain the schema corresponding to user
        // unless configured returns core-user schema or else returns extended user schema)
        SCIMResourceTypeSchema schema = SCIMResourceSchemaManager.getInstance().getUserResourceSchema();
        // decode the SCIM User object, encoded in the submitted payload.
        User user = (User) decoder.decodeResource(scimObjectString, schema, new User());
        // validate the created user.
        ServerSideValidator.validateCreatedSCIMObject(user, schema);
        // get the URIs of required attributes which must be given a value
        Map<String, Boolean> requiredAttributes = ResourceManagerUtil.getOnlyRequiredAttributesURIs((SCIMResourceTypeSchema) CopyUtil.deepCopy(schema), attributes, excludeAttributes);
        User createdUser;
        if (userManager != null) {
            /*handover the SCIM User object to the user usermanager provided by the SP.
            need to send back the newly created user in the response payload*/
            createdUser = userManager.createUser(user, requiredAttributes);
        } else {
            String error = "Provided user manager handler is null.";
            // throw internal server error.
            throw new InternalErrorException(error);
        }
        // encode the newly created SCIM user object and add id attribute to Location header.
        String encodedUser;
        Map<String, String> responseHeaders = new HashMap<String, String>();
        if (createdUser != null) {
            // create a deep copy of the user object since we are going to change it.
            User copiedUser = (User) CopyUtil.deepCopy(createdUser);
            // need to remove password before returning
            ServerSideValidator.validateReturnedAttributes(copiedUser, attributes, excludeAttributes);
            encodedUser = encoder.encodeSCIMObject(copiedUser);
            // add location header
            responseHeaders.put(SCIMConstants.LOCATION_HEADER, getResourceEndpointURL(SCIMConstants.USER_ENDPOINT) + "/" + createdUser.getId());
            responseHeaders.put(SCIMConstants.CONTENT_TYPE_HEADER, SCIMConstants.APPLICATION_JSON);
        } else {
            String error = "Newly created User resource is null.";
            throw new InternalErrorException(error);
        }
        // put the uri of the User object in the response header parameter.
        return new SCIMResponse(ResponseCodeConstants.CODE_CREATED, encodedUser, responseHeaders);
    } catch (CharonException e) {
        // because inside API code throws CharonException.
        if (e.getStatus() == -1) {
            e.setStatus(ResponseCodeConstants.CODE_INTERNAL_ERROR);
        }
        return AbstractResourceManager.encodeSCIMException(e);
    } catch (BadRequestException e) {
        return AbstractResourceManager.encodeSCIMException(e);
    } catch (ConflictException e) {
        return AbstractResourceManager.encodeSCIMException(e);
    } catch (InternalErrorException e) {
        return AbstractResourceManager.encodeSCIMException(e);
    } catch (NotFoundException e) {
        return AbstractResourceManager.encodeSCIMException(e);
    }
}
Also used : User(org.wso2.charon3.core.objects.User) HashMap(java.util.HashMap) ConflictException(org.wso2.charon3.core.exceptions.ConflictException) NotFoundException(org.wso2.charon3.core.exceptions.NotFoundException) InternalErrorException(org.wso2.charon3.core.exceptions.InternalErrorException) JSONDecoder(org.wso2.charon3.core.encoder.JSONDecoder) BadRequestException(org.wso2.charon3.core.exceptions.BadRequestException) JSONEncoder(org.wso2.charon3.core.encoder.JSONEncoder) SCIMResourceTypeSchema(org.wso2.charon3.core.schema.SCIMResourceTypeSchema) CharonException(org.wso2.charon3.core.exceptions.CharonException) SCIMResponse(org.wso2.charon3.core.protocol.SCIMResponse)

Example 72 with Server

use of org.wso2.broker.amqp.Server in project carbon-business-process by wso2.

the class AttachmentMgtDAOBasicOperationsTest method setUp.

@Override
protected void setUp() throws Exception {
    // Setup the MockAttachment-Server
    try {
        ConfigurationContext context = ConfigurationContextFactory.createConfigurationContextFromFileSystem(AXIS2_XML_FILE_PATH, "axis2.xml");
        ConfigurationContextService service = new ConfigurationContextService(context, null);
        AttachmentServerHolder.getInstance().setConfigurationContextService(service);
    } catch (Exception e) {
    }
    server = new MockAttachmentServer();
    attachmentServerHolder = AttachmentServerHolder.getInstance();
    attachmentServerHolder.setAttachmentServer(server);
    server.init();
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) ConfigurationContextService(org.wso2.carbon.utils.ConfigurationContextService) AttachmentMgtException(org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException)

Example 73 with Server

use of org.wso2.broker.amqp.Server in project carbon-business-process by wso2.

the class Database method createActivitiMetaDataTable.

/**
 * during the start up of the server this method will create BPS_BPMN_DEPLOYMENT_METADATA table
 * if it doesn't exist in the activiti database.
 *
 * @throws org.wso2.carbon.bpmn.core.exception.BPMNMetaDataTableCreationException
 */
private void createActivitiMetaDataTable() throws BPMNMetaDataTableCreationException {
    BPMNDatabaseCreator bpmnDatabaseCreator = new BPMNDatabaseCreator(getDataSource());
    String bpmnDeploymentMetaDataQuery = "SELECT * FROM " + BPMNConstants.BPS_BPMN_DEPLOYMENT_METADATA_TABLE;
    if (!bpmnDatabaseCreator.isDatabaseStructureCreated(bpmnDeploymentMetaDataQuery)) {
        try {
            bpmnDatabaseCreator.createRegistryDatabase();
        } catch (Exception e) {
            String errMsg = "Error creating BPS_BPMN_DEPLOYMENT_METADATA table";
            throw new BPMNMetaDataTableCreationException(errMsg, e);
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("BPS_BPMN_DEPLOYMENT_METADATA table already exists. Using the old table.");
        }
    }
}
Also used : BPMNMetaDataTableCreationException(org.wso2.carbon.bpmn.core.exception.BPMNMetaDataTableCreationException) BPMNDatabaseCreator(org.wso2.carbon.bpmn.core.utils.BPMNDatabaseCreator) BPMNMetaDataTableCreationException(org.wso2.carbon.bpmn.core.exception.BPMNMetaDataTableCreationException) DatabaseConfigurationException(org.wso2.carbon.bpmn.core.exception.DatabaseConfigurationException) NamingException(javax.naming.NamingException)

Example 74 with Server

use of org.wso2.broker.amqp.Server in project carbon-business-process by wso2.

the class TenantRepository method deploy.

/**
 * Deploys a BPMN package in the Activiti engine. Each BPMN package has an entry in the registry.
 * Checksum of the latest version of the BPMN package is stored in this entry.
 * This checksum is used to determine whether a package is a new deployment
 * (or a new version of an existing package) or a redeployment of an existing package.
 * We have to ignor the later case. If a package is a new deployment, it is deployed in the Activiti engine.
 *
 * @param deploymentContext DeploymentContext
 * @return true, if artifact was deployed, false, if the artifact has not changed & hence not deployed
 * @throws DeploymentException if deployment fails
 */
// public boolean deploy(BPMNDeploymentContext deploymentContext) throws DeploymentException {
// ZipInputStream archiveStream = null;
// 
// try {
// 
// String deploymentName =
// FilenameUtils.getBaseName(deploymentContext.getBpmnArchive().getName());
// 
// // Compare the checksum of the BPMN archive with the currently available checksum in the registry
// // to determine whether this is a new deployment.
// String checksum = "";
// try {
// checksum = Utils.getMD5Checksum(deploymentContext.getBpmnArchive());
// } catch (IOException e) {
// log.error("Checksum genration failed for IO operation",e);
// } catch (NoSuchAlgorithmException e) {
// log.error("Checksum genration Algorithm not found",e);
// }
// 
// DeploymentMetaDataModel deploymentMetaDataModel =
// activitiDAO.selectTenantAwareDeploymentModel(tenantId.toString(), deploymentName);
// 
// if (log.isDebugEnabled()) {
// log.debug("deploymentName=" + deploymentName + " checksum=" + checksum);
// log.debug("deploymentMetaDataModel=" + deploymentMetaDataModel.toString());
// }
// 
// if (deploymentMetaDataModel != null) {
// if (checksum.equalsIgnoreCase(deploymentMetaDataModel.getCheckSum())) {
// return false;
// }
// }
// 
// ProcessEngineImpl engine =
// (ProcessEngineImpl) BPMNServerHolder.getInstance().getEngine();
// 
// RepositoryService repositoryService = engine.getRepositoryService();
// DeploymentBuilder deploymentBuilder =
// repositoryService.createDeployment().tenantId(tenantId.toString()).
// name(deploymentName);
// try {
// archiveStream =
// new ZipInputStream(new FileInputStream(deploymentContext.getBpmnArchive()));
// } catch (FileNotFoundException e) {
// String errMsg = "Archive stream not found for BPMN repsoitory";
// throw new DeploymentException(errMsg, e);
// }
// 
// deploymentBuilder.addZipInputStream(archiveStream);
// Deployment deployment = deploymentBuilder.deploy();
// 
// if (deploymentMetaDataModel == null) {
// 
// deploymentMetaDataModel = new DeploymentMetaDataModel();
// deploymentMetaDataModel.setPackageName(deploymentName);
// deploymentMetaDataModel.setCheckSum(checksum);
// deploymentMetaDataModel.setTenantID(tenantId.toString());
// deploymentMetaDataModel.setId(deployment.getId());
// 
// //call for insertion
// this.activitiDAO.insertDeploymentMetaDataModel(deploymentMetaDataModel);
// } else {
// //call for update
// deploymentMetaDataModel.setCheckSum(checksum);
// this.activitiDAO.updateDeploymentMetaDataModel(deploymentMetaDataModel);
// }
// 
// } finally {
// if (archiveStream != null) {
// try {
// archiveStream.close();
// } catch (IOException e) {
// log.error("Could not close archive stream", e);
// }
// }
// }
// 
// return true;
// }
public void deploy(BPMNDeploymentContext deploymentContext) throws DeploymentException {
    ZipInputStream archiveStream = null;
    try {
        String deploymentName = FilenameUtils.getBaseName(deploymentContext.getBpmnArchive().getName());
        // Compare the checksum of the BPMN archive with the currently available checksum in the registry to determine whether this is a new deployment.
        String checksum = Utils.getMD5Checksum(deploymentContext.getBpmnArchive());
        RegistryService registryService = BPMNServerHolder.getInstance().getRegistryService();
        Registry tenantRegistry = registryService.getConfigSystemRegistry(tenantId);
        String deploymentRegistryPath = BPMNConstants.BPMN_REGISTRY_PATH + BPMNConstants.REGISTRY_PATH_SEPARATOR + deploymentName;
        Resource deploymentEntry = null;
        if (tenantRegistry.resourceExists(deploymentRegistryPath)) {
            deploymentEntry = tenantRegistry.get(deploymentRegistryPath);
        } else {
            // This is a new deployment
            deploymentEntry = tenantRegistry.newCollection();
        }
        String latestChecksum = deploymentEntry.getProperty(BPMNConstants.LATEST_CHECKSUM_PROPERTY);
        if (latestChecksum != null && checksum.equals(latestChecksum)) {
            // This is a server restart
            return;
        }
        deploymentEntry.setProperty(BPMNConstants.LATEST_CHECKSUM_PROPERTY, checksum);
        // Deploy the package in the Activiti engine
        ProcessEngine engine = BPMNServerHolder.getInstance().getEngine();
        RepositoryService repositoryService = engine.getRepositoryService();
        DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().tenantId(tenantId.toString()).name(deploymentName);
        archiveStream = new ZipInputStream(new FileInputStream(deploymentContext.getBpmnArchive()));
        deploymentBuilder.addZipInputStream(archiveStream);
        deploymentBuilder.deploy();
        tenantRegistry.put(deploymentRegistryPath, deploymentEntry);
    } catch (Exception e) {
        String errorMessage = "Failed to deploy the archive: " + deploymentContext.getBpmnArchive().getName();
        log.error(errorMessage, e);
        // Remove the deployment archive from the tenant's deployment folder
        File deploymentArchive = new File(repoFolder, deploymentContext.getBpmnArchive().getName());
        FileUtils.deleteQuietly(deploymentArchive);
        log.info("Removing the faulty archive : " + deploymentContext.getBpmnArchive().getName());
        throw new DeploymentException(errorMessage, e);
    } finally {
        if (archiveStream != null) {
            try {
                archiveStream.close();
            } catch (IOException e) {
                log.error("Could not close archive stream", e);
            }
        }
    }
}
Also used : Resource(org.wso2.carbon.registry.api.Resource) Registry(org.wso2.carbon.registry.api.Registry) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) RegistryException(org.wso2.carbon.registry.api.RegistryException) DeploymentException(org.apache.axis2.deployment.DeploymentException) IOException(java.io.IOException) ZipInputStream(java.util.zip.ZipInputStream) DeploymentException(org.apache.axis2.deployment.DeploymentException) RegistryService(org.wso2.carbon.registry.api.RegistryService) File(java.io.File) DeploymentBuilder(org.activiti.engine.repository.DeploymentBuilder) ProcessEngine(org.activiti.engine.ProcessEngine) RepositoryService(org.activiti.engine.RepositoryService)

Example 75 with Server

use of org.wso2.broker.amqp.Server in project carbon-business-process by wso2.

the class HumanTaskPackageManagementSkeleton method getTenantTaskStore.

// Returns the task store for the tenant.
private HumanTaskStore getTenantTaskStore() {
    int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    HumanTaskServer server = HumanTaskServiceComponent.getHumanTaskServer();
    return server.getTaskStoreManager().getHumanTaskStore(tenantId);
}
Also used : HumanTaskServer(org.wso2.carbon.humantask.core.HumanTaskServer)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)28 IOException (java.io.IOException)19 ArrayList (java.util.ArrayList)14 HashMap (java.util.HashMap)14 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)10 File (java.io.File)8 JSONObject (org.json.simple.JSONObject)7 MalformedURLException (java.net.MalformedURLException)6 URL (java.net.URL)6 OMElement (org.apache.axiom.om.OMElement)6 JSONObject (org.json.JSONObject)6 URI (java.net.URI)5 URISyntaxException (java.net.URISyntaxException)5 Test (org.testng.annotations.Test)5 KeyManager (org.wso2.carbon.apimgt.api.model.KeyManager)5 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)5 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)5 Connection (java.sql.Connection)4 SQLException (java.sql.SQLException)4 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)4