/** * Encontra a posição de um elemento dentro da lista com o ID informado. Retorna -1 senão encontrar. */ private static int findById(Integer instanceId, List<? extends SInstance> list) { for (int i = 0; i < list.size(); i++) { if (instanceId.equals(list.get(i).getId())) { return i; } } return -1; }
private IValidationError errorInternal(ValidationErrorLevel level, String msg) { ValidationError error = new ValidationError(instance.getId(), level, msg); onError.accept(error); errorFound = true; return error; }
/** Localiza a anotação com o classificado solicitado na instancia informatada. Ou retorna null. */ private SIAnnotation getAnnotation(SInstance instance, String classifier) { if (annotationsMap != null) { for (SIAnnotation a : annotationsMap.get(instance.getId())) { if (classifier.equals(a.getClassifier())) { return a; } } } return null; }
private List<SIAnnotation> getAnnotations(SInstance instance) { if (annotationsMap != null && ! annotationsMap.isEmpty()) { return annotationsMap.get(instance.getId()); } return Collections.emptyList(); }
private List<SIAnnotation> getAnnotations(SInstance instance) { if (annotationsMap != null && ! annotationsMap.isEmpty()) { return annotationsMap.get(instance.getId()); } return Collections.emptyList(); }
private ValidationError errorInternal(ValidationErrorLevel level, String msg) { ValidationError error = new ValidationErrorImpl(instance.getId(), level, msg); onError.accept(error); errorFound = true; return error; }
/** Retorna a informação de diff para a instância informada, que deve ser da instância original. */ public DiffInfo getByOriginal(SInstance instance) { return getByOriginal(instance.getId()); }
/** Localiza a anotação com o classificado solicitado na instancia informatada. Ou retorna null. */ private SIAnnotation getAnnotation(SInstance instance, String classifier) { if (annotationsMap != null) { for (SIAnnotation a : annotationsMap.get(instance.getId())) { if (classifier.equals(a.getClassifier())) { return a; } } } return null; }
public Optional<SInstance> findInstanceById(Integer instanceId) { //TODO (by Daniel) otimizar esse método. Faz pesquisa em profundidade e poderia ser indexado. return SInstances.streamDescendants(getRoot(), true) .filter(it -> instanceId.equals(it.getId())) .findAny(); }
public static Stream<Component> streamChildrenByInstance(Component root, SInstance instance) { Predicate<? super Component> sameInstanceFilter = c -> getInstanceIfAware(c.getDefaultModel()) .filter(it -> Objects.equal(it.getName(), instance.getName())) .filter(it -> Objects.equal(it.getId(), instance.getId())) .isPresent(); return streamDescendants(root) .filter(sameInstanceFilter); } private static Optional<SInstance> getInstanceIfAware(IModel<?> model) {
@Override public List<Option> load(ProviderContext<SIFieldRef<SI>> context) { List<? extends SI> list = getOptionsFunction().apply(context.getInstance()); Stream<? extends SI> stream = (list != null) ? list.stream() : Stream.empty(); return stream .map(it -> new SIFieldRef.Option(it.getId(), getDescriptionFunction().apply(it))) .collect(toList()); }
private void updateDocumentErrorsSingle(SInstance instance) { final SDocument document = instance.getDocument(); final Integer id = instance.getId(); final List<ValidationError> errors = contextErrors.get(id); document.setValidationErrors(id, errors); }
/** * Associa a anotação a instância informada de forma a anotação aponte para o ID e XPath do mesmo. */ final void setTarget(SInstance target) { setTargetId(target.getId()); setTargetPath(buildXPath(target, new StringBuilder()).toString()); }
/** * @return True if this SIinstance is an annotated type and if the anotation has any value. */ public boolean hasAnnotation(SInstance instance) { if (annotationsMap != null && ! annotationsMap.isEmpty()) { for( SIAnnotation si : annotationsMap.get(instance.getId())) { if (StringUtils.isNotBlank(si.getText()) || si.getApproved() != null) { return true; } } } return false; }
private static void initSubFieldsIfNeeded(@Nonnull SInstance instance) { if (hasKeepNodePredicatedInAnyChildren(instance.getType())) { //Forces all sub fields in all sub composites to be created just by walking through then SInstances.streamDescendants(instance, true).forEach(si -> si.getId()); } }
/** * Associa a anotação a instância informada de forma a anotação aponte para o ID e XPath do mesmo. */ final void setTarget(SInstance target) { setTargetId(target.getId()); setTargetPath(buildXPath(target, new StringBuilder()).toString()); }
private void assertUniqueIDs(SInstance target, HashMap<Integer, SInstance> usedIds) { Integer id = target.getId(); SInstance old = usedIds.putIfAbsent(id, target); if (old != null) { throw new AssertionError( "Incossitência Interna: Duas instância do mesmo documento estão usando o mesmo ID '" + id + "': '" + target.getPathFull() + "' e '" + old.getPathFull() + "'"); } target.forEachChild(child -> assertUniqueIDs(child, usedIds)); }
@Override public void onComponentTag(Component component, ComponentTag tag) { if (!isInstanceEnabled(component)) tag.put("disabled", "disabled"); SInstance instance = resolveInstance(component); if (instance != null) { tag.put("snglr", "");//identifica como sendo o singular tag.put("data-instance-id", instance.getId()); tag.put("data-instance-path", instance.getPathFull()); } }
@Override public void onComponentTag(Component component, ComponentTag tag) { if (!isInstanceEnabled(component)) tag.put("disabled", "disabled"); SInstance instance = resolveInstance(component); if (instance != null) { tag.put("snglr", "");//identifica como sendo o singular tag.put("data-instance-id", instance.getId()); tag.put("data-instance-path", instance.getPathFull()); } }