use of io.gravitee.rest.api.model.pagedresult.Metadata in project gravitee-management-rest-api by gravitee-io.
the class MembershipServiceImpl method findUserMembershipMetadata.
@Override
public Metadata findUserMembershipMetadata(List<UserMembership> memberships, MembershipReferenceType type) {
if (memberships == null || memberships.isEmpty() || type == null || (!type.equals(MembershipReferenceType.API) && !type.equals(MembershipReferenceType.APPLICATION) && !type.equals(MembershipReferenceType.GROUP))) {
return new Metadata();
}
try {
Metadata metadata = new Metadata();
if (type.equals(MembershipReferenceType.API)) {
ApiCriteria.Builder criteria = new ApiCriteria.Builder();
ApiFieldExclusionFilter filter = (new ApiFieldExclusionFilter.Builder()).excludeDefinition().excludePicture().build();
criteria.ids(memberships.stream().map(UserMembership::getReference).toArray(String[]::new));
apiRepository.search(criteria.build(), filter).forEach(api -> {
metadata.put(api.getId(), "name", api.getName());
metadata.put(api.getId(), "version", api.getVersion());
metadata.put(api.getId(), "visibility", api.getVisibility());
});
} else if (type.equals(MembershipReferenceType.APPLICATION)) {
applicationRepository.findByIds(memberships.stream().map(UserMembership::getReference).collect(Collectors.toList())).forEach(application -> {
metadata.put(application.getId(), "name", application.getName());
});
}
return metadata;
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to get user membership metadata", ex);
throw new TechnicalManagementException("An error occurs while trying to get user membership metadata", ex);
}
}
use of io.gravitee.rest.api.model.pagedresult.Metadata in project gravitee-management-rest-api by gravitee-io.
the class SubscriptionServiceImpl method getMetadata.
@Override
public Metadata getMetadata(List<SubscriptionEntity> subscriptions) {
Metadata metadata = new Metadata();
subscriptions.forEach(subscription -> {
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());
metadata.put(subscription.getPlan(), "name", planEntity.getName());
}
if (!metadata.containsKey(subscription.getApi())) {
ApiEntity api = apiService.findById(subscription.getApi());
metadata.put(subscription.getApi(), "name", api.getName());
}
});
return metadata;
}
use of io.gravitee.rest.api.model.pagedresult.Metadata 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.rest.api.model.pagedresult.Metadata in project gravitee-management-rest-api by gravitee-io.
the class UserResource method getUserMemberships.
@GET
@Path("/memberships")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "List of memberships the user belongs to", notes = "User must have the ORGANIZATION_USERS[READ] permission to use this service")
@ApiResponses({ @ApiResponse(code = 200, message = "List of user memberships"), @ApiResponse(code = 404, message = "User not found"), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions(@Permission(value = RolePermission.ORGANIZATION_USERS, acls = RolePermissionAction.READ))
public UserMembershipList getUserMemberships(@QueryParam("type") String sType) {
MembershipReferenceType type = null;
if (sType != null) {
type = MembershipReferenceType.valueOf(sType.toUpperCase());
}
List<UserMembership> userMemberships = membershipService.findUserMembership(type, userId);
Metadata metadata = membershipService.findUserMembershipMetadata(userMemberships, type);
UserMembershipList userMembershipList = new UserMembershipList();
userMembershipList.setMemberships(userMemberships);
userMembershipList.setMetadata(metadata.getMetadata());
return userMembershipList;
}
Aggregations