/** * When <code>true</code> the task is really finished. Can be overridden to update the real finished state stored in * database. For sample, a task can be finished from the client side, but not fully executed at the server side. * * @param task * The not <code>null</code> task to evaluate. * @return <code>true</code> when the task is finished. */ default boolean isFinished(final T task) { return task.isFinished(); }
/** * Set the related node's identifier. Alias for name property. * * @param node * The related node. */ public void setNode(final String node) { setName(node); } }
/** * Return the tool instance if is an instance. * * @return The tool instance if is an instance. */ @JsonIgnore public Node getTool() { if (isService()) { return null; } return isInstance() ? getRefined() : this; } }
/** * Write <code>subscription;project;projetKey;projectName;node</code>. * * @param writer * Target output. * @param subscription * Related subscription. */ private void writeCommon(final Writer writer, final Subscription subscription) throws IOException { final Project project = subscription.getProject(); writer.write('\n'); writer.write(String.valueOf(subscription.getId())); writer.write(';'); writer.write(String.valueOf(project.getId())); writer.write(';'); writer.write(project.getPkey()); writer.write(';'); writer.write(project.getName().replaceAll("\"", "'")); writer.write(';'); writer.write(subscription.getNode().getId()); }
/** * Return members of given subscription. */ private Set<UserOrg> getMembersOfSubscription(final Subscription subscription) { final Set<UserOrg> users = new HashSet<>(); final ServicePlugin plugin = servicePluginLocator.getResource(subscription.getNode().getId()); if (plugin instanceof LdapPluginResource) { users.addAll(((LdapPluginResource) plugin).getMembers(subscription.getId())); } return users; }
/** * {@link Event} JPA to VO object transformer without refined information. * * @param entity * Source entity. * @return The corresponding VO object with node/subscription reference. */ public static EventVo toVo(final Event entity) { final EventVo vo = new EventVo(); vo.setValue(entity.getValue()); vo.setType(entity.getType()); if (entity.getNode() == null) { vo.setSubscription(entity.getSubscription().getId()); vo.setNode(NodeResource.toVoLight(entity.getSubscription().getNode())); } else { vo.setNode(NodeResource.toVoLight(entity.getNode())); } return vo; }
/** * Return the last part of the node identifier, excluding the part of the parent. Built like that : * <ul> * <li>node = 'service:id:ldap:ad1', fragment = 'ad1'</li> * <li>node = 'service:id:ldap', fragment = 'ldap'</li> * <li>node = 'service:id', fragment = 'service:id'</li> * </ul> * * @param node * The node to convert to a simple fragment String. * @return The simple fragment. */ private String toFragmentId(final Node node) { return node.isRefining() ? node.getId().substring(node.getRefined().getId().length() + 1) : node.getId(); } }
/** * Check the parameter is related to the given node. * * @param parameter * The parameter to check. * @param node * The node scope the parameter must be related to. */ public void checkOwnership(final Parameter parameter, final Node node) { if (!equalsOrParentOf(parameter.getOwner(), node)) { // This parameter is detached from the node's hierarchy throw new BusinessException("invalid-parameter-node-ownership", "parameter", parameter.getId(), "node", node.getId()); } }
/** * Create the given node parameter values. * * @param values * the parameter values to persist. * @param node * The related node. */ public void create(final List<ParameterValueCreateVo> values, final Node node) { create(values, v -> v.setNode(node)); cacheManager.getCache("node-parameters").evict(node.getId()); }
private boolean equalsOrParentOf(final Node parent, final Node node) { return node.equals(parent) || node.isRefining() && equalsOrParentOf(parent, node.getRefined()); }
/** * Check the parameter value is not used in a subscription when the target value becomes <code>null</code> or empty. * * @param entity * The {@link ParameterValue} entity to check. */ private void checkUnusedValue(final ParameterValue entity) { if (entity.getParameter().isMandatory()) { final int nb = subscriptionRepository.countByParameterValue(entity.getId()); if (nb > 0) { throw new ValidationJsonException(entity.getParameter().getId(), "used-parameter-value", "subscriptions", nb); } } }
/** * Return <code>true</code> when this node is a node/instance level. * * @return <code>true</code> when this node is a node/instance level. */ @JsonIgnore public boolean isInstance() { return getId().split(":").length == 4; }
/** * Check the desired mode is a subset of allowed modes. */ private SubscriptionMode checkMode(final NodeEditionVo vo, final Node entity) { if (entity.isRefining()) { // Check the mode inheritance return checkMode(entity.getRefined().getMode(), vo.getMode()); } return vo.getMode(); }
/** * Create the given subscription parameter values. Value validity is checked. * * @param values * the parameter values to persist. * @param subscription * The related subscription. */ public void create(final List<ParameterValueCreateVo> values, final Subscription subscription) { create(values, v -> v.setSubscription(subscription)); cacheManager.getCache("subscription-parameters").evict(subscription.getId()); }
/** * Find subscriptions where some parameters are defined. * * @param id * node identifier * @return subscriptions with redefined parameters */ protected Map<Subscription, Map<String, String>> findSubscriptionsWithParams(final String id) { final Map<Subscription, Map<String, String>> result = new HashMap<>(); for (final Object[] entityTab : subscriptionRepository.findAllWithValuesByNode(id)) { final ParameterValue value = (ParameterValue) entityTab[1]; result.computeIfAbsent((Subscription) entityTab[0], s -> new HashMap<>()).put(value.getParameter().getId(), value.getData()); } return result; }
/** * Build and return the trigger identifier from the schedule and the * subscription. * * @param schedule * The schedule entity. * @return the {@link String} identifier for the trigger. */ protected static String format(final VmSchedule schedule) { return schedule.getId() + "-" + schedule.getSubscription().getId(); }
protected AbstractContainerLdapRepository(final ContainerType type, final String className) { this.type = type; this.className = className; this.typeName = this.type.name().toLowerCase(Locale.ENGLISH); }
/** * Indicate the current object is refining another object. * * @return <code>true</code> when the current object is refining another object. */ @JsonIgnore @Transient default boolean isRefining() { return getRefined() != null; } }
/** * Check the data constraints and return the associated parameter definition. */ private void checkConstraints(final BasicParameterValueVo vo, final Parameter parameter) { typeToChecker.get(parameter.getType()).accept(vo, parameter); }
/** * Check transition and convert to entity. * * @param vo * new {@link ParameterValueCreateVo} to persist. * @param parameter * The resolved parameter related to the {@link ParameterValue} * @return corresponding entity. */ private ParameterValue createInternal(final ParameterValueCreateVo vo, final Parameter parameter) { return checkSaveOrUpdate(vo, parameter, new ParameterValue()); }