All Downloads are FREE. Search and download functionalities are using the official Maven repository.

br.com.jarch.apt.processor.LogicMasterDetailSubDetail Maven / Gradle / Ivy

There is a newer version: 24.9.0
Show newest version
package br.com.jarch.apt.processor;

import br.com.jarch.annotation.JArchGenerateLogicMasterSubDetail;
import br.com.jarch.apt.generate.*;
import br.com.jarch.util.DateUtils;
import br.com.jarch.util.ProcessorUtils;

import javax.lang.model.element.Element;
import java.time.LocalDateTime;
import java.util.Arrays;

public class LogicMasterDetailSubDetail {

    private final Element element;

    public LogicMasterDetailSubDetail(Element element) {
        this.element = element;
    }

    public void generate() {
        JArchGenerateLogicMasterSubDetail[] generateLogicMasterSubDetails = element.getAnnotationsByType(JArchGenerateLogicMasterSubDetail.class);

        if (generateLogicMasterSubDetails == null || generateLogicMasterSubDetails.length == 0)
            return;

        Arrays
                .stream(generateLogicMasterSubDetails)
                .filter(a -> !a.created())
                .forEach(a -> {
                    ProcessorUtils.messageWarning(DateUtils.formatyyyyMMddHHmmss(LocalDateTime.now()) + ": ### JARCH APT: Analyzing logic " + a.annotationType().getSimpleName() + " ===>>> " + a.master().name() + " ###", element);

                    if (ProcessorUtils.validExistsFieldSearch(element, a.master().fields(), a.master().name())) {
                        boolean createControllers = ProcessorUtils.isExistsEntity(element, a.master().name(), a.nameSubPackage());
                        createEntityMasterSubDetail(a);
                        createSearchMasterSubDetail(a);
                        createJpqlBuilderMasterSubDetail(a);
                        createRepositoryMasterSubDetail(a);
                        createDaoMasterSubDetail(a);
                        createServiceMasterSubDetail(a);
                        createObserverMasterSubDetail(a);
                        createRestMasterSubDetail(a);
                        createPackageInfoMasterSubDetail(a);
                        updateBundleMasterSubDetail(a);

                        if (createControllers) {
                            createControllersMasterSubDetail(a);
                            createFilterSelectMasterSubDetail(a);
                            createDataDetailMasterSubDetail(a);

                            for (int i = 0; i < a.details().length; i++) {
                                DataDetailCodeGenerate.generate(element, a.details()[i].name(), a.nameSubPackage());
                                FilterSelectControllerCodeGenerate.generate(element, a.details()[i].name(), a.nameSubPackage());

                                for (int j = 0; j < a.details()[i].subDetails().length; j++) {
                                    DataDetailCodeGenerate.generate(element, a.details()[i].subDetails()[j].name(), a.nameSubPackage());
                                    FilterSelectControllerCodeGenerate.generate(element, a.details()[i].subDetails()[j].name(), a.nameSubPackage());
                                }
                            }

                            createXhtmlsMasterSubDetail(a);
                            createSystemTest(a);
                        } else {
                            ProcessorUtils.messageNote("3. ATTENTION !!! CONTROLLER'S, XHTML'S AND TEST'S CODE WILL BE CREATED IN NEXT COMPILATION", element);
                        }
                    }
                });
    }

    private void updateBundleMasterSubDetail(JArchGenerateLogicMasterSubDetail a) {
        if (a.updateBundle()) {
            new UpdateBundle(element, a).update();
        }
    }

    private void createPackageInfoMasterSubDetail(JArchGenerateLogicMasterSubDetail a) {
        if (a.packageInfo()) {
            new PackageInfoCodeGenerate(element, a).create();
        }
    }

    private void createXhtmlsMasterSubDetail(JArchGenerateLogicMasterSubDetail a) {
        if (a.xhtml()) {
            new ListXhtmlCodeGenerate(element, a.master().name(), a.nameSubPackage()).create(a.allowInsert(), a.allowClone(), a.allowChange(), a.allowDelete());
            new DataXhtmlCodeGenerate(element, a).create();
        }
    }

    private void createControllersMasterSubDetail(JArchGenerateLogicMasterSubDetail a) {
        if (a.controller()) {
            ListControllerCodeGenerate.generate(element, a.master().name(), a.nameSubPackage());
            new DataControllerCodeGenerate(element, a.master().name(), a.nameSubPackage()).createMasterDetailSubDetail(a);
        }
    }

    private void createObserverMasterSubDetail(JArchGenerateLogicMasterSubDetail a) {
        if (a.observer()) {
            ObserverCodeGenerate.generate(element, a.master().name(), a.nameSubPackage());
        }
    }

    private void createServiceMasterSubDetail(JArchGenerateLogicMasterSubDetail a) {
        if (a.service()) {
            ServiceCodeGenerate.generate(element, a.master().name(), a.nameSubPackage());
        }
    }

    private void createRestMasterSubDetail(JArchGenerateLogicMasterSubDetail a) {
        if (a.rest()) {
            RestCodeGenerate.generate(element, a.master().name(), a.nameSubPackage());
        }
    }

    private void createRepositoryMasterSubDetail(JArchGenerateLogicMasterSubDetail a) {
        if (a.repository()) {
            RepositoryCodeGenerate.generate(element, a.master().name(), a.nameSubPackage());
        }
    }

    private void createDaoMasterSubDetail(JArchGenerateLogicMasterSubDetail a) {
        if (a.dao()) {
            DaoCodeGenerate.generate(element, a.master().name(), a.nameSubPackage());
        }
    }

    private void createEntityMasterSubDetail(JArchGenerateLogicMasterSubDetail a) {
        if (a.entity()) {
            new EntityCodeGenerate(element, a).create();
        }
    }

    private void createSystemTest(JArchGenerateLogicMasterSubDetail a) {
        if (a.systemTest()) {
            new SystemTestGenerate(element, a).create();
        }
    }

    private void createSearchMasterSubDetail(JArchGenerateLogicMasterSubDetail a) {
        if (a.entity()) {
            SearchCodeGenerate.generate(element, a.master().name(), a.nameSubPackage());
        }
    }

    private void createDataDetailMasterSubDetail(JArchGenerateLogicMasterSubDetail a) {
        if (a.entity()) {
            DataDetailCodeGenerate.generate(element, a.master().name(), a.nameSubPackage());
        }
    }

    private void createFilterSelectMasterSubDetail(JArchGenerateLogicMasterSubDetail a) {
        if (a.entity()) {
            FilterSelectControllerCodeGenerate.generate(element, a.master().name(), a.nameSubPackage());
        }
    }

    private void createJpqlBuilderMasterSubDetail(JArchGenerateLogicMasterSubDetail a) {
        if (a.entity()) {
            JpqlBuilderCodeGenerate.generate(element, a.master().name(), a.nameSubPackage());
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy