/** * Return <code>true</code> when this node is a service level. * * @return <code>true</code> when this node is a service level. */ @JsonIgnore public boolean isService() { return getId().split(":").length == 2; }
/** * 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(); } }
private boolean equalsOrParentOf(final Node parent, final Node node) { return node.equals(parent) || node.isRefining() && equalsOrParentOf(parent, node.getRefined()); }
/** * 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; } }
private Snapshotting getSnapshot(final Node node) { return Optional.ofNullable(locator.getResource(node.getId(), Snapshotting.class)) .orElseThrow(() -> new BusinessException("snapshot-no-supported", node.getRefined().getId())); }
/** * 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(); }
/** * Convert a {@link Node} to a {@link Path} inside the given parent directory. * * @param node * The related node. * @param fragments * The computed sibling path (updated). */ private void toFragments(final Node node, List<String> fragments) { if (node.isRefining()) { toFragments(node.getRefined(), fragments); } fragments.add(toFragmentId(node).replace(':', '-')); }
/** * {@link Node} JPA to business object transformer with parameters. * * @param entity * Source entity. * @return The corresponding VO object with resources and without recursive parent reference. */ private static NodeVo toVoParameter(final Node entity) { final NodeVo vo = toVoLight(entity); vo.setParameters(new HashMap<>()); vo.setTag(entity.getTag()); vo.setTagUiClasses(entity.getTagUiClasses()); return vo; }
/** * {@link Node} JPA to VO object transformer without refined information. * * @param entity * Source entity. * @return The corresponding VO object without recursive redefined reference. */ public static NodeVo toVoLight(final Node entity) { final NodeVo vo = new NodeVo(); NamedBean.copy(entity, vo); vo.setMode(entity.getMode()); vo.setUiClasses(entity.getUiClasses()); return vo; }
/** * Check the principal user can subscribe a project to the given visible node. * * @param node * The node identifier to subscribe. * @return The found visible node. Never <code>null</code>. */ private Node checkManagedNodeForSubscription(final String node) { // Check the node can be subscribed by the principal user final Node entity = Optional.ofNullable(nodeRepository.findOneForSubscription(node, securityHelper.getLogin())) .orElseThrow(() -> new ValidationJsonException("node", BusinessException.KEY_UNKNOW_ID, "0", node)); // Check the node accept subscription if (entity.getMode() == SubscriptionMode.NONE) { throw new ValidationJsonException("node", "invalid-mode", "0", node); } return entity; }
/** * Create a new {@link Node}. * * @param vo * The new node definition. */ @POST @CacheRemoveAll(cacheName = "nodes") public void create(final NodeEditionVo vo) { final Node entity = new Node(); // Also check the parent is writable if (vo.isRefining()) { checkWritableNode(vo.getRefined()); } saveOrUpdate(vo, entity); // Create and the new parameters pvResource.create(vo.getParameters(), entity); }
/** * Return all events related to a visible node of given user. * * @param user * The principal user requesting these events. * @return Events related to a visible {@link Node}. */ public List<EventVo> findAll(final String user) { final List<Event> events = repository.findLastEvents(user); final Map<String, EventVo> services = new HashMap<>(); final Map<String, EventVo> tools = new HashMap<>(); for (final Event event : events) { final Node parent = event.getNode().getRefined(); fillParentEvents(tools, parent, EventResource.toVo(event), event.getValue()); fillParentEvents(services, parent.getRefined(), tools.get(parent.getId()), event.getValue()); } return new ArrayList<>(services.values()); }
/** * {@link Node} JPA to business object transformer. * * @param entity * Source entity. * @return The corresponding VO object with recursive redefined reference. */ public static NodeVo toVo(final Node entity) { final NodeVo vo = toVoLight(entity); if (entity.isRefining()) { vo.setRefined(toVo(entity.getRefined())); } return vo; }
/** * Return <code>true</code> when this node is a service level. * * @return <code>true</code> when this node is a service level. */ @JsonIgnore public boolean isTool() { return getId().split(":").length == 3; }
for (final Object[] resultSet : nodesAndValues) { final Node node = (Node) resultSet[0]; final NodeVo vo = nodes.computeIfAbsent(node.getId(), id -> { entities.entrySet().stream().filter(entry -> entry.getValue().isRefining()).forEach(entry -> { final NodeVo parent = nodes.get(entry.getValue().getRefined().getId()); node.setRefined(parent); node.getParameters().putAll(parent.getParameters());
/** * 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; }
/** * Add activities related to a single node. */ private void addUserActivities(final Map<String, Map<String, Activity>> activities, final Node node, final Entry<String, Activity> userActivity) { final String user = userActivity.getKey(); activities.computeIfAbsent(user, k -> new HashMap<>()).put(node.getId(), userActivity.getValue()); }
/** * Check the subscriptions of each subscription related to given node. */ private void checkNodeSubscriptions(final Node node, final Map<String, String> nodeParameters, final Map<Subscription, Map<String, String>> subscriptions) { int counter = 0; for (final Entry<Subscription, Map<String, String>> subscription : subscriptions.entrySet()) { // For each subscription, check status log.info("Check all subscriptions of node {} : {}/{} ...", node.getId(), counter + 1, subscriptions.size()); final Map<String, String> parameters = new HashMap<>(nodeParameters); parameters.putAll(subscription.getValue()); final NodeStatus subscriptionStatus = self.checkSubscriptionStatus(subscription.getKey(), parameters) .getStatus(); eventResource.registerEvent(subscription.getKey(), EventType.STATUS, subscriptionStatus.name()); counter++; } }
/** * 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; }