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

shz.jdbc.generate.template.DefaultApiClientFallbackTemplate Maven / Gradle / Ivy

There is a newer version: 2024.0.1
Show newest version
package shz.jdbc.generate.template;

import shz.jdbc.generate.FileTemplate;

import java.util.LinkedList;
import java.util.List;

public class DefaultApiClientFallbackTemplate extends FileTemplate {
    @Override
    protected String path() {
        return "api/api-" + info.getModuleName();
    }

    @Override
    public String packageName() {
        return info.getBasePackage() + ".api." + info.getModuleName() + ".factory";
    }

    @Override
    public String className() {
        return info.getTemplates().entityTemplate().className() + "ClientFallbackFactory";
    }

    @Override
    protected List annotations() {
        List annotations = new LinkedList<>();

        annotations.add("@Slf4j");

        imports.add("import lombok.extern.slf4j.Slf4j;");

        return annotations;
    }

    @Override
    protected String classDescription() {
        FileTemplate clientTemplate = info.getTemplates().apiClientTemplate();

        imports.add("import org.springframework.cloud.openfeign.FallbackFactory;");
        imports.add(clientTemplate.getImport());

        return "public class " + className() + " implements FallbackFactory<" + clientTemplate.className() + ">";
    }

    @Override
    protected List content() {
        List content = new LinkedList<>();

        FileTemplate clientTemplate = info.getTemplates().apiClientTemplate();

        content.add("    @Override");
        content.add("    public " + clientTemplate.className() + " create(Throwable cause) {");
        content.add("        return InterfaceProxy.getProxy(" + clientTemplate.className() + ".class, p -> {");
        content.add("            log.error(cause.getMessage(), cause);");
        content.add("            return Response.fail(ServerFailure.GATEWAY_TIMEOUT);");
        content.add("        });");
        content.add("    }");


        imports.add("import shz.core.InterfaceProxy;");
        imports.add("import shz.core.model.Response;");
        imports.add("import shz.core.msg.ServerFailure;");

        return content;
    }

    @Override
    protected boolean disabled() {
        return true;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy