@Override default SubscriptionRepository getLockedRepository() { return getSubscriptionRepository(); }
@Override default SubscriptionResource getLockedResource() { return getSubscriptionResource(); }
/** * Return all parameters values related to the subscription. The attached project is validated against the current * user to check it is visible. Beware, these parameters must not be returned to user, since clear encrypted * parameters are present. * * @param id * The subscription identifier. * @return all associated parameters values. Key of returned map is the identifier of * {@link org.ligoj.app.model.Parameter} */ @org.springframework.transaction.annotation.Transactional(readOnly = true) public Map<String, String> getParameters(final int id) { checkVisible(id); return getParametersNoCheck(id); }
/** * Convert the subscriptions result set to {@link SubscriptionLightVo} */ private Collection<SubscriptionLightVo> toSubscriptions(final List<Object[]> subscriptions, final Map<Integer, SubscribingProjectVo> projects) { // Prepare the subscriptions container with project name ordering return subscriptions.stream().filter(rs -> projects.containsKey(rs[1])).map(rs -> { // Build the subscription data final SubscriptionLightVo vo = new SubscriptionLightVo(); vo.setId((Integer) rs[0]); vo.setProject((Integer) rs[1]); vo.setNode((String) rs[2]); return vo; }).collect( () -> new TreeSet<>((o1, o2) -> (projects.get(o1.getProject()).getName() + "," + o1.getId()) .compareToIgnoreCase(projects.get(o2.getProject()).getName() + "," + o2.getId())), TreeSet::add, TreeSet::addAll); }
/** * Add a node to the filtered nodes, and also add recursively the parent. */ private void addNodeAsNeeded(final Map<String, SubscribedNodeVo> filteredNodes, final Map<String, NodeVo> allNodes, final NodeVo node) { if (!filteredNodes.containsKey(node.getId())) { // Build the node wrapper final SubscribedNodeVo subscribedNode = new SubscribedNodeVo(); NamedBean.copy(node, subscribedNode); subscribedNode.setTag(node.getTag()); subscribedNode.setTagUiClasses(node.getTagUiClasses()); filteredNodes.put(node.getId(), subscribedNode); // Now check the parent exists or not and add it to the target // filtered nodes if (node.isRefining()) { // Completed the previous link subscribedNode.setRefined(node.getRefined().getId()); // Add the parent too (as needed addNodeAsNeeded(filteredNodes, allNodes, allNodes.get(subscribedNode.getRefined())); } } }
/** * Get fresh status of given subscription. This fresh status is also stored in the data base. The project must be * visible to current user. * * @param id * Node identifier * @return Status of each subscription of given project. */ @Path("status/{id:\\d+}/refresh") @GET public SubscriptionStatusWithData refreshStatus(@PathParam("id") final int id) { return refreshSubscription(checkVisible(id)); }
/** * Check and return the bug tracker configuration attached to the given * subscription. */ private BugTrackerConfiguration getConfigurationBySubscription(final int subscription) { return repository.findByExpected("subscription", subscriptionResource.checkVisible(subscription)); }
/** * Check the parameters that are being attached to this subscription. */ private List<Parameter> checkInputParameters(final SubscriptionEditionVo vo) { final List<Parameter> acceptedParameters = nodeResource.checkInputParameters(vo); // Check all mandatory parameters for the current subscription mode vo.setParameters(ObjectUtils.defaultIfNull(vo.getParameters(), new ArrayList<>())); checkMandatoryParameters(vo.getParameters(), acceptedParameters, vo.getMode()); return acceptedParameters; }
/** * Convert the project result set to {@link SubscribingProjectVo} */ private Map<Integer, SubscribingProjectVo> toProjects(final List<Object[]> projects) { return projects.stream().map(rs -> { // Build the project final SubscribingProjectVo project = new SubscribingProjectVo(); project.setId((Integer) rs[0]); project.setName((String) rs[1]); project.setPkey((String) rs[2]); // Also save it for indexed search return project; }).collect(Collectors.toMap(SubscribingProjectVo::getId, Function.identity())); }
@Override public void link(final int subscription) { final Map<String, String> parameters = subscriptionResource.getParameters(subscription); // Validate the job settings validateGroup(parameters); // There is no additional step since the group is already created in // LDAP }
/** * Extract the distinct nodes from the subscriptions. */ private Map<String, SubscribedNodeVo> toNodes(final Map<String, NodeVo> nodes, final Collection<SubscriptionLightVo> subscriptions) { final Map<String, SubscribedNodeVo> filteredNodes = new TreeMap<>(); // Add the related node of each subscription subscriptions.stream().map(SubscriptionLightVo::getNode).map(nodes::get) .forEach(n -> addNodeAsNeeded(filteredNodes, nodes, n)); return filteredNodes; }
/** * Delete entity and cascaded associations : parameters, events then subscription. Note that remote data are not * deleted. Links are just destroyed. * * @param id * the entity identifier. * @throws Exception * When the delete fails. Managed at JAX-RS level. */ @Path("{id:\\d+}") @DELETE public void delete(@PathParam("id") final int id) throws Exception { // Deletion without remote deletion delete(id, false); }
/** * Return status of the task. * * @param subscription * The locked subscription identifier. * @return status of task. May <code>null</code> when there is no previous task. */ @GET @Path("{subscription:\\d+}/task") default T getTask(@PathParam("subscription") final int subscription) { checkVisible(subscription); return LongTaskRunner.super.getTaskInternal(subscription); }
@Override @GET public VmExecutionStatus getTask(@PathParam("subscription") final int subscription) { final VmExecutionStatus task = LongTaskRunnerSubscription.super.getTask(subscription); if (task != null && completeStatus(task)) { // Save the new state taskRepository.saveAndFlush(task); } return task; }
/** * Check mandatory parameters are provided. * * @param parameters * The updated parameters to check. * @param acceptedParameters * The accepted parameters. * @param mode * The related mode. */ protected void checkMandatoryParameters(final List<ParameterValueCreateVo> parameters, final List<Parameter> acceptedParameters, final SubscriptionMode mode) { // Check each mandatory parameter for the current mode acceptedParameters.stream() .filter(parameter -> (parameter.getMode() == mode || parameter.getMode() == SubscriptionMode.ALL) && parameter.isMandatory()) .forEach(parameter -> checkMandatoryParameter(parameters, parameter)); }
/** * {@link SubscriptionEditionVo} to JPA entity transformer. * * @param vo * The object to convert. * @param project * The related project. * @param node * The related node. * @return The mapped entity. */ public static Subscription toEntity(final SubscriptionEditionVo vo, final Project project, final Node node) { final Subscription entity = new Subscription(); entity.setProject(project); entity.setId(vo.getId()); entity.setNode(node); return entity; }
@Override public boolean isFinished(final VmSnapshotStatus task) { // Complete the status for the not completed tasks if (task.isFailed()) { task.setFinishedRemote(true); } else if (!task.isFinishedRemote()) { getSnapshot(subscriptionResource.checkVisible(task.getLocked().getId()).getNode()) .completeStatus(task); } return task.isFinishedRemote(); }
/** * Return users member of associated subscription. * * @param subscription * The subscription identifier used to get the related group and members. * @return The members of related groups of the subscription. */ public Collection<UserOrg> getMembers(final int subscription) { // Get current subscription parameters final Map<String, String> parameters = subscriptionResource.getParameters(subscription); final String group = parameters.get(IdentityResource.PARAMETER_GROUP); return userResource.findAllNotSecure(null, group); }
/** * Return the version of tool or <code>null</code> if not available/found. * * @param subscription * the subscription's identifier to use to locate the target instance. * @return the version of tool or <code>null</code> if not available/found. * @throws Exception * When version cannot be be retrieved. */ @GET @Path("version/{subscription:\\d+}") public String getVersion(@PathParam("subscription") final int subscription) throws Exception { // Return the version from the subscription parameters return getVersion(subscriptionResource.getParameters(subscription)); }
@Override public void delete(final int subscription, final boolean deleteRemoteData) { if (deleteRemoteData) { // Data are removed from the LDAP final Map<String, String> parameters = subscriptionResource.getParameters(subscription); final String group = parameters.get(IdentityResource.PARAMETER_GROUP); // Check the group exists, but is not required to continue the // process final GroupLdapRepository repository = getGroup(); final GroupOrg groupLdap = repository.findById(group); if (groupLdap != null) { // Perform the deletion repository.delete(groupLdap); } } }