public AttributeModel convert()

in log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/converter/AttributeConverter.java [45:87]


    public  AttributeModel convert(Attribute attribute) {
        LOGGER.traceEntry(attribute.getName());
        AttributeModel model;
        if (attribute.getId() != null) {
            model = attributeService.getAttribute(attribute.getId()).orElseGet(AttributeModel::new);
        } else {
            model = new AttributeModel();
        }
        model.setName(attribute.getName());
        model.setAliases(attribute.getAliases());
        model.setDescription(attribute.getDescription());
        model.setDisplayName(attribute.getDisplayName());
        model.setDataType(attribute.getDataType());
        model.setId(attribute.getId());
        model.setCatalogId(attribute.getCatalogId());
        model.setIndexed(attribute.isIndexed());
        model.setRequestContext(attribute.isRequestContext());
        model.setRequired(attribute.isRequired());
        model.setSortable(attribute.isSortable());
        model.setExamples(attribute.getExamples());
        Set<ConstraintModel> constraintModels = model.getConstraints() != null ? model.getConstraints() :
                new HashSet<>();
        Map<Long, ConstraintModel> constraintMap =
            constraintModels.stream().collect(Collectors.toMap(ConstraintModel::getId, Function.identity()));
        if (attribute.getConstraints() != null) {
            constraintModels.removeIf(a -> attribute.getConstraints().stream().noneMatch(b -> b.getId().equals(a.getId())));
            for (Constraint constraint : attribute.getConstraints()) {
                ConstraintModel constraintModel;
                if (constraint.getId() != null) {
                    constraintModel = constraintMap.get(constraint.getId());
                    constraintModel.setConstraintType(constraint.getConstraintType().getName());
                    constraintModel.setValue(constraint.getValue());
                } else {
                    constraintModel = new ConstraintModel();
                    constraintModel.setConstraintType(constraint.getConstraintType().getName());
                    constraintModel.setValue(constraint.getValue());
                    constraintModels.add(constraintModel);
                }
            }
        }
        model.setConstraints(constraintModels);
        return LOGGER.traceExit(model);
    }