private static void fromMap(Map<String, Content> map, SIComposite instance) { for (Map.Entry<String, Content> entry : map.entrySet()) { hydrate(instance.getField(entry.getKey()), entry.getValue()); } }
@Override Optional<SInstance> getFieldLocalOpt(PathReader pathReader) { int fieldIndex = findFieldIndexOpt(pathReader); if (fieldIndex != -1) { return Optional.of(getField(fieldIndex)); } return Optional.empty(); }
private void copyIdValues(SInstance source, SInstance target) { target.setId(source.getId()); if (source instanceof SIComposite) { SIComposite sourceComposite = (SIComposite) source; SIComposite targetComposite = (SIComposite) target; if (sourceComposite.getFields() != null) { for (int i = 0; i < sourceComposite.getFields().size() ; i++) { copyIdValues(sourceComposite.getField(i), targetComposite.getField(i)); } } } else if (source instanceof SIList) { SIList sourceList = (SIList) source; SIList targetList = (SIList) target; if (sourceList.getChildren() != null) { for (int i = 0; i < sourceList.getChildren().size() ; i++) { SInstance sourceItem = (SInstance) sourceList.getChildren().get(i); SInstance targetItem = (SInstance) targetList.getChildren().get(i); copyIdValues(sourceItem, targetItem); } } } }
@Override public STypePdfHealth getType() { return (STypePdfHealth) super.getType(); } }
@Override public List<SInstance> getChildren() { return getFields(); }
final Optional<SIList<SIComposite>> lista = ins.findNearest(demonstrativos); for (int i = 0; i < 5; i++) { final SIComposite siComposite = lista.get().addNew(); siComposite.findNearest(ano).get().setValue(LocalDate.now().getYear() + i); final SIList<SIComposite> receitas_ = siComposite.findNearest(receitas).get(); final SIList<SIComposite> despesas_ = siComposite.findNearest(despesas).get(); TIPOS_RECEITA.stream().forEach(tipo -> receitas_.addNew().setValue("tipo", tipo)); TIPOS_DESPESA.stream().forEach(tipo -> despesas_.addNew().setValue("tipo", tipo));
@Override public List<RelationalSQLCommmand> toSQLScript() { List<RelationalSQLCommmand> lines = new ArrayList<>(); for (SType<?> tableContext : targetTables) { String tableName = table(tableContext); List<Object> params = new ArrayList<>(); Map<String, Object> containerKeyColumns = new HashMap<>(); List<RelationalColumn> inserted = insertedColumns(tableName, containerKeyColumns); SIComposite tableInstance = instance; if (tableContext != tableContext(instance.getType())) { Optional<SInstance> found = instance.getFields().stream() .filter(field -> tableContext == tableContext(field.getType())).findFirst(); if (found.isPresent()) { tableInstance = (SIComposite) found.get(); } } lines.add(new RelationalSQLCommmand( "insert into " + tableName + " (" + concatenateColumnNames(inserted, ", ") + ") values (" + concatenateColumnValues(inserted, ", ", containerKeyColumns, params) + ")", params, tableInstance, inserted)); } return lines; }
private void columnValidation(InstanceValidatable<SIComposite> validatable) { Optional<SIBoolean> databaseFieldInstance = validatable.getInstance().findNearest(foundDataBase); Optional<SIBoolean> hibernateFieldInstance = validatable.getInstance().findNearest(foundHibernate); // Encontrado no hibernate e nao no banco if (hibernateFieldInstance.isPresent() && hibernateFieldInstance.get().getValue() && databaseFieldInstance.isPresent() && !databaseFieldInstance.get().getValue()) { validatable.error("Inconsistency between database and Hibernate!"); } else { // Encontrado no banco e nao no hibernate Optional<SIBoolean> nullableFieldInstance = validatable.getInstance().findNearest(nullable); Optional<SIList<SIString>> listObj = validatable.getInstance().findNearest(userPrivs); List<Object> listPrivs = listObj.map(SIList::getValue).orElse(Collections.emptyList()); List<String> vals = new ArrayList<>(); listPrivs.forEach(obj -> vals.add((String) obj)); if (nullableFieldInstance.isPresent() && !nullableFieldInstance.get().getValue() && (!vals.contains("INSERT") || !vals.contains("UPDATE"))) { validatable.error("Column NOT NULL without SELECT or UPDATE permissions"); } } }
@Override public void fillInstance(SInstance ins, T obj) { if (!(ins instanceof SIComposite)) { throw new SingularFormException("AutoSICompositeConverter somente funciona com instancias compostas."); } final SIComposite cins = (SIComposite) ins; final GetterHandler getterHandler = new Mirror().on(obj).get(); cins.getType().getFields().forEach(f -> cins.setValue(f, getterHandler.field(f.getNameSimple()))); }
private SInstance createField(int fieldIndex) { SType<?> fieldType = getType().getField(fieldIndex); SInstance instance = fieldType.newInstance(getDocument()); if (fields == null) { fields = new FieldMapOfRecordInstance(getType().size()); } fields.set(fieldIndex, instance); instance.setParent(this); return instance; }
@Override final <T> T getValueWithDefaultIfNull(PathReader pathReader, Class<T> resultClass) { SInstance instance = getFieldLocalWithoutCreating(pathReader); if (instance != null) { return instance.getValueWithDefaultIfNull(pathReader.next(), resultClass); } SType<?> tipo = SFormUtil.resolveFieldType(getType(), pathReader); return tipo.getAttributeValueOrDefaultValueIfNull(resultClass); }
/** * property column isolado em outro método para isolar o escopo de * serialização do lambda do appendPropertyColumn */ private void propertyColumnAppender(BSDataTableBuilder<SInstance, ?, ?> builder, IModel<String> labelModel, IModel<String> sTypeNameModel, IFunction<SInstance, String> displayValueFunction) { builder.appendPropertyColumn(labelModel, o -> { SIComposite composto = (SIComposite) o; SType<?> mtipo = composto.getDictionary().getType(sTypeNameModel.getObject()); SInstance instancia = composto.findDescendant(mtipo).get(); return displayValueFunction.apply(instancia); }); }
@Override protected void updateInternal(@Nonnull FormKeyLong key, @Nonnull INSTANCE instance, Integer inclusionActor) { instance.getDocument().persistFiles(); formService.update(instance, inclusionActor); }
private boolean isFlatView(FlatViewContext context, SIComposite instance) { return instance.asAtr().getLabel() == null || context.isWithoutTitle(); }
/** * Find a child by the name ({@link SType#getName()}) * @param parent the parent instance * @param childName the complete name of the child {@link SType#getName()} * @return the chield */ public static Optional<? extends SInstance> findChildByName(@Nonnull SInstance parent, @Nonnull String childName) { if(parent instanceof SIComposite) { SType<?> sType = parent.getDictionary().getType(childName); return ((SIComposite)parent).findDescendant(sType); } return Optional.empty(); }
private static void copyIdValues(SInstance source, SInstance target) { target.setId(source.getId()); if (source instanceof SIComposite) { SIComposite sourceComposite = (SIComposite) source; SIComposite targetComposite = (SIComposite) target; for (int i = 0; i < sourceComposite.getFields().size() ; i++) { copyIdValues(sourceComposite.getField(i), targetComposite.getField(i)); } } else if (source instanceof SIList) { SIList sourceList = (SIList) source; SIList targetList = (SIList) target; if (sourceList.getChildren() != null) { for (int i = 0; i < sourceList.getChildren().size() ; i++) { SInstance sourceItem = (SInstance) sourceList.getChildren().get(i); SInstance targetItem = (SInstance) targetList.getChildren().get(i); copyIdValues(sourceItem, targetItem); } } } }
@Override public T getType() { return (T) super.getType(); } }