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);
}
}
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();
}
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.");
}
}
}
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);
}
}
}
}
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);
}
Aggregations