use of org.wso2.carbon.bpmn.core.mgt.model.SubstitutesDataModel in project carbon-business-process by wso2.
the class UserSubstitutionUtils method querySubstitutions.
/**
* Query substitution records by given properties.
* Allowed properties: user, substitute, enabled.
* Pagination parameters : start, size, sort, order
* @param propertiesMap
* @return Paginated list of PaginatedSubstitutesDataModel
*/
public static List<SubstitutesDataModel> querySubstitutions(Map<String, String> propertiesMap, int tenantId) {
ActivitiDAO activitiDAO = SubstitutionDataHolder.getInstance().getActivitiDAO();
PaginatedSubstitutesDataModel model = getPaginatedModelFromRequest(propertiesMap, tenantId);
String enabled = propertiesMap.get(SubstitutionQueryProperties.ENABLED);
boolean enabledProvided = false;
if (enabled != null) {
enabledProvided = true;
}
if (!enabledProvided) {
return prepareEndTime(activitiDAO.querySubstituteInfoWithoutEnabled(model));
} else {
return prepareEndTime(activitiDAO.querySubstituteInfo(model));
}
}
use of org.wso2.carbon.bpmn.core.mgt.model.SubstitutesDataModel in project carbon-business-process by wso2.
the class ActivitiDAO method querySubstituteInfo.
/**
* Return the list of substitute info based on query parameters.
* @param model model with only required query parameter values. Leave others as null. By default enabled=false.
* @return List<SubstitutesDataModel> Result set of substitute info
*/
public List<SubstitutesDataModel> querySubstituteInfo(final PaginatedSubstitutesDataModel model) {
final RowBounds rw = new RowBounds(model.getStart(), model.getSize());
CustomSqlExecution<SubstitutesMapper, List<SubstitutesDataModel>> customSqlExecution = new AbstractCustomSqlExecution<SubstitutesMapper, List<SubstitutesDataModel>>(SubstitutesMapper.class) {
public List<SubstitutesDataModel> execute(SubstitutesMapper substitutesMapper) {
return substitutesMapper.querySubstitutes(rw, model);
}
};
return managementService.executeCustomSql(customSqlExecution);
}
use of org.wso2.carbon.bpmn.core.mgt.model.SubstitutesDataModel in project carbon-business-process by wso2.
the class TransitivityResolver method calculateTransitiveSubstitute.
/**
* Recursively look for a available substitute for given data model user. Makes a DB call for each recursive iteration.
* @param substituteDataModel data model that need the transitive sub
* @return available addSubstituteInfo name
*/
private synchronized String calculateTransitiveSubstitute(SubstitutesDataModel substituteDataModel, String originUser, String originSub) {
String newSub = null;
SubstitutesDataModel nextDataModel = subsMap.get(substituteDataModel.getSubstitute());
if (nextDataModel != null) {
if (nextDataModel.getSubstitute().equals(originUser) || nextDataModel.getSubstitute().equals(originSub)) {
// circular dependency, could not resolve
newSub = BPMNConstants.TRANSITIVE_SUB_UNDEFINED;
} else if (BPMNConstants.TRANSITIVE_SUB_NOT_APPLICABLE.equals(nextDataModel.getTransitiveSub())) {
newSub = nextDataModel.getSubstitute();
} else if (nextDataModel.getTransitiveSub() != null) {
newSub = nextDataModel.getTransitiveSub();
} else {
newSub = calculateTransitiveSubstitute(nextDataModel, originUser, originSub);
}
} else {
// original substitute is available
newSub = substituteDataModel.getSubstitute();
}
updateMap(substituteDataModel, newSub);
return newSub;
}
use of org.wso2.carbon.bpmn.core.mgt.model.SubstitutesDataModel in project carbon-business-process by wso2.
the class TransitivityResolver method updateMap.
private void updateMap(SubstitutesDataModel substituteDataModel, String substitute) {
SubstitutesDataModel model = substituteDataModel;
if (substituteDataModel.getSubstitute().equals(substitute)) {
model.setTransitiveSub(BPMNConstants.TRANSITIVE_SUB_NOT_APPLICABLE);
} else {
model.setTransitiveSub(substitute);
}
subsMap.put(substituteDataModel.getUser(), model);
}
use of org.wso2.carbon.bpmn.core.mgt.model.SubstitutesDataModel in project carbon-business-process by wso2.
the class UserSubstitutionService method getSubstitute.
/**
* Return the substitute info for the given user in path parameter
* @param user
* @return SubstituteInfoResponse
* @throws URISyntaxException
*/
@GET
@Path("/{user}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getSubstitute(@PathParam("user") String user) throws UserStoreException {
if (!subsFeatureEnabled) {
return Response.status(405).build();
}
user = getTenantAwareUser(user);
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
String loggedInUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
if (!loggedInUser.equals(user) && !isUserAuthorizedForSubstitute(loggedInUser)) {
throw new BPMNForbiddenException("Not allowed to view others substitution details. No sufficient permission");
}
SubstitutesDataModel model = UserSubstitutionUtils.getSubstituteOfUser(user, tenantId);
if (model != null) {
SubstituteInfoResponse response = new SubstituteInfoResponse();
response.setSubstitute(model.getSubstitute());
response.setAssignee(model.getUser());
response.setEnabled(model.isEnabled());
response.setStartTime(model.getSubstitutionStart());
response.setEndTime(model.getSubstitutionEnd());
return Response.ok(response).build();
} else {
return Response.status(404).build();
}
}
Aggregations