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

br.com.jarch.apt.generate.GenerateCrud Maven / Gradle / Ivy

The newest version!
package br.com.jarch.apt.generate;

import br.com.jarch.core.annotation.JArchGenerateCrud;
import br.com.jarch.util.DateUtils;
import br.com.jarch.apt.util.ProcessorUtils;

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

public class GenerateCrud {

    private final Element element;

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

    public void generate() {
        JArchGenerateCrud[] generateCruds = element.getAnnotationsByType(JArchGenerateCrud.class);

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

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

                    if (ProcessorUtils.validExistsFieldSearch(element, generateCrud)) {
                        createEntityMasterSubDetail(generateCrud);
                        createSearchMasterSubDetail(generateCrud);
                        createJpqlBuilderMasterSubDetail(generateCrud);
                        createRepositoryMasterSubDetail(generateCrud);
                        createDaoMasterSubDetail(generateCrud);
                        createServiceMasterSubDetail(generateCrud);
                        createObserverMasterSubDetail(generateCrud);
                        createRestMasterSubDetail(generateCrud);
                        createPackageInfoMasterSubDetail(generateCrud);
                        updateBundleMasterSubDetail(generateCrud);

                        boolean createControllers = ProcessorUtils.isExistsEntity(element, generateCrud);
                        if (createControllers) {
                            createControllersMasterSubDetail(generateCrud);
                            createFilterSelectMasterSubDetail(generateCrud);
                            createDataDetailMasterSubDetail(generateCrud);

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

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

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

    private void createEntityMasterSubDetail(JArchGenerateCrud generateCrud) {
        if (generateCrud.entity())
             EntityCodeGenerate.generate(element, generateCrud);
    }

    private void createSearchMasterSubDetail(JArchGenerateCrud generateCrud) {
        if (generateCrud.entity())
            SearchCodeGenerate.generate(element, generateCrud);
    }

    private void createJpqlBuilderMasterSubDetail(JArchGenerateCrud generateCrud) {
        if (generateCrud.entity())
            JpqlBuilderCodeGenerate.generate(element, generateCrud);
    }

    private void createRepositoryMasterSubDetail(JArchGenerateCrud generateCrud) {
        if (generateCrud.repository())
            RepositoryCodeGenerate.generate(element, generateCrud);
    }

    private void createDaoMasterSubDetail(JArchGenerateCrud generateCrud) {
        if (generateCrud.dao())
            DaoCodeGenerate.generate(element, generateCrud);
    }

    private void createServiceMasterSubDetail(JArchGenerateCrud generateCrud) {
        if (generateCrud.service())
            ServiceCodeGenerate.generate(element, generateCrud);
    }

    private void createObserverMasterSubDetail(JArchGenerateCrud generateCrud) {
        if (generateCrud.observer())
            ObserverCodeGenerate.generate(element, generateCrud);
    }

    private void createRestMasterSubDetail(JArchGenerateCrud generateCrud) {
        if (generateCrud.rest())
            RestCodeGenerate.generate(element, generateCrud);
    }

    private void createPackageInfoMasterSubDetail(JArchGenerateCrud generateCrud) {
        if (generateCrud.packageInfo())
            PackageInfoCodeGenerate.generate(element, generateCrud);
    }

    private void updateBundleMasterSubDetail(JArchGenerateCrud generateCrud) {
        if (generateCrud.updateBundle())
            UpdateBundle.update(element, generateCrud);
    }

    private void createControllersMasterSubDetail(JArchGenerateCrud generateCrud) {
        if (generateCrud.controller()) {
            ListControllerCodeGenerate.generate(element, generateCrud);
            DataControllerCodeGenerate.generate(element, generateCrud);
        }
    }

    private void createFilterSelectMasterSubDetail(JArchGenerateCrud generateCrud) {
        if (generateCrud.entity() && generateCrud.controller())
            FilterSelectControllerCodeGenerate.generate(element, generateCrud);
    }

    private void createDataDetailMasterSubDetail(JArchGenerateCrud generateCrud) {
        if (generateCrud.entity() && generateCrud.controller())
            DataDetailCodeGenerate.generate(element, generateCrud);
    }

    private void createXhtmlsMasterSubDetail(JArchGenerateCrud generateCrud) {
        if (generateCrud.xhtml()) {
            ListXhtmlCodeGenerate.generate(element, generateCrud);
            DataXhtmlCodeGenerate.generate(element, generateCrud);
        }
    }

    private void createSystemTest(JArchGenerateCrud generateCrud) {
        if (generateCrud.systemTest())
            SystemTestGenerate.generate(element, generateCrud);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy