shz.jdbc.generate.template.DefaultApiClientFallbackTemplate Maven / Gradle / Ivy
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;
}
}