use of io.gravitee.repository.management.model.Workflow in project gravitee-management-rest-api by gravitee-io.
the class TaskServiceImpl method getMetadata.
@Override
public Metadata getMetadata(List<TaskEntity> tasks) {
final Metadata metadata = new Metadata();
tasks.forEach(task -> {
final Object data = task.getData();
if (data instanceof SubscriptionEntity) {
final SubscriptionEntity subscription = (SubscriptionEntity) data;
if (!metadata.containsKey(subscription.getApplication())) {
ApplicationEntity applicationEntity = applicationService.findById(subscription.getApplication());
metadata.put(subscription.getApplication(), "name", applicationEntity.getName());
}
if (!metadata.containsKey(subscription.getPlan())) {
PlanEntity planEntity = planService.findById(subscription.getPlan());
String apiId = planEntity.getApi();
ApiEntity api = apiService.findById(apiId);
metadata.put(subscription.getPlan(), "name", planEntity.getName());
metadata.put(subscription.getPlan(), "api", apiId);
metadata.put(apiId, "name", api.getName());
}
} else if (data instanceof Workflow) {
final Workflow workflow = (Workflow) data;
if (API.name().equals(workflow.getReferenceType()) && !metadata.containsKey(workflow.getReferenceId())) {
ApiEntity api = apiService.findById(workflow.getReferenceId());
metadata.put(api.getId(), "name", api.getName());
}
}
});
return metadata;
}
use of io.gravitee.repository.management.model.Workflow in project gravitee-management-rest-api by gravitee-io.
the class TaskServiceImpl method findAll.
@Override
public List<TaskEntity> findAll(String userId) {
if (userId == null) {
throw new UnauthorizedAccessException();
}
try {
// because Tasks only consists on subscriptions, we can optimize the search by only look for apis where
// the user has a SUBSCRIPTION_UPDATE permission
// search for PENDING subscriptions
Set<String> apiIds = getApisForAPermission(userId, SUBSCRIPTION.getName());
final List<TaskEntity> tasks;
if (apiIds.isEmpty()) {
tasks = new ArrayList<>();
} else {
SubscriptionQuery query = new SubscriptionQuery();
query.setStatuses(singleton(PENDING));
query.setApis(apiIds);
tasks = subscriptionService.search(query).stream().map(this::convert).collect(toList());
}
// search for PENDING user registration
final Page<UserEntity> pendingUsers = userService.search(new UserCriteria.Builder().statuses(UserStatus.PENDING).build(), new PageableImpl(1, NUMBER_OF_PENDING_USERS_TO_SEARCH));
if (pendingUsers.getContent() != null && !pendingUsers.getContent().isEmpty()) {
tasks.addAll(pendingUsers.getContent().stream().map(this::convert).collect(toList()));
}
// search for IN_REVIEW apis
apiIds = getApisForAPermission(userId, REVIEWS.getName());
if (!apiIds.isEmpty()) {
apiIds.forEach(apiId -> {
final List<Workflow> workflows = workflowService.findByReferenceAndType(API, apiId, WorkflowType.REVIEW);
if (workflows != null && !workflows.isEmpty()) {
final Workflow currentWorkflow = workflows.get(0);
if (WorkflowState.IN_REVIEW.name().equals(currentWorkflow.getState())) {
tasks.add(convert(currentWorkflow));
}
}
});
}
// search for REQUEST_FOR_CHANGES apis
apiIds = getApisForAPermission(userId, DEFINITION.getName());
if (!apiIds.isEmpty()) {
apiIds.forEach(apiId -> {
final List<Workflow> workflows = workflowService.findByReferenceAndType(API, apiId, WorkflowType.REVIEW);
if (workflows != null && !workflows.isEmpty()) {
final Workflow currentWorkflow = workflows.get(0);
if (WorkflowState.REQUEST_FOR_CHANGES.name().equals(currentWorkflow.getState())) {
tasks.add(convert(currentWorkflow));
}
}
});
}
// search for TO_BE_VALIDATED promotions
tasks.addAll(promotionTasksService.getPromotionTasks(GraviteeContext.getCurrentOrganization()));
return tasks;
} catch (TechnicalException e) {
LOGGER.error("Error retrieving user tasks {}", e.getMessage());
throw new TechnicalManagementException("Error retreiving user tasks", e);
}
}
use of io.gravitee.repository.management.model.Workflow in project gravitee-management-rest-api by gravitee-io.
the class WorkflowServiceImpl method create.
@Override
public Workflow create(final WorkflowReferenceType referenceType, final String referenceId, final WorkflowType type, final String user, final WorkflowState state, final String comment) {
final Workflow workflow = new Workflow();
workflow.setId(UuidString.generateRandom());
workflow.setReferenceType(referenceType.name());
workflow.setReferenceId(referenceId);
workflow.setType(type.name());
workflow.setUser(user);
workflow.setState(state.name());
workflow.setComment(comment);
workflow.setCreatedAt(new Date());
try {
return workflowRepository.create(workflow);
} catch (TechnicalException ex) {
final String message = "An error occurs while trying to create workflow of type " + workflow.getType();
LOGGER.error(message, ex);
throw new TechnicalManagementException(message, ex);
}
}
use of io.gravitee.repository.management.model.Workflow in project gravitee-management-rest-api by gravitee-io.
the class ApiService_UpdateTest method shouldNotChangeLifecycleStateFromCreatedInReview.
@Test
public void shouldNotChangeLifecycleStateFromCreatedInReview() throws TechnicalException {
prepareUpdate();
when(parameterService.findAsBoolean(Key.API_REVIEW_ENABLED, "DEFAULT", ParameterReferenceType.ENVIRONMENT)).thenReturn(true);
final Workflow workflow = new Workflow();
workflow.setState("IN_REVIEW");
when(workflowService.findByReferenceAndType(API, API_ID, REVIEW)).thenReturn(singletonList(workflow));
assertUpdate(ApiLifecycleState.CREATED, CREATED, false);
assertUpdate(ApiLifecycleState.CREATED, PUBLISHED, true);
assertUpdate(ApiLifecycleState.CREATED, UNPUBLISHED, true);
assertUpdate(ApiLifecycleState.CREATED, DEPRECATED, true);
}
use of io.gravitee.repository.management.model.Workflow in project gravitee-management-rest-api by gravitee-io.
the class ApiService_UpdateTest method prepareReviewAuditTest.
private void prepareReviewAuditTest() throws TechnicalException {
when(api.getDefinition()).thenReturn(API_DEFINITION);
when(apiRepository.findById(API_ID)).thenReturn(Optional.of(api));
final MembershipEntity membership = new MembershipEntity();
membership.setMemberId(USER_NAME);
when(membershipService.getPrimaryOwner(MembershipReferenceType.API, API_ID)).thenReturn(membership);
when(userService.findById(USER_NAME)).thenReturn(mock(UserEntity.class));
final Workflow workflow = new Workflow();
workflow.setState(WorkflowState.REQUEST_FOR_CHANGES.name());
when(workflowService.create(any(), any(), any(), any(), any(), any())).thenReturn(workflow);
}
Aggregations