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

br.com.jarch.apt.processor.LogicMasterDetail 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.JArchGenerateLogicMasterDetail;
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 LogicMasterDetail {

    private final Element element;

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

    public void generate() {
        generateMasterDetail();
    }

    private void generateMasterDetail() {
        JArchGenerateLogicMasterDetail[] generateLogicMasterDetails = element.getAnnotationsByType(JArchGenerateLogicMasterDetail.class);

        if (generateLogicMasterDetails != null && generateLogicMasterDetails.length > 0) {
            Arrays
                    .stream(generateLogicMasterDetails)
                    .filter(a -> !a.created())
                    .forEach(a -> {
                        ProcessorUtils.messageNote(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());
                            createEntitysMasterDetail(a);
                            createSearchMasterDetail(a);
                            createJpqlBuilderMasterDetail(a);
                            createRepositoryMasterDetail(a);
                            createDaoMasterDetail(a);
                            createServiceMasterDetail(a);
                            createObserverMasterDetail(a);
                            createRestMasterDetail(a);
                            createPackageInfoMasterDetail(a);
                            updateBundleMasterDetail(a);
                            if (createControllers) {
                                createControllersMasterDetail(a);
                                createDataDetailMasterDetail(a);
                                createFilterSelectMasterDetail(a);

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

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

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

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

    private void createXhtmlsMasterDetail(JArchGenerateLogicMasterDetail 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 createControllersMasterDetail(JArchGenerateLogicMasterDetail a) {
        if (a.controller()) {
            ListControllerCodeGenerate.generate(element, a.master().name(), a.nameSubPackage());
            new DataControllerCodeGenerate(element, a.master().name(), a.nameSubPackage()).createMasterDetail(a);
        }
    }

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

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

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

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

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

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

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

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

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

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

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

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy