commit b21283f295d7cdef1f6e2efa8ea245e4c3927469 Author: albino.servin <121980479+Decano989@users.noreply.github.com> Date: Mon Oct 6 22:51:14 2025 -0300 test adapter diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae21355 --- /dev/null +++ b/.gitignore @@ -0,0 +1,36 @@ +# ---> Maven +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +# https://github.com/takari/maven-wrapper#usage-without-binary-jar +.mvn/wrapper/maven-wrapper.jar + +# Eclipse m2e generated files +# Eclipse Core +.project +# JDT-specific (Eclipse Java Development Tools) +.classpath + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +# ---> NetBeans +**/nbproject/private/ +**/nbproject/Makefile-*.mk +**/nbproject/Package-*.bash +nb-configuration.xml + +build/ +nbbuild/ +dist/ +nbdist/ +.nb-gradle/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..7e3163e --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# iqr-server-gen + diff --git a/nbactions.xml b/nbactions.xml new file mode 100644 index 0000000..9d6937c --- /dev/null +++ b/nbactions.xml @@ -0,0 +1,55 @@ + + + + run + + jar + + + process-classes + org.codehaus.mojo:exec-maven-plugin:3.1.0:exec + + + + ${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs} + + io.kumare.iqr.IqrApplication + java + + + + debug + + jar + + + process-classes + org.codehaus.mojo:exec-maven-plugin:3.1.0:exec + + + -agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address} + ${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs} + + io.kumare.iqr.IqrApplication + java + true + + + + profile + + jar + + + process-classes + org.codehaus.mojo:exec-maven-plugin:3.1.0:exec + + + + ${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs} + io.kumare.iqr.IqrApplication + java + + + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..2fe6ae4 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 3.5.0 + + + + + io.kumare.time + time-server + 0.0.1-SNAPSHOT + Kumare Time Server + time + + + + + + + + + + + + + + + + + + + + 22 + + + + + + + io.kumare + kumare-base-server-spring + 0.0.1-SNAPSHOT + + + + io.kumare + kumare-adapter-spring-oauthlib + 0.0.1-SNAPSHOT + + + + io.kumare + kumare-adapter-spring-visma-time + 0.0.1-SNAPSHOT + + + + com.fasterxml.jackson.datatype + jackson-datatype-hibernate6 + + + + + org.springframework.security + spring-security-core + + + + + org.springframework.boot + spring-boot-starter-web + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.postgresql + postgresql + runtime + + + + + org.springframework.boot + spring-boot-starter-security + + + + org.springframework.boot + spring-boot-starter-oauth2-client + + + org.springframework.boot + spring-boot-starter-oauth2-resource-server + + + + + com.google.code.gson + gson + + + + + org.springdoc + springdoc-openapi-starter-webmvc-ui + 2.8.13 + + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + + diff --git a/src/main/java/io/kumare/iqr/IqrApplication.java b/src/main/java/io/kumare/iqr/IqrApplication.java new file mode 100644 index 0000000..92b8e32 --- /dev/null +++ b/src/main/java/io/kumare/iqr/IqrApplication.java @@ -0,0 +1,32 @@ +/* + * + */ +package io.kumare.iqr; + +// spring +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.data.web.config.EnableSpringDataWebSupport; +// app +import io.kumare.iqr.app.App; + +/** + * + * @author afatecha + */ +@SpringBootApplication(scanBasePackages = {"io.kumare"}) +@EnableSpringDataWebSupport(pageSerializationMode = EnableSpringDataWebSupport.PageSerializationMode.VIA_DTO) +public class IqrApplication { + + // ::: cons + // + public static void main(String[] args) { + + var innerContext = SpringApplication.run(IqrApplication.class, args); + + // app + App.getEngine().getBase().setInnerContext(innerContext); + App.init(); + } + +} diff --git a/src/main/java/io/kumare/iqr/app/App.java b/src/main/java/io/kumare/iqr/app/App.java new file mode 100644 index 0000000..da0e6fa --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/App.java @@ -0,0 +1,48 @@ +/* + * + */ +package io.kumare.iqr.app; + +// base +import io.kumare.lib.app.api.module.ServiceModuleController; +// app +import io.kumare.iqr.app.adapter.AppAdapters; +import io.kumare.iqr.app.module.AppModules; + +/** + * + * @author afatecha + */ +public class App { + + // ::: constants + // + private static final AppModules modules = new AppModules(); + private static final AppAdapters adapters = new AppAdapters(); + // + private static boolean initialized = false; + + public static void init() { + if (!initialized) { + modules.init(); + //adapters.init(); + initialized = true; + } + } + + public static AppEngine getEngine() { + return AppEngine.getEngine(); + } + + public static AppModules getModules() { + return modules; + } + + public static AppAdapters getAdapters() { + return adapters; + } + + public static ServiceModuleController getController(String name) { + return getModules().getController(name); + } +} diff --git a/src/main/java/io/kumare/iqr/app/AppConstants.java b/src/main/java/io/kumare/iqr/app/AppConstants.java new file mode 100644 index 0000000..b20c284 --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/AppConstants.java @@ -0,0 +1,21 @@ +/* + * + */ +package io.kumare.iqr.app; + +/** + * + * @author afatecha + */ +public class AppConstants { + + // ::: modules + // + public static final int AUTHENTICATION_CODE = 1; + public static final int TAXONOMY_CODE = 2; + public static final int POCKET_CODE = 3; + public static final int BIZ_CODE = 4; + public static final int CLIENTELE_CODE = 5; + public static final int LOYALTY_CODE = 6; + +} diff --git a/src/main/java/io/kumare/iqr/app/AppContext.java b/src/main/java/io/kumare/iqr/app/AppContext.java new file mode 100644 index 0000000..1326de5 --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/AppContext.java @@ -0,0 +1,77 @@ +/* + * + */ +package io.kumare.iqr.app; + +// base +import io.kumare.lib.app.api.module.ServiceModuleController; +import io.kumare.lib.app.api.security.PermissionReference; +import io.kumare.lib.base.server.spring.BaseContext; +// app +import io.kumare.iqr.app.adapter.AppAdapters; +import io.kumare.iqr.app.module.AppModules; +import io.kumare.iqr.app.security.AppSecurityContext; + +/** + * + * @author afatecha + */ +public class AppContext extends BaseContext { + + // ::: cons + // + private final AppSecurityContext security = new AppSecurityContext(this); + + // ::: vars + // + + // ::: fields + // + @Override + public AppEngine getEngine() { + return AppEngine.getEngine(); + } + + // ::: adapters + // + @Override + public AppAdapters getAdapters() { + return App.getAdapters(); + } + + // ::: modules + // + @Override + public AppModules getModules() { + return App.getModules(); + } + + @Override + public ServiceModuleController getController(String name) { + return App.getController(name); + } + + // ::: security + // + @Override + public AppSecurityContext getSecurity() { + return security; + } + + @Override + public void ensureAuthorization(PermissionReference ref) { + /* + var attached = isAttached("authorized"); + if(attached && (Boolean) get("authorized")) { + return; + } + + var controller = AppModules.auth.getController(); + var allowed = controller.isAllowed(this, ref); + V.ifFalse(allowed, ref.getError()); + attach("authorized", true);*/ + } + +} + + diff --git a/src/main/java/io/kumare/iqr/app/AppEngine.java b/src/main/java/io/kumare/iqr/app/AppEngine.java new file mode 100644 index 0000000..65d0f13 --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/AppEngine.java @@ -0,0 +1,64 @@ +/* + * + */ +package io.kumare.iqr.app; + +// base +import io.kumare.lib.app.api.Engine; +import io.kumare.lib.base.server.spring.BaseEngine; +import org.springframework.context.ConfigurableApplicationContext; +// app +import io.kumare.iqr.app.action.AppActionManager; +import io.kumare.iqr.app.security.AppPermissionManager; + +/** + * wrapper of BaseEngine + * + * @author afatecha + */ +public class AppEngine implements Engine { + + // cons + // + private static final AppEngine engine = new AppEngine(); + + // ::: constructors + // + private AppEngine() { + } + + // ::: api + // + public static AppEngine getEngine() { + return engine; + } + + // ::: api + // + @Override + public BaseEngine getBase() { + return BaseEngine.getEngine(); + } + + @Override + public ConfigurableApplicationContext getInnerContext() { + return (ConfigurableApplicationContext) getBase().getInnerContext(); + } + + @Override + public AppContext newContext() { + return new AppContext(); + } + + @Override + public AppActionManager getActionManager() { + return new AppActionManager(); + } + + @Override + public AppPermissionManager getPermissionManager() { + return new AppPermissionManager(); + } +} + + diff --git a/src/main/java/io/kumare/iqr/app/AppErrors.java b/src/main/java/io/kumare/iqr/app/AppErrors.java new file mode 100644 index 0000000..af8a423 --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/AppErrors.java @@ -0,0 +1,69 @@ +/* + * + */ +package io.kumare.iqr.app; + +// java +import java.util.Map; +import java.util.HashMap; +// lib +import io.kumare.lib.transport.TransportCode; +import static io.kumare.lib.transport.Transports.code; +import io.kumare.lib.v.ExceptionPrototype; +// app +import io.kumare.iqr.app.endpoint.AppTransports; + +/** + * + * @author afatecha + */ +public enum AppErrors implements ExceptionPrototype { + + action_arg_notfound(1, code(AppTransports.http, 500)), + action_unauthorized(2, code(AppTransports.http, 500)); + + // ::: vars + // + private final Map transportCodes = new HashMap(); + private final int code; + + // ::: constructors + // + AppErrors(int code, TransportCode... codes) { + this.code = code; + if (codes != null) { + for (var i : codes) { + if (i != null) { + transportCodes.put(i.getId(), i.getCode()); + } + } + } + } + + // ::: prototype api + // + @Override + public int getCode() { + return code; + } + + @Override + public String getName() { + return name(); + } + + @Override + public Map getTransportCodes() { + return transportCodes; + } + + @Override + public RuntimeException newInstance(String msg, Throwable cause, Map extra) { + var ex = new AppException(this, msg, cause); + ex.setExtra(extra); + return ex; + } + +} + + diff --git a/src/main/java/io/kumare/iqr/app/AppException.java b/src/main/java/io/kumare/iqr/app/AppException.java new file mode 100644 index 0000000..6d11aca --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/AppException.java @@ -0,0 +1,132 @@ +/* + * + */ +package io.kumare.iqr.app; + +// java +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.v.ExceptionInterface; +import io.kumare.lib.v.ExceptionPrototype; +// app +import io.kumare.iqr.app.endpoint.AppTransports; + +/** + * + * @author afatecha + */ +public class AppException extends RuntimeException implements ExceptionInterface { + + // ::: vars + // + private int code = 1; + private String name = "unknown"; + private final Map transportCodes = new HashMap<>(); + private Map extra; + + // ::: constructors + // + public AppException() { + } + + public AppException(Throwable cause) { + this(null, null, cause); + } + + public AppException(ExceptionPrototype proto, String msg) { + this(proto, msg, null); + } + + public AppException(ExceptionPrototype proto, String msg, Throwable cause) { + super(msg); + + if (proto != null) { + this.code = proto.getCode(); + this.name = proto.getName(); + this.addTransportCodes(proto.getTransportCodes()); + } + + if (cause != null) { + initCause(cause); + } + } + + public AppException(int code, String name) { + this(code, name, null); + } + + public AppException(int code, String name, String msg) { + this(code, name, msg, null); + } + + public AppException(int code, String name, String msg, Throwable cause) { + super(msg); + + if (code > 0) { + this.code = code; + } + + if (name != null) { + this.name = name; + } + + if (cause != null) { + initCause(cause); + } + + } + + // ::: fields + // + @Override + public int getCode() { + return code; + } + + @Override + public String getName() { + return name; + } + + @Override + public Object getTransportCode(String transportName) { + return getTransportCode(AppTransports.valueOf(transportName)); + } + + @Override + public Object getTransportCode(Enum transportId) { + return getTransportCode(AppTransports.valueOf(transportId.name())); + } + + public Object getTransportCode(AppTransports transportId) { + return transportCodes.get(transportId); + } + + public void setTransportCode(AppTransports transportId, Object code) { + transportCodes.put(transportId, code); + } + + @Override + public Map getTransportCodes() { + return transportCodes; + } + + public final void addTransportCodes(Map map) { + if (map != null) { + this.transportCodes.putAll(map); + } + } + + @Override + public Map getExtra() { + return extra; + } + + public void setExtra(Map extra) { + this.extra = extra; + } + +} + + diff --git a/src/main/java/io/kumare/iqr/app/action/AppAction.java b/src/main/java/io/kumare/iqr/app/action/AppAction.java new file mode 100644 index 0000000..5fac80d --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/action/AppAction.java @@ -0,0 +1,36 @@ +/* + * + */ +package io.kumare.iqr.app.action; + +// base +import io.kumare.lib.base.server.spring.action.BaseAction; +// app +import io.kumare.iqr.app.AppContext; + +/** + * + * @author afatecha + * @param + * @param + */ +public abstract class AppAction extends BaseAction { + + + // ::: cons + // + + // ::: vars + // + + // ::: fields + // + + + + // ::: api + // + + // ::: internals + // +} diff --git a/src/main/java/io/kumare/iqr/app/action/AppActionArgument.java b/src/main/java/io/kumare/iqr/app/action/AppActionArgument.java new file mode 100644 index 0000000..b18fe01 --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/action/AppActionArgument.java @@ -0,0 +1,40 @@ +/* + * + */ +package io.kumare.iqr.app.action; + +// java +import java.io.Serializable; +import java.util.Map; + +/** + * + * @author afatecha + */ +public class AppActionArgument implements Serializable { + + + // ::: vars + // + private Map context; + private Map params; + + // ::: fields + // + public Map getContext() { + return context; + } + + public void setContext(Map context) { + this.context = context; + } + + public Map getParams() { + return params; + } + + public void setParams(Map params) { + this.params = params; + } + +} diff --git a/src/main/java/io/kumare/iqr/app/action/AppActionError.java b/src/main/java/io/kumare/iqr/app/action/AppActionError.java new file mode 100644 index 0000000..d399caf --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/action/AppActionError.java @@ -0,0 +1,12 @@ +/* + * + */ +package io.kumare.iqr.app.action; + +/** + * + * @author afatecha + */ +public class AppActionError { + +} diff --git a/src/main/java/io/kumare/iqr/app/action/AppActionManager.java b/src/main/java/io/kumare/iqr/app/action/AppActionManager.java new file mode 100644 index 0000000..1dbc343 --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/action/AppActionManager.java @@ -0,0 +1,15 @@ +/* + * + */ +package io.kumare.iqr.app.action; + +// base +import io.kumare.lib.base.server.spring.action.BaseActionManager; + +/** + * + * @author afatecha + */ +public class AppActionManager extends BaseActionManager { + +} diff --git a/src/main/java/io/kumare/iqr/app/action/AppActionResult.java b/src/main/java/io/kumare/iqr/app/action/AppActionResult.java new file mode 100644 index 0000000..519f0f6 --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/action/AppActionResult.java @@ -0,0 +1,15 @@ +/* + * + */ +package io.kumare.iqr.app.action; + +// java +import java.io.Serializable; + +/** + * + * @author afatecha + */ +public class AppActionResult implements Serializable { + +} diff --git a/src/main/java/io/kumare/iqr/app/action/AppEntityActionArgument.java b/src/main/java/io/kumare/iqr/app/action/AppEntityActionArgument.java new file mode 100644 index 0000000..7f33940 --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/action/AppEntityActionArgument.java @@ -0,0 +1,46 @@ +/* + * + */ +package io.kumare.iqr.app.action; + +// base +import io.kumare.lib.app.api.store.Entity; + +/** + * + * @author afatecha + * @param + */ +public class AppEntityActionArgument extends AppActionArgument { + + // ::: vars + // + private E entity; + + // ::: constructors + // + public AppEntityActionArgument() { + } + + public AppEntityActionArgument(E entity) { + this.entity = entity; + } + + // ::: fields + // + public E getEntity() { + return entity; + } + + public void setEntity(E entity) { + this.entity = entity; + } + + // ::: fluents + // + public AppEntityActionArgument entity(E entity) { + setEntity(entity); + return this; + } + +} diff --git a/src/main/java/io/kumare/iqr/app/action/AppEntityActionResult.java b/src/main/java/io/kumare/iqr/app/action/AppEntityActionResult.java new file mode 100644 index 0000000..fc18a1a --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/action/AppEntityActionResult.java @@ -0,0 +1,30 @@ +/* + * + */ +package io.kumare.iqr.app.action; + +// base +import io.kumare.lib.app.api.store.Entity; + +/** + * + * @author afatecha + * @param + */ +public class AppEntityActionResult extends AppActionResult { + + // ::: vars + // + private E entity; + + // ::: fields + // + public E getEntity() { + return entity; + } + + public void setEntity(E entity) { + this.entity = entity; + } + +} diff --git a/src/main/java/io/kumare/iqr/app/action/AppListActionArgument.java b/src/main/java/io/kumare/iqr/app/action/AppListActionArgument.java new file mode 100644 index 0000000..4a47b74 --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/action/AppListActionArgument.java @@ -0,0 +1,85 @@ +/* + * + */ +package io.kumare.iqr.app.action; + +// base +import io.kumare.lib.app.api.store.Entity; + +/** + * + * @author afatecha + * @param + */ +public class AppListActionArgument extends AppEntityActionArgument { + + // ::: vars + // + private boolean wrapped = false; + private boolean pageable = false; + private int pageNumber = 0; + private int pageSize = 0; + private String sort; + private String query; + + // ::: constructor + // + public AppListActionArgument() { + } + + public AppListActionArgument(E entity) { + super(entity); + } + + // ::: fields + // + public boolean isWrapped() { + return wrapped; + } + + public void setWrapped(boolean wrapped) { + this.wrapped = wrapped; + } + + public boolean isPageable() { + return pageable; + } + + public void setPageable(boolean pageable) { + this.pageable = pageable; + } + + public int getPageNumber() { + return pageNumber; + } + + public void setPageNumber(int pageNumber) { + this.pageNumber = pageNumber; + } + + public int getPageSize() { + return pageSize; + } + + public void setPageSize(int pageSize) { + this.pageSize = pageSize; + } + + public String getSort() { + return sort; + } + + public void setSort(String sort) { + this.sort = sort; + } + + public String getQuery() { + return query; + } + + public void setQuery(String query) { + this.query = query; + } + + +} diff --git a/src/main/java/io/kumare/iqr/app/adapter/AppAdapters.java b/src/main/java/io/kumare/iqr/app/adapter/AppAdapters.java new file mode 100644 index 0000000..5c5ed34 --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/adapter/AppAdapters.java @@ -0,0 +1,27 @@ +/* + * + */ +package io.kumare.iqr.app.adapter; + +// base +import io.kumare.adapter.spring.vismatime.VismaTimeAdapter; +import io.kumare.lib.base.server.spring.adapter.BaseAdapters; +import io.kumare.oauthlib.server.app.adapter.oauth.OauthAdapter; +// app + +/** + * + * @author afatecha + */ +public class AppAdapters extends BaseAdapters { + + // ::: adapters + // + public OauthAdapter getOauth() { + return getContext().getBean(OauthAdapter.class); + } + + public VismaTimeAdapter getVisma() { + return getContext().getBean(VismaTimeAdapter.class); + } +} diff --git a/src/main/java/io/kumare/iqr/app/endpoint/AppTransports.java b/src/main/java/io/kumare/iqr/app/endpoint/AppTransports.java new file mode 100644 index 0000000..37dfc00 --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/endpoint/AppTransports.java @@ -0,0 +1,14 @@ +/* + * + */ +package io.kumare.iqr.app.endpoint; + +/** + * + * @author afatecha + */ +public enum AppTransports { + + http + +} diff --git a/src/main/java/io/kumare/iqr/app/endpoint/rest/AppEndpointRest.java b/src/main/java/io/kumare/iqr/app/endpoint/rest/AppEndpointRest.java new file mode 100644 index 0000000..afa2fc0 --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/endpoint/rest/AppEndpointRest.java @@ -0,0 +1,28 @@ +/* + * + */ +package io.kumare.iqr.app.endpoint.rest; + +// base +import io.kumare.lib.app.api.action.ActionManager; +import io.kumare.lib.base.server.spring.endpoint.rest.BaseEndpointRest; +// app +import io.kumare.iqr.app.AppContext; +import io.kumare.iqr.app.AppEngine; + +/** + * + * @author afatecha + */ +public class AppEndpointRest extends BaseEndpointRest { + + @Override + protected ActionManager getActionManager() { + return AppEngine.getEngine().getActionManager(); + } + + @Override + protected AppContext newContext() { + return AppEngine.getEngine().newContext(); + } +} diff --git a/src/main/java/io/kumare/iqr/app/endpoint/rest/AppOpenAPIConfiguration.java b/src/main/java/io/kumare/iqr/app/endpoint/rest/AppOpenAPIConfiguration.java new file mode 100644 index 0000000..99c69aa --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/endpoint/rest/AppOpenAPIConfiguration.java @@ -0,0 +1,31 @@ +/* + * + */ +package io.kumare.iqr.app.endpoint.rest; + +// openapi +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Contact; +import io.swagger.v3.oas.models.info.Info; +// spring +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * + * @author afatecha + */ +@Configuration +public class AppOpenAPIConfiguration { + + @Bean + public OpenAPI customOpenAPI() { + return new OpenAPI().info( + new Info() + .title("iqr") + .version("1.0") + .description("iqr project") + .contact(new Contact().name("Catatrepa").email("soporte@catatrepa.com")) + ); + } +} diff --git a/src/main/java/io/kumare/iqr/app/endpoint/rest/WebSecurityConfig.java b/src/main/java/io/kumare/iqr/app/endpoint/rest/WebSecurityConfig.java new file mode 100644 index 0000000..920b131 --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/endpoint/rest/WebSecurityConfig.java @@ -0,0 +1,122 @@ +/* + */ +package io.kumare.iqr.app.endpoint.rest; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.web.SecurityFilterChain; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; + +import java.util.Arrays; + +/** + * @author aservin + */ +@Configuration +@EnableWebSecurity +public class WebSecurityConfig { + + // ::: constants + // + //private final JwtAuthConverter jwtAuthConverter; + + // ::: constructors + // + /* + public WebSecurityConfig(JwtAuthConverter jwtAuthConverter) { + this.jwtAuthConverter = jwtAuthConverter; + }*/ + + // ::: beans + // + @Bean + public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { + // REQUESTS + /*http.authorizeHttpRequests(authorize -> authorize + // Permitir acceso al login + .requestMatchers(HttpMethod.POST, "/account/accounts/login/**").permitAll() + // Agrupar rutas con las mismas reglas de autorización + .requestMatchers( + "/account/**", + "/actor/**", + "/attachment/**", + "/bpmflow/**", + "/authority/**", + "/bpmwork/**", + "/currency/**", + "/instrument/**", + "/issue/**", + "/management/**", + "/sale/**", + "/title/**", + "/workcase/**", + "/workgroup/**", + "/workflow/**" + ).hasAnyRole("ADMIN", "MOD") + // Permitir todas las rutas bajo "/procesos/" para todos los métodos + .requestMatchers("/procesos/**", + "/location/**").permitAll() + // Permitir acceso a Swagger y documentación API + .requestMatchers(HttpMethod.GET, + "/swagger-workflow-server.html", + "/swagger-ui/**", + "/swagger-ui.html", + "/v3/api-docs/**").permitAll() + // Requiere autenticación para el resto de las rutas + .anyRequest().authenticated());*/ + + //http + // .authorizeHttpRequests(authorize -> authorize.anyRequest().permitAll()); + + + /* + // OAUTH JWT CONFIGURATION + http.oauth2ResourceServer(oauth2ResourceServer + -> oauth2ResourceServer.jwt(jwt + -> jwt.jwtAuthenticationConverter(jwtAuthConverter)));*/ + + // CORS CONFIGURATION + var source = new UrlBasedCorsConfigurationSource(); + var corsConfig = new CorsConfiguration(); + corsConfig.setAllowCredentials(true); + corsConfig.addAllowedOriginPattern("*"); // Permitir cualquier origen + corsConfig.addAllowedHeader("*"); + corsConfig.setAllowedMethods(Arrays.asList("OPTIONS", "HEAD", "GET", "PUT", "POST", "DELETE", "PATCH")); + source.registerCorsConfiguration("/**", corsConfig); + + http.csrf(csrf -> csrf.disable()).cors(cors -> cors.configurationSource(source)); + + // SESSION MANAGEMENT + /* + http.sessionManagement(sessionManagement + -> sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS));*/ + + // FINAL CONFIGURATION + return http.getOrBuild(); + } + + /* + //para prueba + @Bean + public CorsFilter corsFilter() { + final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + final CorsConfiguration config = new CorsConfiguration(); + //config.setAllowCredentials(true); + config.setAllowCredentials(false); + config.addAllowedOrigin("*"); + config.addAllowedHeader("*"); + config.addAllowedMethod("OPTIONS"); + config.addAllowedMethod("HEAD"); + config.addAllowedMethod("GET"); + config.addAllowedMethod("PUT"); + config.addAllowedMethod("POST"); + config.addAllowedMethod("DELETE"); + config.addAllowedMethod("PATCH"); + source.registerCorsConfiguration("/**", config); + return new CorsFilter(source); + }*/ +} diff --git a/src/main/java/io/kumare/iqr/app/module/AppModuleController.java b/src/main/java/io/kumare/iqr/app/module/AppModuleController.java new file mode 100644 index 0000000..ed067a5 --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/module/AppModuleController.java @@ -0,0 +1,16 @@ +/* + * + */ +package io.kumare.iqr.app.module; + +// base +import io.kumare.lib.base.server.spring.module.BaseModuleController; + +/** + * + * @author afatecha + */ +public abstract class AppModuleController extends BaseModuleController { + + +} diff --git a/src/main/java/io/kumare/iqr/app/module/AppModules.java b/src/main/java/io/kumare/iqr/app/module/AppModules.java new file mode 100644 index 0000000..441ae4a --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/module/AppModules.java @@ -0,0 +1,67 @@ +/* + * + */ +package io.kumare.iqr.app.module; + +// base +import io.kumare.lib.base.server.spring.module.BaseModules; +// app +import io.kumare.iqr.mod.authentication.AuthenticationModule; +import io.kumare.iqr.mod.taxonomy.TaxonomyModule; +import io.kumare.iqr.mod.pocket.PocketModule; +import io.kumare.iqr.mod.biz.BizModule; +import io.kumare.iqr.mod.clientele.ClienteleModule; +import io.kumare.iqr.mod.loyalty.LoyaltyModule; + +/** + * + * @author afatecha + */ +public class AppModules extends BaseModules { + + // ::: constants + // + public static final AuthenticationModule authentication = new AuthenticationModule(); + public static final TaxonomyModule taxonomy = new TaxonomyModule(); + public static final PocketModule pocket = new PocketModule(); + public static final BizModule biz = new BizModule(); + public static final ClienteleModule clientele = new ClienteleModule(); + public static final LoyaltyModule loyalty = new LoyaltyModule(); + + // ::: modules + // + public AuthenticationModule getAuthentication() { + return authentication; + } + + public TaxonomyModule getTaxonomy() { + return taxonomy; + } + + public PocketModule getPocket() { + return pocket; + } + + public BizModule getBiz() { + return biz; + } + + public ClienteleModule getClientele() { + return clientele; + } + + public LoyaltyModule getLoyalty() { + return loyalty; + } + + // ::: init + // + public void init() { + add(authentication); + add(taxonomy); + add(pocket); + add(biz); + add(clientele); + add(loyalty); + } +} diff --git a/src/main/java/io/kumare/iqr/app/security/AppPermissionManager.java b/src/main/java/io/kumare/iqr/app/security/AppPermissionManager.java new file mode 100644 index 0000000..d8a0057 --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/security/AppPermissionManager.java @@ -0,0 +1,16 @@ +/* + * + */ +package io.kumare.iqr.app.security; + +// base +import io.kumare.lib.base.server.spring.security.BasePermissionManager; + +/** + * + * @author afatecha + */ +public class AppPermissionManager extends BasePermissionManager { + + +} diff --git a/src/main/java/io/kumare/iqr/app/security/AppSecurityContext.java b/src/main/java/io/kumare/iqr/app/security/AppSecurityContext.java new file mode 100644 index 0000000..ca0d83b --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/security/AppSecurityContext.java @@ -0,0 +1,23 @@ +/* + * + */ +package io.kumare.iqr.app.security; + +// base +import io.kumare.lib.base.server.spring.security.BaseSecurityContext; +// app +import io.kumare.iqr.app.AppContext; + +/** + * + * @author afatecha + */ +public class AppSecurityContext extends BaseSecurityContext { + + // ::: constructor + // + public AppSecurityContext(AppContext context) { + super(context); + } + +} diff --git a/src/main/java/io/kumare/iqr/app/security/AppSecurityScopes.java b/src/main/java/io/kumare/iqr/app/security/AppSecurityScopes.java new file mode 100644 index 0000000..cb47776 --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/security/AppSecurityScopes.java @@ -0,0 +1,57 @@ +/* + * + */ +package io.kumare.iqr.app.security; + +// java +import java.util.LinkedList; +import java.util.List; + + +/** + * + * @author afatecha + */ +public enum AppSecurityScopes { + + system(false), + service(false), + module(false), + reference(true), + component(true); + + // ::: api + // + private final boolean idRequired; + + AppSecurityScopes(boolean idRequired) { + this.idRequired = idRequired; + } + + public boolean isIdRequired() { + return idRequired; + } + + public int level() { + return ordinal() + 1; + } + + // ::: static + // + public static List scopes(String referenceId, String componentId) { + var list = new LinkedList(); + + list.add(system.name()); + list.add(service.name()); + list.add(module.name()); + + if (referenceId != null) { + list.add(reference.name() + "-" + referenceId); + } + if (componentId != null) { + list.add(component.name() + "-" + componentId); + } + + return list; + } +} diff --git a/src/main/java/io/kumare/iqr/app/store/AppEntity.java b/src/main/java/io/kumare/iqr/app/store/AppEntity.java new file mode 100644 index 0000000..93f44cc --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/store/AppEntity.java @@ -0,0 +1,29 @@ +/* + * + */ +package io.kumare.iqr.app.store; + +// java +import jakarta.persistence.MappedSuperclass; +// base +import io.kumare.lib.base.server.spring.store.jpa.DefaultJpaEntity; + +/** + * + * @author afatecha + */ +@MappedSuperclass +public class AppEntity extends DefaultJpaEntity { + + // ::: constructors + // + public AppEntity() { + super(); + } + + public AppEntity(String id) { + super(id); + } + +} + diff --git a/src/main/java/io/kumare/iqr/app/store/AppEntityRepository.java b/src/main/java/io/kumare/iqr/app/store/AppEntityRepository.java new file mode 100644 index 0000000..b92b676 --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/store/AppEntityRepository.java @@ -0,0 +1,21 @@ +/* + * + */ +package io.kumare.iqr.app.store; + +// spring +import org.springframework.data.repository.NoRepositoryBean; +// base +import io.kumare.lib.app.api.store.Entity; +import io.kumare.lib.base.server.spring.store.jpa.BaseJpaEntityRepository; + +/** + * + * @author afatecha + * @param + */ +@NoRepositoryBean +public interface AppEntityRepository extends BaseJpaEntityRepository { + + +} diff --git a/src/main/java/io/kumare/iqr/app/store/AppEntityStore.java b/src/main/java/io/kumare/iqr/app/store/AppEntityStore.java new file mode 100644 index 0000000..f71aec6 --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/store/AppEntityStore.java @@ -0,0 +1,29 @@ +/* + * + */ +package io.kumare.iqr.app.store; + +// base +import io.kumare.lib.app.api.store.Entity; +import io.kumare.lib.base.server.spring.BaseContext; +import io.kumare.lib.base.server.spring.store.jpa.BaseJpaEntityStore; +// app +import io.kumare.iqr.app.util.AppUtil; + +/** + * + * @author afatecha + * @param + */ +public abstract class AppEntityStore extends BaseJpaEntityStore { + + // ::: api + // + @Override + protected String makeEntityId(E model) { + return model.getId() == null ? AppUtil.randomId() : model.getId().toString(); + } + + + +} diff --git a/src/main/java/io/kumare/iqr/app/store/AppExtendedEntity.java b/src/main/java/io/kumare/iqr/app/store/AppExtendedEntity.java new file mode 100644 index 0000000..7372be9 --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/store/AppExtendedEntity.java @@ -0,0 +1,30 @@ +/* + * + */ +package io.kumare.iqr.app.store; + +// java +import java.io.Serializable; +import jakarta.persistence.MappedSuperclass; +// base +import io.kumare.lib.base.server.spring.store.jpa.DefaultExtendedJpaEntity; + +/** + * + * @author afatecha + * @param + */ +@MappedSuperclass +public class AppExtendedEntity extends DefaultExtendedJpaEntity { + + // ::: constructors + // + public AppExtendedEntity() { + super(); + } + + public AppExtendedEntity(String id) { + super(id); + } +} + diff --git a/src/main/java/io/kumare/iqr/app/store/AppExtendedEntityData.java b/src/main/java/io/kumare/iqr/app/store/AppExtendedEntityData.java new file mode 100644 index 0000000..e104613 --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/store/AppExtendedEntityData.java @@ -0,0 +1,15 @@ +/* + * + */ +package io.kumare.iqr.app.store; + +// java +import java.io.Serializable; + +/** + * + * @author afatecha + */ +public class AppExtendedEntityData implements Serializable { + +} diff --git a/src/main/java/io/kumare/iqr/app/store/AppJacksonConfiguration.java b/src/main/java/io/kumare/iqr/app/store/AppJacksonConfiguration.java new file mode 100644 index 0000000..b72acce --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/store/AppJacksonConfiguration.java @@ -0,0 +1,26 @@ +/* + * + */ +package io.kumare.iqr.app.store; + +// jackson +import com.fasterxml.jackson.datatype.hibernate6.Hibernate6Module; +// spring +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * + */ +@Configuration +public class AppJacksonConfiguration { + + @Bean + public Hibernate6Module hibernate6Module() { + + Hibernate6Module module = new Hibernate6Module(); + module.enable(Hibernate6Module.Feature.SERIALIZE_IDENTIFIER_FOR_LAZY_NOT_LOADED_OBJECTS); + return module; + } + +} diff --git a/src/main/java/io/kumare/iqr/app/store/AppKeyEntityRepository.java b/src/main/java/io/kumare/iqr/app/store/AppKeyEntityRepository.java new file mode 100644 index 0000000..7c5063c --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/store/AppKeyEntityRepository.java @@ -0,0 +1,21 @@ +/* + * + */ +package io.kumare.iqr.app.store; + +// spring +import org.springframework.data.repository.NoRepositoryBean; +// base +import io.kumare.lib.app.api.store.Entity; +import io.kumare.lib.base.server.spring.store.jpa.BaseJpaKeyEntityRepository; + +/** + * + * @author afatecha + * @param + */ +@NoRepositoryBean +public interface AppKeyEntityRepository extends BaseJpaKeyEntityRepository{ + + +} diff --git a/src/main/java/io/kumare/iqr/app/store/AppKeyEntityStore.java b/src/main/java/io/kumare/iqr/app/store/AppKeyEntityStore.java new file mode 100644 index 0000000..5152c5b --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/store/AppKeyEntityStore.java @@ -0,0 +1,29 @@ +/* + * + */ +package io.kumare.iqr.app.store; + +// base +import io.kumare.lib.app.api.store.Entity; +import io.kumare.lib.app.api.Context; +import io.kumare.lib.base.server.spring.store.jpa.BaseJpaKeyEntityStore; +// app +import io.kumare.iqr.app.util.AppUtil; + +/** + * + * @author afatecha + * @param + */ +public abstract class AppKeyEntityStore extends BaseJpaKeyEntityStore { + + // ::: api + // + @Override + protected String makeEntityId(E model) { + return model.getId() == null ? AppUtil.randomId() : model.getId().toString(); + } + + + +} diff --git a/src/main/java/io/kumare/iqr/app/util/AppUtil.java b/src/main/java/io/kumare/iqr/app/util/AppUtil.java new file mode 100644 index 0000000..ca23931 --- /dev/null +++ b/src/main/java/io/kumare/iqr/app/util/AppUtil.java @@ -0,0 +1,18 @@ +/* + * + */ +package io.kumare.iqr.app.util; + +import java.util.UUID; + +/** + * + * @author afatecha + */ +public class AppUtil { + + public static String randomId() { + return UUID.randomUUID().toString(); + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/AuthenticationConstants.java b/src/main/java/io/kumare/iqr/mod/authentication/AuthenticationConstants.java new file mode 100644 index 0000000..574e665 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/AuthenticationConstants.java @@ -0,0 +1,20 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication; + +// base +import io.kumare.iqr.app.AppConstants; + +/** + * + * @author afatecha + */ +public class AuthenticationConstants { + + // ::: codes + // + public static final int CODE = AppConstants.AUTHENTICATION_CODE; + public static final String NAME = "authentication"; + +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/AuthenticationController.java b/src/main/java/io/kumare/iqr/mod/authentication/AuthenticationController.java new file mode 100644 index 0000000..8f6a2de --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/AuthenticationController.java @@ -0,0 +1,57 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication; + +// java +import io.kumare.iqr.mod.authentication.store.AuthenticationEntities; +import java.util.Arrays; +import java.util.List; +// base +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app +import io.kumare.iqr.app.module.AppModuleController; +// module +import io.kumare.iqr.mod.authentication.store.authuser.AuthUserStore; +import io.kumare.iqr.mod.authentication.store.authuserrelation.AuthUserRelationStore; + +/** + * + * @author afatecha + */ +public class AuthenticationController extends AppModuleController { + + // ::: api + // + @Override + public boolean hasStore(String name) { + return AuthenticationEntities.hasDescriptor(name); + } + + @Override + public EntityDescriptor getEntityDescriptor(Class entityClass) { + return AuthenticationEntities.descriptorOf(entityClass); + } + + @Override + public EntityDescriptor getEntityDescriptor(String name) { + return AuthenticationEntities.descriptorOf(name); + } + + @Override + public List getEntityDescriptors() { + return Arrays.asList(AuthenticationEntities.values()); + } + + // ::: stores + // + public AuthUserStore getAuthUserStore() { + return getService(AuthUserStore.class); + } + + public AuthUserRelationStore getAuthUserRelationStore() { + return getService(AuthUserRelationStore.class); + } + + +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/AuthenticationErrors.java b/src/main/java/io/kumare/iqr/mod/authentication/AuthenticationErrors.java new file mode 100644 index 0000000..33128e6 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/AuthenticationErrors.java @@ -0,0 +1,94 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication; + +// java +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.transport.TransportCode; +import static io.kumare.lib.transport.Transports.code; +import io.kumare.lib.v.ExceptionPrototype; +// app +import io.kumare.iqr.app.AppException; +import io.kumare.iqr.app.endpoint.AppTransports; + + +/** + * + * @author afatecha + */ +public enum AuthenticationErrors implements ExceptionPrototype { + + + // auth user + authuser_notfound(1, code(AppTransports.http, 400)), + authuser_data_notfound(1, code(AppTransports.http, 400)), + authuser_preload_empty(1, code(AppTransports.http, 400)), + authuser_externalid_empty(1, code(AppTransports.http, 400)), + authuser_entitykey_empty(1, code(AppTransports.http, 400)), + authuser_custom_empty(1, code(AppTransports.http, 400)), + authuser_visible_empty(1, code(AppTransports.http, 400)), + authuser_email_empty(1, code(AppTransports.http, 400)), + authuser_emailconfirmed_empty(1, code(AppTransports.http, 400)), + authuser_phone_empty(1, code(AppTransports.http, 400)), + authuser_phoneconfirmed_empty(1, code(AppTransports.http, 400)), + authuser_name_empty(1, code(AppTransports.http, 400)), + + // auth user relation + authuserrelation_notfound(1, code(AppTransports.http, 400)), + authuserrelation_data_notfound(1, code(AppTransports.http, 400)), + authuserrelation_preload_empty(1, code(AppTransports.http, 400)), + authuserrelation_externalid_empty(1, code(AppTransports.http, 400)), + authuserrelation_userkey_empty(1, code(AppTransports.http, 400)), + authuserrelation_typevalue_empty(1, code(AppTransports.http, 400)), + authuserrelation_resourcetype_empty(1, code(AppTransports.http, 400)), + authuserrelation_resourcekey_empty(1, code(AppTransports.http, 400)), + authuserrelation_resourceid_empty(1, code(AppTransports.http, 400)), + authuserrelation_authuser_notfound(1, code(AppTransports.http, 400)); + + // ::: vars + // + private final Map transportCodes = new HashMap(); + private final int code; + + // ::: constructors + // + private AuthenticationErrors(int code, TransportCode... codes) { + this.code = code; + if (codes != null) { + for (var i : codes) { + if (i != null) { + transportCodes.put(i.getId(), i.getCode()); + } + } + } + } + + // ::: prototype api + // + @Override + public int getCode() { + return code; + } + + @Override + public String getName() { + return name(); + } + + @Override + public Map getTransportCodes() { + return transportCodes; + } + + @Override + public RuntimeException newInstance(String msg, Throwable cause, Map extra) { + var ex = new AppException(this, msg, cause); + ex.setExtra(extra); + return ex; + } + + +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/AuthenticationModule.java b/src/main/java/io/kumare/iqr/mod/authentication/AuthenticationModule.java new file mode 100644 index 0000000..cd00a42 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/AuthenticationModule.java @@ -0,0 +1,37 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication; + +// java +import io.kumare.lib.base.server.spring.module.BaseModule; + + +/** + * + * @author afatecha + */ +public class AuthenticationModule extends BaseModule { + + // ::: + // + public static final AuthenticationController controller = new AuthenticationController(); + + // ::: api + // + @Override + public int getId() { + return AuthenticationConstants.CODE; + } + + @Override + public String getName() { + return AuthenticationConstants.NAME; + } + + @Override + public AuthenticationController getController() { + return controller; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/AuthenticationPermissions.java b/src/main/java/io/kumare/iqr/mod/authentication/AuthenticationPermissions.java new file mode 100644 index 0000000..950fad5 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/AuthenticationPermissions.java @@ -0,0 +1,84 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication; + +// base +import io.kumare.iqr.mod.authentication.store.AuthenticationEntities; +import io.kumare.lib.app.api.security.PermissionReference; +// app +import io.kumare.iqr.app.AppErrors; + +/** + * + * @author afatecha + */ +public enum AuthenticationPermissions { + + // auth user + //auth_user_add(AuthenticationEntities.authUser), + //auth_user_edit(AuthenticationEntities.authUser), + //auth_user_find(AuthenticationEntities.authUser), + //auth_user_enable(AuthenticationEntities.authUser), + //auth_user_disable(AuthenticationEntities.authUser), + //auth_user_list(AuthenticationEntities.authUser), + //auth_user_delete(AuthenticationEntities.authUser), + //auth_user_preload(AuthenticationEntities.authUser), + // + auth_user_viewer(AuthenticationEntities.authUser), + //auth_user_guest(AuthenticationEntities.authUser), + //auth_user_collab(AuthenticationEntities.authUser), + auth_user_worker(AuthenticationEntities.authUser), + //auth_user_control(AuthenticationEntities.authUser), + auth_user_manager(AuthenticationEntities.authUser), + auth_user_admin(null), + auth_user_system(null), + + // auth user relation + //auth_user_relation_add(AuthenticationEntities.authUserRelation), + //auth_user_relation_edit(AuthenticationEntities.authUserRelation), + //auth_user_relation_find(AuthenticationEntities.authUserRelation), + //auth_user_relation_enable(AuthenticationEntities.authUserRelation), + //auth_user_relation_disable(AuthenticationEntities.authUserRelation), + //auth_user_relation_list(AuthenticationEntities.authUserRelation), + //auth_user_relation_delete(AuthenticationEntities.authUserRelation), + //auth_user_relation_preload(AuthenticationEntities.authUserRelation), + // + auth_user_relation_viewer(AuthenticationEntities.authUserRelation), + //auth_user_relation_guest(AuthenticationEntities.authUserRelation), + //auth_user_relation_collab(AuthenticationEntities.authUserRelation), + auth_user_relation_worker(AuthenticationEntities.authUserRelation), + //auth_user_relation_control(AuthenticationEntities.authUserRelation), + auth_user_relation_manager(AuthenticationEntities.authUserRelation), + auth_user_relation_admin(null), + auth_user_relation_system(null); + + + // ::: + // + private final AuthenticationEntities resourceType; + + AuthenticationPermissions(AuthenticationEntities entityRef) { + this.resourceType = entityRef; + } + + // + public PermissionReference toReference() { + return toReference(null); + } + + public PermissionReference toReference(String resourceKey) { + var ref = new PermissionReference() + .module(AuthenticationConstants.NAME) + .permission(name()) + .error(AppErrors.action_unauthorized); + + if (resourceType != null && resourceKey != null) { + ref.resourceType(resourceType.name()) + .resourceKey(resourceKey); + } + + return ref; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserActionArgument.java b/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserActionArgument.java new file mode 100644 index 0000000..960df42 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserActionArgument.java @@ -0,0 +1,29 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.action.authuser; + +// base +import io.kumare.iqr.app.action.AppEntityActionArgument; +// entity +import io.kumare.iqr.mod.authentication.store.authuser.AuthUserEntity; + +/** + * + * @author afatecha + */ +public class AuthUserActionArgument extends AppEntityActionArgument { + + // ::: constructors + // + public AuthUserActionArgument() { + } + + public AuthUserActionArgument(AuthUserEntity entity) { + super(entity); + } + + // ::: api + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserAddAction.java b/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserAddAction.java new file mode 100644 index 0000000..5de1a83 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserAddAction.java @@ -0,0 +1,169 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.action.authuser; + +// java +import java.util.List; +// lib +import io.kumare.lib.base.server.spring.action.Actions; +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.authentication.AuthenticationErrors; +// entity +import io.kumare.iqr.mod.authentication.store.authuser.AuthUserEntity; + +import io.kumare.iqr.mod.authentication.action.authuserrelation.AuthUserRelationAddAction; +import io.kumare.iqr.mod.authentication.action.authuserrelation.AuthUserRelationAddArgument; +import io.kumare.oauthlib.server.app.adapter.oauth.OauthAdapter; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import org.keycloak.admin.client.CreatedResponseUtil; +import org.keycloak.representations.idm.CredentialRepresentation; +import org.keycloak.representations.idm.UserRepresentation; + +/** + * + * @author afatecha + */ +public class AuthUserAddAction extends AppAction> { + + // ::: vars + // + private AuthUserEntity entity; + private UserRepresentation user; + private OauthAdapter oauth; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, AuthenticationErrors.authuser_notfound); + + // relations + // fields + //V.ifEmpty(model.getExternalId(), AuthenticationErrors.authuser_externalid_empty); + //V.ifEmpty(model.getEntityKey(), AuthenticationErrors.authuser_entitykey_empty); + //V.ifEmpty(model.isCustom(), AuthenticationErrors.authuser_custom_empty); + //V.ifEmpty(model.isVisible(), AuthenticationErrors.authuser_visible_empty); + V.ifEmpty(model.getEmail(), AuthenticationErrors.authuser_email_empty); + //V.ifEmpty(model.isEmailConfirmed(), AuthenticationErrors.authuser_emailconfirmed_empty); + //V.ifEmpty(model.getPhone(), AuthenticationErrors.authuser_phone_empty); + //V.ifEmpty(model.isPhoneConfirmed(), AuthenticationErrors.authuser_phoneconfirmed_empty); + V.ifEmpty(model.getName(), AuthenticationErrors.authuser_name_empty); + } + + @Override + protected void doAction() { + + // adapters + //oauth = getContext().getAdapters().getOauth(); + + // controllers + //createKeycloakUser(); + // model + var model = makeModel(); + + // add + entity = saveEntity(model); + + // add others + addRelations(getArgument().getRelations()); + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private AuthUserEntity makeModel() { + var argModel = getArgument().getEntity(); + var model = new AuthUserEntity(); + + // relations + // fields + //model.setExternalId(user.getId()); + model.setEntityKey(argModel.getEntityKey());//user.getUsername()); + model.setCustom(argModel.isCustom()); + model.setVisible(argModel.isVisible()); + model.setEmail(argModel.getEmail()); + model.setEmailConfirmed(argModel.isEmailConfirmed()); + model.setPhone(argModel.getPhone()); + model.setPhoneConfirmed(argModel.isPhoneConfirmed()); + model.setName(argModel.getName()); + model.setActive(true); + + return model; + } + + // ::: save + // + private AuthUserEntity saveEntity(AuthUserEntity model) { + + var store = AppModules.authentication.getController().getAuthUserStore(); + + var saved = store.add(getContext(), model); + getContext().attach(saved.getId(), saved); + return saved; + } + + // ::: add relations + // + private void addRelations(List list) { + if (list != null) { + list.forEach(i -> { + i.getEntity().authUser(entity); + Actions.perform(getContext(), new AuthUserRelationAddAction(), i); + }); + } + } + + private void createKeycloakUser() { + var arg = getArgument().getEntity(); + + user = new UserRepresentation(); + user.setFirstName(arg.getName()); + user.setLastName(arg.getName()); + user.setEmail(arg.getEmail()); + user.setEmailVerified(false); + user.setUsername(arg.getEmail()); + + var credential = new CredentialRepresentation(); + credential.setType("password"); + credential.setTemporary(false); + String password = getArgument().getPassword(); + credential.setValue(password); + user.setCredentials(Collections.singletonList(credential)); + Map> attributes = new HashMap<>(); + attributes.put("phone", Collections.singletonList(arg.getPhone())); + user.setAttributes(attributes); + + createUserInKeycloak(); + } + + private void createUserInKeycloak() { + user.setEnabled(true); + user.setEmailVerified(false); + + var response = oauth.users().create(user); + String userId = CreatedResponseUtil.getCreatedId(response); + user = oauth.users().find(userId); + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserAddArgument.java b/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserAddArgument.java new file mode 100644 index 0000000..2e925ef --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserAddArgument.java @@ -0,0 +1,52 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.action.authuser; + +// java +import java.util.List; +// app +import io.kumare.iqr.mod.authentication.store.authuser.AuthUserEntity; +import io.kumare.iqr.mod.authentication.action.authuserrelation.AuthUserRelationAddArgument; + +/** + * + * @author afatecha + */ +public class AuthUserAddArgument extends AuthUserActionArgument { + + // ::: vars + // + private List relations; + private String password; + + // ::: constructors + // + public AuthUserAddArgument() { + } + + public AuthUserAddArgument(AuthUserEntity entity) { + super(entity); + } + + // ::: fields + // + public List getRelations() { + return relations; + } + + public void setRelations(List list) { + this.relations = list; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + + +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserDeleteAction.java b/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserDeleteAction.java new file mode 100644 index 0000000..f24f629 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserDeleteAction.java @@ -0,0 +1,59 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.action.authuser; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.authentication.AuthenticationErrors; +// entity +import io.kumare.iqr.mod.authentication.store.authuser.AuthUserEntity; + +/** + * + * @author afatecha + */ +public class AuthUserDeleteAction extends AppAction> { + + // ::: vars + // + private AuthUserEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), AuthenticationErrors.authuser_notfound); + V.ifNull(getArgument().getEntity().getId(), AuthenticationErrors.authuser_notfound); + } + + @Override + protected void doAction() { + + var argModel = getArgument().getEntity(); + + deleteEntity(argModel); + } + + @Override + protected void setResultOnly() { + } + + // ::: delete + // + private void deleteEntity(AuthUserEntity model) { + + var store = AppModules.authentication.getController().getAuthUserStore(); + + store.deleteById(getContext(), model.getId()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserEditAction.java b/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserEditAction.java new file mode 100644 index 0000000..d9386e5 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserEditAction.java @@ -0,0 +1,109 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.action.authuser; + +// lib +import io.kumare.lib.v.V; +// app +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.authentication.AuthenticationErrors; +// entity +import io.kumare.iqr.mod.authentication.store.authuser.AuthUserEntity; + +/** + * + * @author afatecha + */ +public class AuthUserEditAction extends AppAction> { + + // ::: vars + // + private AuthUserEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, AuthenticationErrors.authuser_notfound); + + // fields + V.ifEmpty(model.getExternalId(), AuthenticationErrors.authuser_externalid_empty); + V.ifEmpty(model.getEntityKey(), AuthenticationErrors.authuser_entitykey_empty); + V.ifEmpty(model.isCustom(), AuthenticationErrors.authuser_custom_empty); + V.ifEmpty(model.isVisible(), AuthenticationErrors.authuser_visible_empty); + V.ifEmpty(model.getEmail(), AuthenticationErrors.authuser_email_empty); + V.ifEmpty(model.isEmailConfirmed(), AuthenticationErrors.authuser_emailconfirmed_empty); + V.ifEmpty(model.getPhone(), AuthenticationErrors.authuser_phone_empty); + V.ifEmpty(model.isPhoneConfirmed(), AuthenticationErrors.authuser_phoneconfirmed_empty); + V.ifEmpty(model.getName(), AuthenticationErrors.authuser_name_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + + var authentication = AppModules.authentication.getController(); + var authUserStore = authentication.getAuthUserStore(); + + // edit + entity = authUserStore.ensure(getContext(), argModel, AuthenticationErrors.authuser_notfound); + + editEntity(); + + entity = saveEntity(); + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private void editEntity() { + + var model = getArgument().getEntity(); + + // fields + entity.setExternalId(V.firstNotEmpty(model.getExternalId(), entity.getExternalId())); + entity.setEntityKey(V.firstNotEmpty(model.getEntityKey(), entity.getEntityKey())); + entity.setCustom(V.firstNotEmpty(model.isCustom(), entity.isCustom())); + entity.setVisible(V.firstNotEmpty(model.isVisible(), entity.isVisible())); + entity.setEmail(V.firstNotEmpty(model.getEmail(), entity.getEmail())); + entity.setEmailConfirmed(V.firstNotEmpty(model.isEmailConfirmed(), entity.isEmailConfirmed())); + entity.setPhone(V.firstNotEmpty(model.getPhone(), entity.getPhone())); + entity.setPhoneConfirmed(V.firstNotEmpty(model.isPhoneConfirmed(), entity.isPhoneConfirmed())); + entity.setName(V.firstNotEmpty(model.getName(), entity.getName())); + + + } + + // ::: save + // + private AuthUserEntity saveEntity() { + + var store = AppModules.authentication.getController().getAuthUserStore(); + + var saved = store.edit(getContext(), entity); + getContext().attach(saved.getId(), saved); + return saved; + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserEditArgument.java b/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserEditArgument.java new file mode 100644 index 0000000..6dbeae1 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserEditArgument.java @@ -0,0 +1,32 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.action.authuser; + +// app +import io.kumare.iqr.mod.authentication.store.authuser.AuthUserEntity; + +/** + * + * @author afatecha + */ +public class AuthUserEditArgument extends AuthUserActionArgument { + + // ::: vars + // + + + // ::: constructors + // + public AuthUserEditArgument() { + } + + public AuthUserEditArgument(AuthUserEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserEnableAction.java b/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserEnableAction.java new file mode 100644 index 0000000..6e0f8de --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserEnableAction.java @@ -0,0 +1,60 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.action.authuser; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.authentication.AuthenticationErrors; +// entity +import io.kumare.iqr.mod.authentication.store.authuser.AuthUserEntity; + + +/** + * + * @author afatecha + */ +public class AuthUserEnableAction extends AppAction { + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), AuthenticationErrors.authuser_notfound); + V.ifNull(getArgument().getEntity().getId(), AuthenticationErrors.authuser_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + + enableEntity(model); + } + + @Override + protected void setResultOnly() { + } + + // ::: enable + // + private void enableEntity(AuthUserEntity model) { + + var store = AppModules.authentication.getController().getAuthUserStore(); + + if (getArgument().getEntity().isActive()) { + store.enableById(getContext(), model.getId()); + } else { + store.disableById(getContext(), model.getId()); + } + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserFindAction.java b/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserFindAction.java new file mode 100644 index 0000000..126471c --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserFindAction.java @@ -0,0 +1,64 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.action.authuser; + +// java +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.authentication.AuthenticationErrors; +// entity +import io.kumare.iqr.mod.authentication.store.authuser.AuthUserEntity; + + +/** + * + * @author afatecha + */ +public class AuthUserFindAction extends AppAction { + + // ::: vars + // + private AuthUserEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), AuthenticationErrors.authuser_notfound); + V.ifNull(getArgument().getEntity().getId(), AuthenticationErrors.authuser_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + entity = findEntity(model); + } + + @Override + protected void setResultOnly() { + var result = new HashMap(); + result.put("entity", entity); + setResult(result); + } + + // ::: find + // + private AuthUserEntity findEntity(AuthUserEntity model) { + + var store = AppModules.authentication.getController().getAuthUserStore(); + return store.findById(getContext(), model.getId()); + } + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserListAction.java b/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserListAction.java new file mode 100644 index 0000000..1937780 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserListAction.java @@ -0,0 +1,148 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.action.authuser; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.LinkedList; +import java.util.Map; +// spring +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// entity +import io.kumare.iqr.mod.authentication.store.authuser.AuthUserEntity; +import io.kumare.iqr.mod.authentication.store.authuser.AuthUserMapBuilder; + + +/** + * + * @author afatecha + */ +public class AuthUserListAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private final List entities = new LinkedList<>(); + + // ::: public api + // + public List getEntities() { + return entities; + } + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + } + + @Override + protected void doAction() { + + result.put("pageable", getArgument().isPageable()); + result.put("wrapped", getArgument().isWrapped()); + + if (getArgument().isPageable()) { + + var page = makePage(); + entities.addAll(page.toList()); + + if (getArgument().isWrapped()) { + result.put("page", makeWrappedPage(page)); + } else { + result.put("page", page); + } + + } else { + + var list = makeList(); + entities.addAll(list); + + if (getArgument().isWrapped()) { + result.put("list", makeWrappedList()); + } else { + result.put("list", list); + } + } + + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: page + // + private Page makePage() { + + var page = getArgument().getPageNumber(); + var size = getArgument().getPageSize(); + //var sort = getArgument().getSort(); + + var pageable = PageRequest.of(page, size); + + var store = AppModules.authentication.getController().getAuthUserStore(); + return store.getRepository().findAll(pageable); + } + + // ::: wrapped page + // + private Map makeWrappedPage(Page found) { + + var page = new HashMap(); + var content = new LinkedList(); + + wrapList(entities, content); + + page.put("size", found.getSize()); + page.put("number", found.getNumber()); + page.put("totalElements", found.getTotalElements()); + page.put("totalPages", found.getTotalPages()); + page.put("content", content); + + return page; + } + + + // ::: list + // + + private List makeList() { + + var store = AppModules.authentication.getController().getAuthUserStore(); + + return store.listAll(getContext()); + } + + // ::: wrapped list + private List makeWrappedList() { + var list = new LinkedList(); + + wrapList(entities, list); + + return list; + } + + // ::: wrapper + // + private void wrapList(List found, List output) { + + var builder = new AuthUserMapBuilder().addListGroup(); + + + output.addAll(builder.build(getContext(), found)); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserListArgument.java b/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserListArgument.java new file mode 100644 index 0000000..31b12e5 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserListArgument.java @@ -0,0 +1,33 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.action.authuser; + +// app +import io.kumare.iqr.app.action.AppListActionArgument; +// store +import io.kumare.iqr.mod.authentication.store.authuser.AuthUserEntity; + +/** + * + * @author afatecha + */ +public class AuthUserListArgument extends AppListActionArgument { + + // ::: vars + // + + // ::: constructors + // + public AuthUserListArgument() { + } + + public AuthUserListArgument(AuthUserEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserPreloadAction.java b/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserPreloadAction.java new file mode 100644 index 0000000..0fcd2ba --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserPreloadAction.java @@ -0,0 +1,101 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.action.authuser; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.authentication.AuthenticationErrors; +// entity +import io.kumare.iqr.mod.authentication.store.authuser.AuthUserEntity; +// relations + + +/** + * + * @author afatecha + */ +public class AuthUserPreloadAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private Map params = new HashMap<>(); + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifEmpty(getArgument().getAction(), AuthenticationErrors.authuser_preload_empty); + } + + @Override + protected void doAction() { + if(getArgument().getParams() != null) { + params = getArgument().getParams(); + } + + switch (getArgument().getAction()) { + case "find" -> + prepareFind(); + case "list" -> + prepareList(); + case "add" -> + prepareAdd(); + case "edit" -> + prepareEdit(); + } + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: preload + // + private void prepareAdd() { + + } + + private void prepareEdit() { + var entity = findEntity(); + result.put("entity", entity); + + } + + private void prepareList() { + } + + private void prepareFind() { + var entity = findEntity(); + result.put("entity", entity); + + } + + // ::: queries + // + private AuthUserEntity findEntity() { + var store = AppModules.authentication.getController().getAuthUserStore(); + + var id = (String) params.get("id"); + if(id == null && getArgument().getEntity() != null) { + id = getArgument().getEntity().getId(); + } + return store.findById(getContext(), id); + } + + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserPreloadArgument.java b/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserPreloadArgument.java new file mode 100644 index 0000000..b4ddf7a --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/action/authuser/AuthUserPreloadArgument.java @@ -0,0 +1,26 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.action.authuser; + +/** + * + * @author afatecha + */ +public class AuthUserPreloadArgument extends AuthUserActionArgument { + + // ::: vars + // + private String action; + + // ::: fields + // + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationActionArgument.java b/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationActionArgument.java new file mode 100644 index 0000000..d93e0cc --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationActionArgument.java @@ -0,0 +1,29 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.action.authuserrelation; + +// base +import io.kumare.iqr.app.action.AppEntityActionArgument; +// entity +import io.kumare.iqr.mod.authentication.store.authuserrelation.AuthUserRelationEntity; + +/** + * + * @author afatecha + */ +public class AuthUserRelationActionArgument extends AppEntityActionArgument { + + // ::: constructors + // + public AuthUserRelationActionArgument() { + } + + public AuthUserRelationActionArgument(AuthUserRelationEntity entity) { + super(entity); + } + + // ::: api + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationAddAction.java b/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationAddAction.java new file mode 100644 index 0000000..b144358 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationAddAction.java @@ -0,0 +1,123 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.action.authuserrelation; + + +// lib +import io.kumare.lib.base.server.spring.action.Actions; +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.authentication.AuthenticationErrors; +// entity +import io.kumare.iqr.mod.authentication.store.authuserrelation.AuthUserRelationEntity; +import io.kumare.iqr.mod.authentication.store.authuser.AuthUserEntity; + + +/** + * + * @author afatecha + */ +public class AuthUserRelationAddAction extends AppAction> { + + // ::: vars + // + private AuthUserRelationEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, AuthenticationErrors.authuserrelation_notfound); + + // relations + V.ifNull(model.getAuthUser(), AuthenticationErrors.authuserrelation_authuser_notfound); + + // fields + V.ifEmpty(model.getExternalId(), AuthenticationErrors.authuserrelation_externalid_empty); + V.ifEmpty(model.getUserKey(), AuthenticationErrors.authuserrelation_userkey_empty); + V.ifEmpty(model.getTypeValue(), AuthenticationErrors.authuserrelation_typevalue_empty); + V.ifEmpty(model.getResourceType(), AuthenticationErrors.authuserrelation_resourcetype_empty); + V.ifEmpty(model.getResourceKey(), AuthenticationErrors.authuserrelation_resourcekey_empty); + V.ifEmpty(model.getResourceId(), AuthenticationErrors.authuserrelation_resourceid_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + var authentication = AppModules.authentication.getController(); + + var authUserStore = authentication.getAuthUserStore(); + + var authUser = authUserStore.ensure(getContext(), argModel.getAuthUser(), AuthenticationErrors.authuserrelation_authuser_notfound); + + // model + var model = makeModel(authUser); + + // add + entity = saveEntity(model); + + // add others + + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private AuthUserRelationEntity makeModel(AuthUserEntity authUser) { + + var argModel = getArgument().getEntity(); + var model = new AuthUserRelationEntity(); + + // relations + model.setAuthUser(authUser); + + // fields + model.setExternalId(argModel.getExternalId()); + model.setUserKey(argModel.getUserKey()); + model.setTypeValue(argModel.getTypeValue()); + model.setResourceType(argModel.getResourceType()); + model.setResourceKey(argModel.getResourceKey()); + model.setResourceId(argModel.getResourceId()); + model.setActive(true); + + + + return model; + } + + // ::: save + // + private AuthUserRelationEntity saveEntity(AuthUserRelationEntity model) { + + var store = AppModules.authentication.getController().getAuthUserRelationStore(); + + var saved = store.add(getContext(), model); + getContext().attach(saved.getId(), saved); + return saved; + } + + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationAddArgument.java b/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationAddArgument.java new file mode 100644 index 0000000..78cd768 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationAddArgument.java @@ -0,0 +1,34 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.action.authuserrelation; + + +// app +import io.kumare.iqr.mod.authentication.store.authuserrelation.AuthUserRelationEntity; + + +/** + * + * @author afatecha + */ +public class AuthUserRelationAddArgument extends AuthUserRelationActionArgument { + + // ::: vars + // + + + // ::: constructors + // + public AuthUserRelationAddArgument() { + } + + public AuthUserRelationAddArgument(AuthUserRelationEntity entity) { + super(entity); + } + + // ::: fields + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationDeleteAction.java b/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationDeleteAction.java new file mode 100644 index 0000000..45096da --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationDeleteAction.java @@ -0,0 +1,59 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.action.authuserrelation; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.authentication.AuthenticationErrors; +// entity +import io.kumare.iqr.mod.authentication.store.authuserrelation.AuthUserRelationEntity; + +/** + * + * @author afatecha + */ +public class AuthUserRelationDeleteAction extends AppAction> { + + // ::: vars + // + private AuthUserRelationEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), AuthenticationErrors.authuserrelation_notfound); + V.ifNull(getArgument().getEntity().getId(), AuthenticationErrors.authuserrelation_notfound); + } + + @Override + protected void doAction() { + + var argModel = getArgument().getEntity(); + + deleteEntity(argModel); + } + + @Override + protected void setResultOnly() { + } + + // ::: delete + // + private void deleteEntity(AuthUserRelationEntity model) { + + var store = AppModules.authentication.getController().getAuthUserRelationStore(); + + store.deleteById(getContext(), model.getId()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationEditAction.java b/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationEditAction.java new file mode 100644 index 0000000..5e9ac7b --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationEditAction.java @@ -0,0 +1,103 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.action.authuserrelation; + +// lib +import io.kumare.lib.v.V; +// app +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.authentication.AuthenticationErrors; +// entity +import io.kumare.iqr.mod.authentication.store.authuserrelation.AuthUserRelationEntity; + +/** + * + * @author afatecha + */ +public class AuthUserRelationEditAction extends AppAction> { + + // ::: vars + // + private AuthUserRelationEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, AuthenticationErrors.authuserrelation_notfound); + + // fields + V.ifEmpty(model.getExternalId(), AuthenticationErrors.authuserrelation_externalid_empty); + V.ifEmpty(model.getUserKey(), AuthenticationErrors.authuserrelation_userkey_empty); + V.ifEmpty(model.getTypeValue(), AuthenticationErrors.authuserrelation_typevalue_empty); + V.ifEmpty(model.getResourceType(), AuthenticationErrors.authuserrelation_resourcetype_empty); + V.ifEmpty(model.getResourceKey(), AuthenticationErrors.authuserrelation_resourcekey_empty); + V.ifEmpty(model.getResourceId(), AuthenticationErrors.authuserrelation_resourceid_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + + var authentication = AppModules.authentication.getController(); + var authUserRelationStore = authentication.getAuthUserRelationStore(); + + // edit + entity = authUserRelationStore.ensure(getContext(), argModel, AuthenticationErrors.authuserrelation_notfound); + + editEntity(); + + entity = saveEntity(); + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private void editEntity() { + + var model = getArgument().getEntity(); + + // fields + entity.setExternalId(V.firstNotEmpty(model.getExternalId(), entity.getExternalId())); + entity.setUserKey(V.firstNotEmpty(model.getUserKey(), entity.getUserKey())); + entity.setTypeValue(V.firstNotEmpty(model.getTypeValue(), entity.getTypeValue())); + entity.setResourceType(V.firstNotEmpty(model.getResourceType(), entity.getResourceType())); + entity.setResourceKey(V.firstNotEmpty(model.getResourceKey(), entity.getResourceKey())); + entity.setResourceId(V.firstNotEmpty(model.getResourceId(), entity.getResourceId())); + + + } + + // ::: save + // + private AuthUserRelationEntity saveEntity() { + + var store = AppModules.authentication.getController().getAuthUserRelationStore(); + + var saved = store.edit(getContext(), entity); + getContext().attach(saved.getId(), saved); + return saved; + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationEditArgument.java b/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationEditArgument.java new file mode 100644 index 0000000..f1755bb --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationEditArgument.java @@ -0,0 +1,32 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.action.authuserrelation; + +// app +import io.kumare.iqr.mod.authentication.store.authuserrelation.AuthUserRelationEntity; + +/** + * + * @author afatecha + */ +public class AuthUserRelationEditArgument extends AuthUserRelationActionArgument { + + // ::: vars + // + + + // ::: constructors + // + public AuthUserRelationEditArgument() { + } + + public AuthUserRelationEditArgument(AuthUserRelationEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationEnableAction.java b/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationEnableAction.java new file mode 100644 index 0000000..ddbbc0a --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationEnableAction.java @@ -0,0 +1,60 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.action.authuserrelation; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.authentication.AuthenticationErrors; +// entity +import io.kumare.iqr.mod.authentication.store.authuserrelation.AuthUserRelationEntity; + + +/** + * + * @author afatecha + */ +public class AuthUserRelationEnableAction extends AppAction { + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), AuthenticationErrors.authuserrelation_notfound); + V.ifNull(getArgument().getEntity().getId(), AuthenticationErrors.authuserrelation_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + + enableEntity(model); + } + + @Override + protected void setResultOnly() { + } + + // ::: enable + // + private void enableEntity(AuthUserRelationEntity model) { + + var store = AppModules.authentication.getController().getAuthUserRelationStore(); + + if (getArgument().getEntity().isActive()) { + store.enableById(getContext(), model.getId()); + } else { + store.disableById(getContext(), model.getId()); + } + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationFindAction.java b/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationFindAction.java new file mode 100644 index 0000000..fb84b8a --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationFindAction.java @@ -0,0 +1,64 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.action.authuserrelation; + +// java +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.authentication.AuthenticationErrors; +// entity +import io.kumare.iqr.mod.authentication.store.authuserrelation.AuthUserRelationEntity; + + +/** + * + * @author afatecha + */ +public class AuthUserRelationFindAction extends AppAction { + + // ::: vars + // + private AuthUserRelationEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), AuthenticationErrors.authuserrelation_notfound); + V.ifNull(getArgument().getEntity().getId(), AuthenticationErrors.authuserrelation_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + entity = findEntity(model); + } + + @Override + protected void setResultOnly() { + var result = new HashMap(); + result.put("entity", entity); + setResult(result); + } + + // ::: find + // + private AuthUserRelationEntity findEntity(AuthUserRelationEntity model) { + + var store = AppModules.authentication.getController().getAuthUserRelationStore(); + return store.findById(getContext(), model.getId()); + } + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationListAction.java b/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationListAction.java new file mode 100644 index 0000000..1a6e42d --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationListAction.java @@ -0,0 +1,148 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.action.authuserrelation; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.LinkedList; +import java.util.Map; +// spring +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// entity +import io.kumare.iqr.mod.authentication.store.authuserrelation.AuthUserRelationEntity; +import io.kumare.iqr.mod.authentication.store.authuserrelation.AuthUserRelationMapBuilder; + + +/** + * + * @author afatecha + */ +public class AuthUserRelationListAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private final List entities = new LinkedList<>(); + + // ::: public api + // + public List getEntities() { + return entities; + } + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + } + + @Override + protected void doAction() { + + result.put("pageable", getArgument().isPageable()); + result.put("wrapped", getArgument().isWrapped()); + + if (getArgument().isPageable()) { + + var page = makePage(); + entities.addAll(page.toList()); + + if (getArgument().isWrapped()) { + result.put("page", makeWrappedPage(page)); + } else { + result.put("page", page); + } + + } else { + + var list = makeList(); + entities.addAll(list); + + if (getArgument().isWrapped()) { + result.put("list", makeWrappedList()); + } else { + result.put("list", list); + } + } + + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: page + // + private Page makePage() { + + var page = getArgument().getPageNumber(); + var size = getArgument().getPageSize(); + //var sort = getArgument().getSort(); + + var pageable = PageRequest.of(page, size); + + var store = AppModules.authentication.getController().getAuthUserRelationStore(); + return store.getRepository().findAll(pageable); + } + + // ::: wrapped page + // + private Map makeWrappedPage(Page found) { + + var page = new HashMap(); + var content = new LinkedList(); + + wrapList(entities, content); + + page.put("size", found.getSize()); + page.put("number", found.getNumber()); + page.put("totalElements", found.getTotalElements()); + page.put("totalPages", found.getTotalPages()); + page.put("content", content); + + return page; + } + + + // ::: list + // + + private List makeList() { + + var store = AppModules.authentication.getController().getAuthUserRelationStore(); + + return store.listAll(getContext()); + } + + // ::: wrapped list + private List makeWrappedList() { + var list = new LinkedList(); + + wrapList(entities, list); + + return list; + } + + // ::: wrapper + // + private void wrapList(List found, List output) { + + var builder = new AuthUserRelationMapBuilder().addListGroup(); + builder.getAuthUserBuilder().addMainGroup(); + + output.addAll(builder.build(getContext(), found)); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationListArgument.java b/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationListArgument.java new file mode 100644 index 0000000..dcadf54 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationListArgument.java @@ -0,0 +1,33 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.action.authuserrelation; + +// app +import io.kumare.iqr.app.action.AppListActionArgument; +// store +import io.kumare.iqr.mod.authentication.store.authuserrelation.AuthUserRelationEntity; + +/** + * + * @author afatecha + */ +public class AuthUserRelationListArgument extends AppListActionArgument { + + // ::: vars + // + + // ::: constructors + // + public AuthUserRelationListArgument() { + } + + public AuthUserRelationListArgument(AuthUserRelationEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationPreloadAction.java b/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationPreloadAction.java new file mode 100644 index 0000000..ab6a221 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationPreloadAction.java @@ -0,0 +1,105 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.action.authuserrelation; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.authentication.AuthenticationErrors; +// entity +import io.kumare.iqr.mod.authentication.store.authuserrelation.AuthUserRelationEntity; +// relations +import io.kumare.iqr.mod.authentication.store.authuser.AuthUserEntity; + +/** + * + * @author afatecha + */ +public class AuthUserRelationPreloadAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private Map params = new HashMap<>(); + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifEmpty(getArgument().getAction(), AuthenticationErrors.authuserrelation_preload_empty); + } + + @Override + protected void doAction() { + if(getArgument().getParams() != null) { + params = getArgument().getParams(); + } + + switch (getArgument().getAction()) { + case "find" -> + prepareFind(); + case "list" -> + prepareList(); + case "add" -> + prepareAdd(); + case "edit" -> + prepareEdit(); + } + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: preload + // + private void prepareAdd() { + result.put("authUsers", listAuthUsers()); + } + + private void prepareEdit() { + var entity = findEntity(); + result.put("entity", entity); + result.put("authUser", entity.getAuthUser()); + } + + private void prepareList() { + } + + private void prepareFind() { + var entity = findEntity(); + result.put("entity", entity); + result.put("authUser", entity.getAuthUser()); + } + + // ::: queries + // + private AuthUserRelationEntity findEntity() { + var store = AppModules.authentication.getController().getAuthUserRelationStore(); + + var id = (String) params.get("id"); + if(id == null && getArgument().getEntity() != null) { + id = getArgument().getEntity().getId(); + } + return store.findById(getContext(), id); + } + + public List listAuthUsers() { + var store = AppModules.authentication.getController().getAuthUserStore(); + + return store.listAll(getContext()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationPreloadArgument.java b/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationPreloadArgument.java new file mode 100644 index 0000000..b91ecc9 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/action/authuserrelation/AuthUserRelationPreloadArgument.java @@ -0,0 +1,26 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.action.authuserrelation; + +/** + * + * @author afatecha + */ +public class AuthUserRelationPreloadArgument extends AuthUserRelationActionArgument { + + // ::: vars + // + private String action; + + // ::: fields + // + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/endpoint/rest/AbstractAuthUserRelationRest.java b/src/main/java/io/kumare/iqr/mod/authentication/endpoint/rest/AbstractAuthUserRelationRest.java new file mode 100644 index 0000000..7928b85 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/endpoint/rest/AbstractAuthUserRelationRest.java @@ -0,0 +1,214 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.endpoint.rest; + +// java +import java.util.Map; +// openapi +import io.swagger.v3.oas.annotations.*; +import io.swagger.v3.oas.annotations.media.*; +import io.swagger.v3.oas.annotations.responses.*; +// spring +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +// base +import io.kumare.lib.app.api.operation.TransactionType; +import io.kumare.lib.app.api.security.PermissionReference; +// app +import io.kumare.iqr.app.endpoint.rest.AppEndpointRest; +import io.kumare.iqr.app.action.*; +// module +import io.kumare.iqr.mod.authentication.AuthenticationPermissions; +import io.kumare.iqr.mod.authentication.store.authuserrelation.AuthUserRelationEntity; +import io.kumare.iqr.mod.authentication.action.authuserrelation.*; + +/** +* +* @author afatecha +*/ +public abstract class AbstractAuthUserRelationRest extends AppEndpointRest { + + // ::: DEFAULT PERMISSIONS + // + protected PermissionReference getPermission(String action, String ref, Object extra) { + switch (action) { + case null -> { + return null; + } + case "add" -> { + return AuthenticationPermissions.auth_user_relation_worker.toReference(ref); + } + case "edit" -> { + return AuthenticationPermissions.auth_user_relation_worker.toReference(ref); + } + case "enable" -> { + return AuthenticationPermissions.auth_user_relation_manager.toReference(ref); + } + case "disable" -> { + return AuthenticationPermissions.auth_user_relation_manager.toReference(ref); + } + case "delete" -> { + return AuthenticationPermissions.auth_user_relation_manager.toReference(ref); + } + case "find" -> { + return AuthenticationPermissions.auth_user_relation_viewer.toReference(ref); + } + case "list" -> { + return AuthenticationPermissions.auth_user_relation_viewer.toReference(ref); + } + default -> { + return null; + } + } + } + + + // ::: ADD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "auth user relation add operation", description = "") + // + @PostMapping + public ResponseEntity add(@RequestBody AuthUserRelationAddArgument arg) { + + var permission = getPermission("add", null, arg); + return handle(new AuthUserRelationAddAction(), arg, permission, TransactionType.service); + } + + // ::: EDIT + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "auth user relation edit operation", description = "") + // + @PutMapping("/{id}") + public ResponseEntity edit(@PathVariable("id") String id, + @RequestBody AuthUserRelationEditArgument arg) { + + arg.getEntity().id(id); + + var permission = getPermission("edit", id, arg); + return handle(new AuthUserRelationEditAction(), arg, permission, TransactionType.service); + } + + // ::: FIND + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "auth user relation find operation", description = "") + // + @GetMapping("/{id}") + public ResponseEntity find(@PathVariable("id") String id, + @ModelAttribute AuthUserRelationActionArgument arg) { + + + arg = arg == null ? new AuthUserRelationActionArgument() : arg; + + arg.entity(new AuthUserRelationEntity(id)); + + var permission = getPermission("find", id, arg); + return handle(new AuthUserRelationFindAction(), arg, permission); + } + + // ::: ENABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "auth user relation enable operation", description = "") + // + @PutMapping("/{id}/enable") + public ResponseEntity enable(@PathVariable("id") String id) { + + var arg = new AuthUserRelationActionArgument(); + arg.setEntity(new AuthUserRelationEntity(id)); + arg.getEntity().setActive(true); + + var permission = getPermission("disable", id, arg); + return handle(new AuthUserRelationEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: DISABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "auth user relation disable operation", description = "") + // + @PutMapping("/{id}/disable") + public ResponseEntity disable(@PathVariable("id") String id) { + + var arg = new AuthUserRelationActionArgument(); + arg.setEntity(new AuthUserRelationEntity(id)); + arg.getEntity().setActive(false); + + var permission = getPermission("disable", id, arg); + return handle(new AuthUserRelationEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: LIST + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "auth user relation list operation", description = "") + // + @GetMapping + public ResponseEntity list(@ModelAttribute AuthUserRelationListArgument arg) { + + arg = arg == null ? new AuthUserRelationListArgument() : arg; + + var permission = getPermission("list", null, arg); + return handle(new AuthUserRelationListAction(), arg, permission); + } + + // ::: DELETE + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "auth user relation delete operation", description = "") + // + @DeleteMapping("/{id}") + public ResponseEntity delete(@PathVariable("id") String id) { + + var arg = new AuthUserRelationActionArgument(); + + arg.setEntity(new AuthUserRelationEntity(id)); + + var permission = getPermission("delete", id, arg); + return handle(new AuthUserRelationDeleteAction(), arg, permission, TransactionType.service); + } + + // ::: PRELOAD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "auth user relation preload operation", description = "") + // + @PostMapping("/preload") + public ResponseEntity preload(@RequestBody AuthUserRelationPreloadArgument arg) { + + var permission = getPermission(arg.getAction(), null, arg); + return handle(new AuthUserRelationPreloadAction(), arg, permission); + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/endpoint/rest/AbstractAuthUserRest.java b/src/main/java/io/kumare/iqr/mod/authentication/endpoint/rest/AbstractAuthUserRest.java new file mode 100644 index 0000000..6c68580 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/endpoint/rest/AbstractAuthUserRest.java @@ -0,0 +1,214 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.endpoint.rest; + +// java +import java.util.Map; +// openapi +import io.swagger.v3.oas.annotations.*; +import io.swagger.v3.oas.annotations.media.*; +import io.swagger.v3.oas.annotations.responses.*; +// spring +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +// base +import io.kumare.lib.app.api.operation.TransactionType; +import io.kumare.lib.app.api.security.PermissionReference; +// app +import io.kumare.iqr.app.endpoint.rest.AppEndpointRest; +import io.kumare.iqr.app.action.*; +// module +import io.kumare.iqr.mod.authentication.AuthenticationPermissions; +import io.kumare.iqr.mod.authentication.store.authuser.AuthUserEntity; +import io.kumare.iqr.mod.authentication.action.authuser.*; + +/** +* +* @author afatecha +*/ +public abstract class AbstractAuthUserRest extends AppEndpointRest { + + // ::: DEFAULT PERMISSIONS + // + protected PermissionReference getPermission(String action, String ref, Object extra) { + switch (action) { + case null -> { + return null; + } + case "add" -> { + return AuthenticationPermissions.auth_user_worker.toReference(ref); + } + case "edit" -> { + return AuthenticationPermissions.auth_user_worker.toReference(ref); + } + case "enable" -> { + return AuthenticationPermissions.auth_user_manager.toReference(ref); + } + case "disable" -> { + return AuthenticationPermissions.auth_user_manager.toReference(ref); + } + case "delete" -> { + return AuthenticationPermissions.auth_user_manager.toReference(ref); + } + case "find" -> { + return AuthenticationPermissions.auth_user_viewer.toReference(ref); + } + case "list" -> { + return AuthenticationPermissions.auth_user_viewer.toReference(ref); + } + default -> { + return null; + } + } + } + + + // ::: ADD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "auth user add operation", description = "") + // + @PostMapping + public ResponseEntity add(@RequestBody AuthUserAddArgument arg) { + + var permission = getPermission("add", null, arg); + return handle(new AuthUserAddAction(), arg, permission, TransactionType.service); + } + + // ::: EDIT + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "auth user edit operation", description = "") + // + @PutMapping("/{id}") + public ResponseEntity edit(@PathVariable("id") String id, + @RequestBody AuthUserEditArgument arg) { + + arg.getEntity().id(id); + + var permission = getPermission("edit", id, arg); + return handle(new AuthUserEditAction(), arg, permission, TransactionType.service); + } + + // ::: FIND + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "auth user find operation", description = "") + // + @GetMapping("/{id}") + public ResponseEntity find(@PathVariable("id") String id, + @ModelAttribute AuthUserActionArgument arg) { + + + arg = arg == null ? new AuthUserActionArgument() : arg; + + arg.entity(new AuthUserEntity(id)); + + var permission = getPermission("find", id, arg); + return handle(new AuthUserFindAction(), arg, permission); + } + + // ::: ENABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "auth user enable operation", description = "") + // + @PutMapping("/{id}/enable") + public ResponseEntity enable(@PathVariable("id") String id) { + + var arg = new AuthUserActionArgument(); + arg.setEntity(new AuthUserEntity(id)); + arg.getEntity().setActive(true); + + var permission = getPermission("disable", id, arg); + return handle(new AuthUserEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: DISABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "auth user disable operation", description = "") + // + @PutMapping("/{id}/disable") + public ResponseEntity disable(@PathVariable("id") String id) { + + var arg = new AuthUserActionArgument(); + arg.setEntity(new AuthUserEntity(id)); + arg.getEntity().setActive(false); + + var permission = getPermission("disable", id, arg); + return handle(new AuthUserEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: LIST + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "auth user list operation", description = "") + // + @GetMapping + public ResponseEntity list(@ModelAttribute AuthUserListArgument arg) { + + arg = arg == null ? new AuthUserListArgument() : arg; + + var permission = getPermission("list", null, arg); + return handle(new AuthUserListAction(), arg, permission); + } + + // ::: DELETE + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "auth user delete operation", description = "") + // + @DeleteMapping("/{id}") + public ResponseEntity delete(@PathVariable("id") String id) { + + var arg = new AuthUserActionArgument(); + + arg.setEntity(new AuthUserEntity(id)); + + var permission = getPermission("delete", id, arg); + return handle(new AuthUserDeleteAction(), arg, permission, TransactionType.service); + } + + // ::: PRELOAD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "auth user preload operation", description = "") + // + @PostMapping("/preload") + public ResponseEntity preload(@RequestBody AuthUserPreloadArgument arg) { + + var permission = getPermission(arg.getAction(), null, arg); + return handle(new AuthUserPreloadAction(), arg, permission); + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/endpoint/rest/AuthUserRelationRest.java b/src/main/java/io/kumare/iqr/mod/authentication/endpoint/rest/AuthUserRelationRest.java new file mode 100644 index 0000000..3e6405b --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/endpoint/rest/AuthUserRelationRest.java @@ -0,0 +1,24 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.endpoint.rest; + +// java +import io.swagger.v3.oas.annotations.tags.*; +// spring +import org.springframework.web.bind.annotation.*; + +/** +* +* @author afatecha +*/ + +// openapi +//@Tag(name = "auth user relation rest endpoint") +// +//@RestController +//@RequestMapping("/authentication/auth-user-relations") +public class AuthUserRelationRest extends AbstractAuthUserRelationRest { + + +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/endpoint/rest/AuthUserRest.java b/src/main/java/io/kumare/iqr/mod/authentication/endpoint/rest/AuthUserRest.java new file mode 100644 index 0000000..fe7d39a --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/endpoint/rest/AuthUserRest.java @@ -0,0 +1,24 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.endpoint.rest; + +// java +import io.swagger.v3.oas.annotations.tags.*; +// spring +import org.springframework.web.bind.annotation.*; + +/** +* +* @author afatecha +*/ + +// openapi +//@Tag(name = "auth user rest endpoint") +// +//@RestController +//@RequestMapping("/authentication/auth-users") +public class AuthUserRest extends AbstractAuthUserRest { + + +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/store/AuthenticationEntities.java b/src/main/java/io/kumare/iqr/mod/authentication/store/AuthenticationEntities.java new file mode 100644 index 0000000..d6d3e6b --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/store/AuthenticationEntities.java @@ -0,0 +1,102 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.store; + +// base +// base +import io.kumare.lib.app.api.module.ServiceModule; +import io.kumare.lib.app.api.store.EntityStore; +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app +import io.kumare.iqr.app.AppEngine; +import io.kumare.iqr.app.module.AppModules; +import io.kumare.iqr.mod.authentication.store.authuser.AuthUserEntity; +import io.kumare.iqr.mod.authentication.store.authuser.AuthUserStore; +import io.kumare.iqr.mod.authentication.store.authuserrelation.AuthUserRelationEntity; +import io.kumare.iqr.mod.authentication.store.authuserrelation.AuthUserRelationStore; + + +/** + * + * @author afatecha + */ +public enum AuthenticationEntities implements EntityDescriptor { + + authUser(AuthUserEntity.class, AuthUserStore.class), + authUserRelation(AuthUserRelationEntity.class, AuthUserRelationStore.class); + + // ::: vars + // + private final Class entityClass; + private final Class storeClass; + + // ::: constructor + // + AuthenticationEntities(Class entityClass, Class storeClass) { + this.entityClass = entityClass; + this.storeClass = storeClass; + } + + // ::: entity descriptor api + // + @Override + public String getName() { + return name(); + } + + @Override + public ServiceModule getModule() { + return AppModules.authentication; + } + + @Override + public Class getEntityClass() { + return entityClass; + } + + @Override + public Class getStoreClass() { + return storeClass; + } + + @Override + public EntityStore getStore() { + return (EntityStore) AppEngine.getEngine().getInnerContext().getBean(storeClass); + } + + // ::: statics + // + public static boolean hasDescriptor(String name) { + try { + var value = valueOf(name); + return value != null; + + } catch (Throwable t) { + return false; + } + } + + public static EntityDescriptor descriptorOf(String name) { + try { + return valueOf(name); + + } catch (Throwable t) { + return null; + } + } + + public static EntityDescriptor descriptorOf(Class entityClass) { + try { + for (var i : values()) { + if (i.entityClass == entityClass) { + return i; + } + } + + } catch (Throwable t) { + } + + return null; + } +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/store/authuser/AuthUserData.java b/src/main/java/io/kumare/iqr/mod/authentication/store/authuser/AuthUserData.java new file mode 100644 index 0000000..a77d4bd --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/store/authuser/AuthUserData.java @@ -0,0 +1,25 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.store.authuser; + +// base +import io.kumare.iqr.app.store.AppExtendedEntityData; +// imports + + +public class AuthUserData extends AppExtendedEntityData { + + // ::: vars + // + + + // ::: fields + // + + + // ::: fluent + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/store/authuser/AuthUserEntity.java b/src/main/java/io/kumare/iqr/mod/authentication/store/authuser/AuthUserEntity.java new file mode 100644 index 0000000..d7febb2 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/store/authuser/AuthUserEntity.java @@ -0,0 +1,179 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.store.authuser; + +// jakarta +import jakarta.persistence.Entity; +import jakarta.persistence.Index; +import jakarta.persistence.Table; +// base +import io.kumare.lib.app.api.store.*; +import io.kumare.iqr.app.store.*; +// imports + +// relations +// annotations +@Entity +@Table( + name = "auth_user", + indexes = { + @Index(name = "idx_auth_user_external_id", columnList = "externalId"), + @Index(name = "idx_auth_user_entity_key", columnList = "entityKey"), + @Index(name = "idx_auth_user_custom", columnList = "custom"), + @Index(name = "idx_auth_user_visible", columnList = "visible"), + @Index(name = "idx_auth_user_email", columnList = "email"), + @Index(name = "idx_auth_user_email_confirmed", columnList = "emailConfirmed"), + @Index(name = "idx_auth_user_phone", columnList = "phone"), + @Index(name = "idx_auth_user_phone_confirmed", columnList = "phoneConfirmed"), + @Index(name = "idx_auth_user_name", columnList = "name") + } +) +public class AuthUserEntity extends AppEntity implements SupportedEntityKey { + + // ::: vars + // + private String externalId; + private String entityKey; + private boolean custom; + private boolean visible; + private String email; + private boolean emailConfirmed; + private String phone; + private boolean phoneConfirmed; + private String name; + // relations + + // ::: constructors + // + public AuthUserEntity() { + } + + public AuthUserEntity(String id) { + super(id); + } + + // ::: fields + // + public String getExternalId() { + return externalId; + } + + public void setExternalId(String externalId) { + this.externalId = externalId; + } + + public String getEntityKey() { + return entityKey; + } + + public void setEntityKey(String entityKey) { + this.entityKey = entityKey; + } + + public boolean isCustom() { + return custom; + } + + public void setCustom(boolean custom) { + this.custom = custom; + } + + public boolean isVisible() { + return visible; + } + + public void setVisible(boolean visible) { + this.visible = visible; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public boolean isEmailConfirmed() { + return emailConfirmed; + } + + public void setEmailConfirmed(boolean emailConfirmed) { + this.emailConfirmed = emailConfirmed; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public boolean isPhoneConfirmed() { + return phoneConfirmed; + } + + public void setPhoneConfirmed(boolean phoneConfirmed) { + this.phoneConfirmed = phoneConfirmed; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + // relations + // ::: fluent + // + public AuthUserEntity externalId(String externalId) { + setExternalId(externalId); + return this; + } + + public AuthUserEntity entityKey(String entityKey) { + setEntityKey(entityKey); + return this; + } + + public AuthUserEntity custom(boolean custom) { + setCustom(custom); + return this; + } + + public AuthUserEntity visible(boolean visible) { + setVisible(visible); + return this; + } + + public AuthUserEntity email(String email) { + setEmail(email); + return this; + } + + public AuthUserEntity emailConfirmed(boolean emailConfirmed) { + setEmailConfirmed(emailConfirmed); + return this; + } + + public AuthUserEntity phone(String phone) { + setPhone(phone); + return this; + } + + public AuthUserEntity phoneConfirmed(boolean phoneConfirmed) { + setPhoneConfirmed(phoneConfirmed); + return this; + } + + public AuthUserEntity name(String name) { + setName(name); + return this; + } + + // relations +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/store/authuser/AuthUserFields.java b/src/main/java/io/kumare/iqr/mod/authentication/store/authuser/AuthUserFields.java new file mode 100644 index 0000000..d5ae3f8 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/store/authuser/AuthUserFields.java @@ -0,0 +1,163 @@ +/* + */ +package io.kumare.iqr.mod.authentication.store.authuser; + +// java +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +// base +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app + + +/** + * + * @author afatecha + */ +public enum AuthUserFields implements EntityFieldDescriptor { + + id(MAIN, FIND, LIST), + externalId(MAIN, FIND, LIST), + entityKey(MAIN, FIND, LIST), + custom(MAIN, FIND, LIST), + visible(MAIN, FIND, LIST), + email(MAIN, FIND, LIST), + emailConfirmed(MAIN, FIND, LIST), + phone(MAIN, FIND, LIST), + phoneConfirmed(MAIN, FIND, LIST), + name(MAIN, FIND, LIST), + active(MAIN, FIND, LIST), + inserted(AUDIT, FIND, LIST), + inserter(AUDIT, FIND, LIST), + modified(AUDIT, FIND), + modifier(AUDIT, FIND), + deleted(AUDIT), + removed(AUDIT), + remover(AUDIT); + + // ::: vars + // + private final boolean relation; + private final EntityDescriptor entityDescriptor; + private final Class enumClass; + private final List groups; + + // ::: constructors + // + AuthUserFields(String... groups) { + this(false, null, null, groups); + } + + AuthUserFields(EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this(true, entityDescriptor, enumClass, groups); + } + + AuthUserFields(boolean relation, EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this.relation = relation; + this.entityDescriptor = entityDescriptor; + this.enumClass = enumClass; + this.groups = groups == null ? Collections.EMPTY_LIST : Arrays.asList(groups); + } + + // ::: api + // + @Override + public String getName() { + return name(); + } + + @Override + public boolean isRelation() { + return relation; + } + + @Override + public Class getRelationEnumClass() { + return enumClass; + } + + @Override + public List getGroups() { + return groups; + } + + @Override + public EntityDescriptor getEntityDescriptor() { + return entityDescriptor; + } + + @Override + public Object fetchValue(AuthUserEntity entity) { + if (entity == null) { + return null; + } + + switch (this) { + case null -> { + return null; + } + case id -> { + return entity.getId(); + } + case externalId ->{ + return entity.getExternalId(); + } + case entityKey ->{ + return entity.getEntityKey(); + } + case custom ->{ + return entity.isCustom(); + } + case visible ->{ + return entity.isVisible(); + } + case email ->{ + return entity.getEmail(); + } + case emailConfirmed ->{ + return entity.isEmailConfirmed(); + } + case phone ->{ + return entity.getPhone(); + } + case phoneConfirmed ->{ + return entity.isPhoneConfirmed(); + } + case name ->{ + return entity.getName(); + } + case active -> { + return entity.isActive(); + } + case inserted -> { + return entity.getInserted(); + } + case inserter -> { + return entity.getInserter(); + } + case modified -> { + return entity.getModified(); + } + case modifier -> { + return entity.getModifier(); + } + case deleted -> { + return entity.isDeleted(); + } + case removed -> { + return entity.getRemoved(); + } + case remover -> { + return entity.getRemover(); + } + + default -> { + return null; + } + } + + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/store/authuser/AuthUserMapBuilder.java b/src/main/java/io/kumare/iqr/mod/authentication/store/authuser/AuthUserMapBuilder.java new file mode 100644 index 0000000..8c9865a --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/store/authuser/AuthUserMapBuilder.java @@ -0,0 +1,93 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.store.authuser; + +// java +import java.util.List; +import java.util.Map; +// base +import io.kumare.lib.app.api.Context; +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.BaseEntityMapBuilder; +// app + + +/** + * + * @author afatecha + */ +public class AuthUserMapBuilder extends BaseEntityMapBuilder { + + // ::: vars + // + + + + // ::: fields + // + @Override + public AuthUserMapBuilder addGroup(String name, boolean cascade) { + includes.addAll(EntityFieldDescriptor.group(AuthUserFields.values(), name)); + + return this; + } + + @Override + public AuthUserMapBuilder add(String fieldName) { + includes.add(AuthUserFields.valueOf(fieldName)); + return this; + } + + @Override + public AuthUserMapBuilder addAll(String... names) { + for (var i : names) { + includes.add(AuthUserFields.valueOf(i)); + } + return this; + } + + @Override + public AuthUserMapBuilder remove(String fieldName) { + excludes.add(AuthUserFields.valueOf(fieldName)); + return this; + } + + @Override + public AuthUserMapBuilder removeAll(String... names) { + for (var i : names) { + excludes.add(AuthUserFields.valueOf(i)); + } + return this; + } + + // ::: relations + // + @Override + public AuthUserMapBuilder addPlains(boolean cascade) { + includes.addAll(EntityFieldDescriptor.plains(AuthUserFields.values())); + + return this; + } + + @Override + public AuthUserMapBuilder addRelations(boolean cascade) { + includes.addAll(EntityFieldDescriptor.relations(AuthUserFields.values())); + + return this; + } + + + + // ::: internals + // + @Override + protected void internalAttachRelations(Context context, + AuthUserEntity entity, + List fields, + Map resultMap) { + + + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/store/authuser/AuthUserRepository.java b/src/main/java/io/kumare/iqr/mod/authentication/store/authuser/AuthUserRepository.java new file mode 100644 index 0000000..16ce227 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/store/authuser/AuthUserRepository.java @@ -0,0 +1,18 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.store.authuser; + +// spring +import org.springframework.stereotype.Repository; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Repository +public interface AuthUserRepository extends AppKeyEntityRepository{ + +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/store/authuser/AuthUserStore.java b/src/main/java/io/kumare/iqr/mod/authentication/store/authuser/AuthUserStore.java new file mode 100644 index 0000000..5e900d4 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/store/authuser/AuthUserStore.java @@ -0,0 +1,35 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.store.authuser; + +// spring +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Service +public class AuthUserStore extends AppKeyEntityStore { + + // ::: vars + // + @Autowired + private AuthUserRepository repository; + + // ::: override + // + @Override + public AuthUserRepository getRepository() { + return repository; + } + + // ::: api + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/store/authuserrelation/AuthUserRelationData.java b/src/main/java/io/kumare/iqr/mod/authentication/store/authuserrelation/AuthUserRelationData.java new file mode 100644 index 0000000..7ad1af6 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/store/authuserrelation/AuthUserRelationData.java @@ -0,0 +1,25 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.store.authuserrelation; + +// base +import io.kumare.iqr.app.store.AppExtendedEntityData; +// imports + + +public class AuthUserRelationData extends AppExtendedEntityData { + + // ::: vars + // + + + // ::: fields + // + + + // ::: fluent + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/store/authuserrelation/AuthUserRelationEntity.java b/src/main/java/io/kumare/iqr/mod/authentication/store/authuserrelation/AuthUserRelationEntity.java new file mode 100644 index 0000000..e0798b2 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/store/authuserrelation/AuthUserRelationEntity.java @@ -0,0 +1,153 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.store.authuserrelation; + +// jakarta +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.Index; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +// base +import io.kumare.lib.app.api.store.*; +import io.kumare.iqr.app.store.*; +// imports + +// relations +import io.kumare.iqr.mod.authentication.store.authuser.AuthUserEntity; + +// annotations +@Entity +@Table( + name = "auth_user_relation", + indexes = { + @Index(name = "idx_auth_user_relation_external_id", columnList = "externalId"), + @Index(name = "idx_auth_user_relation_user_key", columnList = "userKey"), + @Index(name = "idx_auth_user_relation_type_value", columnList = "typeValue"), + @Index(name = "idx_auth_user_relation_resource_type", columnList = "resourceType"), + @Index(name = "idx_auth_user_relation_resource_key", columnList = "resourceKey"), + @Index(name = "idx_auth_user_relation_resource_id", columnList = "resourceId") + } +) +public class AuthUserRelationEntity extends AppEntity { + + // ::: vars + // + private String externalId; + private String userKey; + private String typeValue; + private String resourceType; + private String resourceKey; + private String resourceId; + // relations + @ManyToOne(fetch = FetchType.LAZY) + private AuthUserEntity authUser; + + // ::: constructors + // + public AuthUserRelationEntity() { + } + + public AuthUserRelationEntity(String id) { + super(id); + } + + // ::: fields + // + public String getExternalId() { + return externalId; + } + + public void setExternalId(String externalId) { + this.externalId = externalId; + } + + public String getUserKey() { + return userKey; + } + + public void setUserKey(String userKey) { + this.userKey = userKey; + } + + public String getTypeValue() { + return typeValue; + } + + public void setTypeValue(String typeValue) { + this.typeValue = typeValue; + } + + public String getResourceType() { + return resourceType; + } + + public void setResourceType(String resourceType) { + this.resourceType = resourceType; + } + + public String getResourceKey() { + return resourceKey; + } + + public void setResourceKey(String resourceKey) { + this.resourceKey = resourceKey; + } + + public String getResourceId() { + return resourceId; + } + + public void setResourceId(String resourceId) { + this.resourceId = resourceId; + } + + // relations + public AuthUserEntity getAuthUser() { + return authUser; + } + + public void setAuthUser(AuthUserEntity authUser) { + this.authUser = authUser; + } + + // ::: fluent + // + public AuthUserRelationEntity externalId(String externalId) { + setExternalId(externalId); + return this; + } + + public AuthUserRelationEntity userKey(String userKey) { + setUserKey(userKey); + return this; + } + + public AuthUserRelationEntity typeValue(String typeValue) { + setTypeValue(typeValue); + return this; + } + + public AuthUserRelationEntity resourceType(String resourceType) { + setResourceType(resourceType); + return this; + } + + public AuthUserRelationEntity resourceKey(String resourceKey) { + setResourceKey(resourceKey); + return this; + } + + public AuthUserRelationEntity resourceId(String resourceId) { + setResourceId(resourceId); + return this; + } + + // relations + public AuthUserRelationEntity authUser(AuthUserEntity authUser) { + setAuthUser(authUser); + return this; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/store/authuserrelation/AuthUserRelationFields.java b/src/main/java/io/kumare/iqr/mod/authentication/store/authuserrelation/AuthUserRelationFields.java new file mode 100644 index 0000000..ec93337 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/store/authuserrelation/AuthUserRelationFields.java @@ -0,0 +1,155 @@ +/* + */ +package io.kumare.iqr.mod.authentication.store.authuserrelation; + +// java +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +// base +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app +import io.kumare.iqr.mod.authentication.store.AuthenticationEntities; +import io.kumare.iqr.mod.authentication.store.authuser.AuthUserFields; + +/** + * + * @author afatecha + */ +public enum AuthUserRelationFields implements EntityFieldDescriptor { + + id(MAIN, FIND, LIST), + externalId(MAIN, FIND, LIST), + userKey(MAIN, FIND, LIST), + typeValue(MAIN, FIND, LIST), + resourceType(MAIN, FIND, LIST), + resourceKey(MAIN, FIND, LIST), + resourceId(MAIN, FIND, LIST), + active(MAIN, FIND, LIST), + inserted(AUDIT, FIND, LIST), + inserter(AUDIT, FIND, LIST), + modified(AUDIT, FIND), + modifier(AUDIT, FIND), + deleted(AUDIT), + removed(AUDIT), + remover(AUDIT), + authUser(AuthenticationEntities.authUser, AuthUserFields.class, FIND, LIST); + + // ::: vars + // + private final boolean relation; + private final EntityDescriptor entityDescriptor; + private final Class enumClass; + private final List groups; + + // ::: constructors + // + AuthUserRelationFields(String... groups) { + this(false, null, null, groups); + } + + AuthUserRelationFields(EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this(true, entityDescriptor, enumClass, groups); + } + + AuthUserRelationFields(boolean relation, EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this.relation = relation; + this.entityDescriptor = entityDescriptor; + this.enumClass = enumClass; + this.groups = groups == null ? Collections.EMPTY_LIST : Arrays.asList(groups); + } + + // ::: api + // + @Override + public String getName() { + return name(); + } + + @Override + public boolean isRelation() { + return relation; + } + + @Override + public Class getRelationEnumClass() { + return enumClass; + } + + @Override + public List getGroups() { + return groups; + } + + @Override + public EntityDescriptor getEntityDescriptor() { + return entityDescriptor; + } + + @Override + public Object fetchValue(AuthUserRelationEntity entity) { + if (entity == null) { + return null; + } + + switch (this) { + case null -> { + return null; + } + case id -> { + return entity.getId(); + } + case externalId ->{ + return entity.getExternalId(); + } + case userKey ->{ + return entity.getUserKey(); + } + case typeValue ->{ + return entity.getTypeValue(); + } + case resourceType ->{ + return entity.getResourceType(); + } + case resourceKey ->{ + return entity.getResourceKey(); + } + case resourceId ->{ + return entity.getResourceId(); + } + case active -> { + return entity.isActive(); + } + case inserted -> { + return entity.getInserted(); + } + case inserter -> { + return entity.getInserter(); + } + case modified -> { + return entity.getModified(); + } + case modifier -> { + return entity.getModifier(); + } + case deleted -> { + return entity.isDeleted(); + } + case removed -> { + return entity.getRemoved(); + } + case remover -> { + return entity.getRemover(); + } + case authUser ->{ + return entity.getAuthUser(); + } + default -> { + return null; + } + } + + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/store/authuserrelation/AuthUserRelationMapBuilder.java b/src/main/java/io/kumare/iqr/mod/authentication/store/authuserrelation/AuthUserRelationMapBuilder.java new file mode 100644 index 0000000..94307c5 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/store/authuserrelation/AuthUserRelationMapBuilder.java @@ -0,0 +1,139 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.store.authuserrelation; + +// java +import java.util.List; +import java.util.Map; +// base +import io.kumare.lib.app.api.Context; +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.BaseEntityMapBuilder; +// app +import io.kumare.iqr.mod.authentication.store.authuser.AuthUserMapBuilder; + +/** + * + * @author afatecha + */ +public class AuthUserRelationMapBuilder extends BaseEntityMapBuilder { + + // ::: vars + // + private AuthUserMapBuilder authUserBuilder; + + + // ::: fields + // + @Override + public AuthUserRelationMapBuilder addGroup(String name, boolean cascade) { + includes.addAll(EntityFieldDescriptor.group(AuthUserRelationFields.values(), name)); + + if(cascade) { + if (includes.contains(AuthUserRelationFields.authUser)) { + getAuthUserBuilder().addGroup(name); + } + } + return this; + } + + @Override + public AuthUserRelationMapBuilder add(String fieldName) { + includes.add(AuthUserRelationFields.valueOf(fieldName)); + return this; + } + + @Override + public AuthUserRelationMapBuilder addAll(String... names) { + for (var i : names) { + includes.add(AuthUserRelationFields.valueOf(i)); + } + return this; + } + + @Override + public AuthUserRelationMapBuilder remove(String fieldName) { + excludes.add(AuthUserRelationFields.valueOf(fieldName)); + return this; + } + + @Override + public AuthUserRelationMapBuilder removeAll(String... names) { + for (var i : names) { + excludes.add(AuthUserRelationFields.valueOf(i)); + } + return this; + } + + // ::: relations + // + @Override + public AuthUserRelationMapBuilder addPlains(boolean cascade) { + includes.addAll(EntityFieldDescriptor.plains(AuthUserRelationFields.values())); + + if(cascade) { + if (includes.contains(AuthUserRelationFields.authUser)) { + getAuthUserBuilder().addPlains(); + } + } + return this; + } + + @Override + public AuthUserRelationMapBuilder addRelations(boolean cascade) { + includes.addAll(EntityFieldDescriptor.relations(AuthUserRelationFields.values())); + + if(cascade) { + if (includes.contains(AuthUserRelationFields.authUser)) { + getAuthUserBuilder().addRelations(); + } + } + return this; + } + + // ::: auth user + // + public AuthUserRelationMapBuilder addAuthUser() { + return addAuthUser(null); + } + + public AuthUserRelationMapBuilder addAuthUser(String group) { + return addAuthUser(group, false); + } + + public AuthUserRelationMapBuilder addAuthUser(String group, boolean cascade) { + includes.add(AuthUserRelationFields.authUser); + + if (group != null) { + getAuthUserBuilder().addGroup(group); + } + + return this; + } + + public AuthUserMapBuilder getAuthUserBuilder() { + if(authUserBuilder == null) { + authUserBuilder = new AuthUserMapBuilder(); + } + return authUserBuilder; + } + + // ::: internals + // + @Override + protected void internalAttachRelations(Context context, + AuthUserRelationEntity entity, + List fields, + Map resultMap) { + + if (fields.contains(AuthUserRelationFields.authUser)) { + attachRelation(context, + entity, + AuthUserRelationFields.authUser, + getAuthUserBuilder(), + resultMap); + } + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/store/authuserrelation/AuthUserRelationRepository.java b/src/main/java/io/kumare/iqr/mod/authentication/store/authuserrelation/AuthUserRelationRepository.java new file mode 100644 index 0000000..4a46242 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/store/authuserrelation/AuthUserRelationRepository.java @@ -0,0 +1,18 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.store.authuserrelation; + +// spring +import org.springframework.stereotype.Repository; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Repository +public interface AuthUserRelationRepository extends AppEntityRepository{ + +} diff --git a/src/main/java/io/kumare/iqr/mod/authentication/store/authuserrelation/AuthUserRelationStore.java b/src/main/java/io/kumare/iqr/mod/authentication/store/authuserrelation/AuthUserRelationStore.java new file mode 100644 index 0000000..393c0f0 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/authentication/store/authuserrelation/AuthUserRelationStore.java @@ -0,0 +1,35 @@ +/* + * + */ +package io.kumare.iqr.mod.authentication.store.authuserrelation; + +// spring +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Service +public class AuthUserRelationStore extends AppEntityStore { + + // ::: vars + // + @Autowired + private AuthUserRelationRepository repository; + + // ::: override + // + @Override + public AuthUserRelationRepository getRepository() { + return repository; + } + + // ::: api + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/BizConstants.java b/src/main/java/io/kumare/iqr/mod/biz/BizConstants.java new file mode 100644 index 0000000..0d4e317 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/BizConstants.java @@ -0,0 +1,20 @@ +/* + * + */ +package io.kumare.iqr.mod.biz; + +// base +import io.kumare.iqr.app.AppConstants; + +/** + * + * @author afatecha + */ +public class BizConstants { + + // ::: codes + // + public static final int CODE = AppConstants.BIZ_CODE; + public static final String NAME = "biz"; + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/BizController.java b/src/main/java/io/kumare/iqr/mod/biz/BizController.java new file mode 100644 index 0000000..c932f3c --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/BizController.java @@ -0,0 +1,87 @@ +/* + * + */ +package io.kumare.iqr.mod.biz; + +// java +import io.kumare.iqr.mod.biz.store.BizEntities; +import java.util.Arrays; +import java.util.List; +// base +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app +import io.kumare.iqr.app.module.AppModuleController; +// module +import io.kumare.iqr.mod.biz.store.business.BusinessStore; +import io.kumare.iqr.mod.biz.store.businessprofile.BusinessProfileStore; +import io.kumare.iqr.mod.biz.store.businesssetting.BusinessSettingStore; +import io.kumare.iqr.mod.biz.store.businesspromo.BusinessPromoStore; +import io.kumare.iqr.mod.biz.store.businesspromoitem.BusinessPromoItemStore; +import io.kumare.iqr.mod.biz.store.businessimage.BusinessImageStore; +import io.kumare.iqr.mod.biz.store.businessworker.BusinessWorkerStore; +import io.kumare.iqr.mod.biz.store.businesstag.BusinessTagStore; + +/** + * + * @author afatecha + */ +public class BizController extends AppModuleController { + + // ::: api + // + @Override + public boolean hasStore(String name) { + return BizEntities.hasDescriptor(name); + } + + @Override + public EntityDescriptor getEntityDescriptor(Class entityClass) { + return BizEntities.descriptorOf(entityClass); + } + + @Override + public EntityDescriptor getEntityDescriptor(String name) { + return BizEntities.descriptorOf(name); + } + + @Override + public List getEntityDescriptors() { + return Arrays.asList(BizEntities.values()); + } + + // ::: stores + // + public BusinessStore getBusinessStore() { + return getService(BusinessStore.class); + } + + public BusinessProfileStore getBusinessProfileStore() { + return getService(BusinessProfileStore.class); + } + + public BusinessSettingStore getBusinessSettingStore() { + return getService(BusinessSettingStore.class); + } + + public BusinessPromoStore getBusinessPromoStore() { + return getService(BusinessPromoStore.class); + } + + public BusinessPromoItemStore getBusinessPromoItemStore() { + return getService(BusinessPromoItemStore.class); + } + + public BusinessImageStore getBusinessImageStore() { + return getService(BusinessImageStore.class); + } + + public BusinessWorkerStore getBusinessWorkerStore() { + return getService(BusinessWorkerStore.class); + } + + public BusinessTagStore getBusinessTagStore() { + return getService(BusinessTagStore.class); + } + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/BizErrors.java b/src/main/java/io/kumare/iqr/mod/biz/BizErrors.java new file mode 100644 index 0000000..ab9a2da --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/BizErrors.java @@ -0,0 +1,165 @@ +/* + * + */ +package io.kumare.iqr.mod.biz; + +// java +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.transport.TransportCode; +import static io.kumare.lib.transport.Transports.code; +import io.kumare.lib.v.ExceptionPrototype; +// app +import io.kumare.iqr.app.AppException; +import io.kumare.iqr.app.endpoint.AppTransports; + + +/** + * + * @author afatecha + */ +public enum BizErrors implements ExceptionPrototype { + + + // business + business_notfound(1, code(AppTransports.http, 400)), + business_data_notfound(1, code(AppTransports.http, 400)), + business_preload_empty(1, code(AppTransports.http, 400)), + business_entitykey_empty(1, code(AppTransports.http, 400)), + business_alias_empty(1, code(AppTransports.http, 400)), + business_statevalue_empty(1, code(AppTransports.http, 400)), + business_name_empty(1, code(AppTransports.http, 400)), + business_description_empty(1, code(AppTransports.http, 400)), + business_logo_notfound(1, code(AppTransports.http, 400)), + business_state_notfound(1, code(AppTransports.http, 400)), + + // business profile + businessprofile_notfound(1, code(AppTransports.http, 400)), + businessprofile_data_notfound(1, code(AppTransports.http, 400)), + businessprofile_preload_empty(1, code(AppTransports.http, 400)), + businessprofile_activityvalue_empty(1, code(AppTransports.http, 400)), + businessprofile_gpslatitude_empty(1, code(AppTransports.http, 400)), + businessprofile_gpslongitude_empty(1, code(AppTransports.http, 400)), + businessprofile_website_empty(1, code(AppTransports.http, 400)), + businessprofile_phone_empty(1, code(AppTransports.http, 400)), + businessprofile_address_empty(1, code(AppTransports.http, 400)), + businessprofile_extrainfo_empty(1, code(AppTransports.http, 400)), + businessprofile_description_empty(1, code(AppTransports.http, 400)), + businessprofile_business_notfound(1, code(AppTransports.http, 400)), + businessprofile_image_notfound(1, code(AppTransports.http, 400)), + businessprofile_activity_notfound(1, code(AppTransports.http, 400)), + + // business setting + businesssetting_notfound(1, code(AppTransports.http, 400)), + businesssetting_data_notfound(1, code(AppTransports.http, 400)), + businesssetting_preload_empty(1, code(AppTransports.http, 400)), + businesssetting_pointexchange_empty(1, code(AppTransports.http, 400)), + businesssetting_leadcapturereward_empty(1, code(AppTransports.http, 400)), + businesssetting_customercapturereward_empty(1, code(AppTransports.http, 400)), + businesssetting_business_notfound(1, code(AppTransports.http, 400)), + + // business promo + businesspromo_notfound(1, code(AppTransports.http, 400)), + businesspromo_data_notfound(1, code(AppTransports.http, 400)), + businesspromo_preload_empty(1, code(AppTransports.http, 400)), + businesspromo_statevalue_empty(1, code(AppTransports.http, 400)), + businesspromo_started_empty(1, code(AppTransports.http, 400)), + businesspromo_ended_empty(1, code(AppTransports.http, 400)), + businesspromo_schedulestart_empty(1, code(AppTransports.http, 400)), + businesspromo_scheduleend_empty(1, code(AppTransports.http, 400)), + businesspromo_title_empty(1, code(AppTransports.http, 400)), + businesspromo_bodyinfo_empty(1, code(AppTransports.http, 400)), + businesspromo_footerinfo_empty(1, code(AppTransports.http, 400)), + businesspromo_business_notfound(1, code(AppTransports.http, 400)), + businesspromo_image_notfound(1, code(AppTransports.http, 400)), + businesspromo_state_notfound(1, code(AppTransports.http, 400)), + + // business promo item + businesspromoitem_notfound(1, code(AppTransports.http, 400)), + businesspromoitem_data_notfound(1, code(AppTransports.http, 400)), + businesspromoitem_preload_empty(1, code(AppTransports.http, 400)), + businesspromoitem_title_empty(1, code(AppTransports.http, 400)), + businesspromoitem_description_empty(1, code(AppTransports.http, 400)), + businesspromoitem_points_empty(1, code(AppTransports.http, 400)), + businesspromoitem_condition_empty(1, code(AppTransports.http, 400)), + businesspromoitem_business_notfound(1, code(AppTransports.http, 400)), + businesspromoitem_promo_notfound(1, code(AppTransports.http, 400)), + businesspromoitem_image_notfound(1, code(AppTransports.http, 400)), + + // business image + businessimage_notfound(1, code(AppTransports.http, 400)), + businessimage_data_notfound(1, code(AppTransports.http, 400)), + businessimage_preload_empty(1, code(AppTransports.http, 400)), + businessimage_typevalue_empty(1, code(AppTransports.http, 400)), + businessimage_bytes_empty(1, code(AppTransports.http, 400)), + businessimage_business_notfound(1, code(AppTransports.http, 400)), + businessimage_type_notfound(1, code(AppTransports.http, 400)), + + // business worker + businessworker_notfound(1, code(AppTransports.http, 400)), + businessworker_data_notfound(1, code(AppTransports.http, 400)), + businessworker_preload_empty(1, code(AppTransports.http, 400)), + businessworker_entitykey_empty(1, code(AppTransports.http, 400)), + businessworker_rolevalue_empty(1, code(AppTransports.http, 400)), + businessworker_statevalue_empty(1, code(AppTransports.http, 400)), + businessworker_email_empty(1, code(AppTransports.http, 400)), + businessworker_phone_empty(1, code(AppTransports.http, 400)), + businessworker_name_empty(1, code(AppTransports.http, 400)), + businessworker_description_empty(1, code(AppTransports.http, 400)), + businessworker_business_notfound(1, code(AppTransports.http, 400)), + businessworker_authuser_notfound(1, code(AppTransports.http, 400)), + businessworker_role_notfound(1, code(AppTransports.http, 400)), + businessworker_state_notfound(1, code(AppTransports.http, 400)), + + // business tag + businesstag_notfound(1, code(AppTransports.http, 400)), + businesstag_data_notfound(1, code(AppTransports.http, 400)), + businesstag_preload_empty(1, code(AppTransports.http, 400)), + businesstag_entitykey_empty(1, code(AppTransports.http, 400)), + businesstag_name_empty(1, code(AppTransports.http, 400)); + + // ::: vars + // + private final Map transportCodes = new HashMap(); + private final int code; + + // ::: constructors + // + private BizErrors(int code, TransportCode... codes) { + this.code = code; + if (codes != null) { + for (var i : codes) { + if (i != null) { + transportCodes.put(i.getId(), i.getCode()); + } + } + } + } + + // ::: prototype api + // + @Override + public int getCode() { + return code; + } + + @Override + public String getName() { + return name(); + } + + @Override + public Map getTransportCodes() { + return transportCodes; + } + + @Override + public RuntimeException newInstance(String msg, Throwable cause, Map extra) { + var ex = new AppException(this, msg, cause); + ex.setExtra(extra); + return ex; + } + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/BizModule.java b/src/main/java/io/kumare/iqr/mod/biz/BizModule.java new file mode 100644 index 0000000..a2191c5 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/BizModule.java @@ -0,0 +1,37 @@ +/* + * + */ +package io.kumare.iqr.mod.biz; + +// java +import io.kumare.lib.base.server.spring.module.BaseModule; + + +/** + * + * @author afatecha + */ +public class BizModule extends BaseModule { + + // ::: + // + public static final BizController controller = new BizController(); + + // ::: api + // + @Override + public int getId() { + return BizConstants.CODE; + } + + @Override + public String getName() { + return BizConstants.NAME; + } + + @Override + public BizController getController() { + return controller; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/BizPermissions.java b/src/main/java/io/kumare/iqr/mod/biz/BizPermissions.java new file mode 100644 index 0000000..a554fd9 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/BizPermissions.java @@ -0,0 +1,198 @@ +/* + * + */ +package io.kumare.iqr.mod.biz; + +// base +import io.kumare.iqr.mod.biz.store.BizEntities; +import io.kumare.lib.app.api.security.PermissionReference; +// app +import io.kumare.iqr.app.AppErrors; + +/** + * + * @author afatecha + */ +public enum BizPermissions { + + // business + //business_add(BizEntities.business), + //business_edit(BizEntities.business), + //business_find(BizEntities.business), + //business_enable(BizEntities.business), + //business_disable(BizEntities.business), + //business_list(BizEntities.business), + //business_delete(BizEntities.business), + //business_preload(BizEntities.business), + // + business_viewer(BizEntities.business), + //business_guest(BizEntities.business), + //business_collab(BizEntities.business), + business_worker(BizEntities.business), + //business_control(BizEntities.business), + business_manager(BizEntities.business), + business_admin(null), + business_system(null), + + // business profile + //business_profile_add(BizEntities.businessProfile), + //business_profile_edit(BizEntities.businessProfile), + //business_profile_find(BizEntities.businessProfile), + //business_profile_enable(BizEntities.businessProfile), + //business_profile_disable(BizEntities.businessProfile), + //business_profile_list(BizEntities.businessProfile), + //business_profile_delete(BizEntities.businessProfile), + //business_profile_preload(BizEntities.businessProfile), + // + business_profile_viewer(BizEntities.businessProfile), + //business_profile_guest(BizEntities.businessProfile), + //business_profile_collab(BizEntities.businessProfile), + business_profile_worker(BizEntities.businessProfile), + //business_profile_control(BizEntities.businessProfile), + business_profile_manager(BizEntities.businessProfile), + business_profile_admin(null), + business_profile_system(null), + + // business setting + //business_setting_add(BizEntities.businessSetting), + //business_setting_edit(BizEntities.businessSetting), + //business_setting_find(BizEntities.businessSetting), + //business_setting_enable(BizEntities.businessSetting), + //business_setting_disable(BizEntities.businessSetting), + //business_setting_list(BizEntities.businessSetting), + //business_setting_delete(BizEntities.businessSetting), + //business_setting_preload(BizEntities.businessSetting), + // + business_setting_viewer(BizEntities.businessSetting), + //business_setting_guest(BizEntities.businessSetting), + //business_setting_collab(BizEntities.businessSetting), + business_setting_worker(BizEntities.businessSetting), + //business_setting_control(BizEntities.businessSetting), + business_setting_manager(BizEntities.businessSetting), + business_setting_admin(null), + business_setting_system(null), + + // business promo + //business_promo_add(BizEntities.businessPromo), + //business_promo_edit(BizEntities.businessPromo), + //business_promo_find(BizEntities.businessPromo), + //business_promo_enable(BizEntities.businessPromo), + //business_promo_disable(BizEntities.businessPromo), + //business_promo_list(BizEntities.businessPromo), + //business_promo_delete(BizEntities.businessPromo), + //business_promo_preload(BizEntities.businessPromo), + // + business_promo_viewer(BizEntities.businessPromo), + //business_promo_guest(BizEntities.businessPromo), + //business_promo_collab(BizEntities.businessPromo), + business_promo_worker(BizEntities.businessPromo), + //business_promo_control(BizEntities.businessPromo), + business_promo_manager(BizEntities.businessPromo), + business_promo_admin(null), + business_promo_system(null), + + // business promo item + //business_promo_item_add(BizEntities.businessPromoItem), + //business_promo_item_edit(BizEntities.businessPromoItem), + //business_promo_item_find(BizEntities.businessPromoItem), + //business_promo_item_enable(BizEntities.businessPromoItem), + //business_promo_item_disable(BizEntities.businessPromoItem), + //business_promo_item_list(BizEntities.businessPromoItem), + //business_promo_item_delete(BizEntities.businessPromoItem), + //business_promo_item_preload(BizEntities.businessPromoItem), + // + business_promo_item_viewer(BizEntities.businessPromoItem), + //business_promo_item_guest(BizEntities.businessPromoItem), + //business_promo_item_collab(BizEntities.businessPromoItem), + business_promo_item_worker(BizEntities.businessPromoItem), + //business_promo_item_control(BizEntities.businessPromoItem), + business_promo_item_manager(BizEntities.businessPromoItem), + business_promo_item_admin(null), + business_promo_item_system(null), + + // business image + //business_image_add(BizEntities.businessImage), + //business_image_edit(BizEntities.businessImage), + //business_image_find(BizEntities.businessImage), + //business_image_enable(BizEntities.businessImage), + //business_image_disable(BizEntities.businessImage), + //business_image_list(BizEntities.businessImage), + //business_image_delete(BizEntities.businessImage), + //business_image_preload(BizEntities.businessImage), + // + business_image_viewer(BizEntities.businessImage), + //business_image_guest(BizEntities.businessImage), + //business_image_collab(BizEntities.businessImage), + business_image_worker(BizEntities.businessImage), + //business_image_control(BizEntities.businessImage), + business_image_manager(BizEntities.businessImage), + business_image_admin(null), + business_image_system(null), + + // business worker + //business_worker_add(BizEntities.businessWorker), + //business_worker_edit(BizEntities.businessWorker), + //business_worker_find(BizEntities.businessWorker), + //business_worker_enable(BizEntities.businessWorker), + //business_worker_disable(BizEntities.businessWorker), + //business_worker_list(BizEntities.businessWorker), + //business_worker_delete(BizEntities.businessWorker), + //business_worker_preload(BizEntities.businessWorker), + // + business_worker_viewer(BizEntities.businessWorker), + //business_worker_guest(BizEntities.businessWorker), + //business_worker_collab(BizEntities.businessWorker), + business_worker_worker(BizEntities.businessWorker), + //business_worker_control(BizEntities.businessWorker), + business_worker_manager(BizEntities.businessWorker), + business_worker_admin(null), + business_worker_system(null), + + // business tag + //business_tag_add(BizEntities.businessTag), + //business_tag_edit(BizEntities.businessTag), + //business_tag_find(BizEntities.businessTag), + //business_tag_enable(BizEntities.businessTag), + //business_tag_disable(BizEntities.businessTag), + //business_tag_list(BizEntities.businessTag), + //business_tag_delete(BizEntities.businessTag), + //business_tag_preload(BizEntities.businessTag), + // + business_tag_viewer(BizEntities.businessTag), + //business_tag_guest(BizEntities.businessTag), + //business_tag_collab(BizEntities.businessTag), + business_tag_worker(BizEntities.businessTag), + //business_tag_control(BizEntities.businessTag), + business_tag_manager(BizEntities.businessTag), + business_tag_admin(null), + business_tag_system(null); + + + // ::: + // + private final BizEntities resourceType; + + BizPermissions(BizEntities entityRef) { + this.resourceType = entityRef; + } + + // + public PermissionReference toReference() { + return toReference(null); + } + + public PermissionReference toReference(String resourceKey) { + var ref = new PermissionReference() + .module(BizConstants.NAME) + .permission(name()) + .error(AppErrors.action_unauthorized); + + if (resourceType != null && resourceKey != null) { + ref.resourceType(resourceType.name()) + .resourceKey(resourceKey); + } + + return ref; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessActionArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessActionArgument.java new file mode 100644 index 0000000..027eee0 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessActionArgument.java @@ -0,0 +1,29 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.business; + +// base +import io.kumare.iqr.app.action.AppEntityActionArgument; +// entity +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; + +/** + * + * @author afatecha + */ +public class BusinessActionArgument extends AppEntityActionArgument { + + // ::: constructors + // + public BusinessActionArgument() { + } + + public BusinessActionArgument(BusinessEntity entity) { + super(entity); + } + + // ::: api + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessAddAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessAddAction.java new file mode 100644 index 0000000..def4266 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessAddAction.java @@ -0,0 +1,161 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.business; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +import io.kumare.iqr.mod.authentication.action.authuser.AuthUserAddArgument; +import io.kumare.iqr.mod.authentication.store.authuser.AuthUserEntity; +// module +import io.kumare.iqr.mod.biz.BizErrors; +import io.kumare.iqr.mod.biz.action.businessprofile.BusinessProfileAddAction; +import io.kumare.iqr.mod.biz.action.businessprofile.BusinessProfileAddArgument; +import io.kumare.iqr.mod.biz.action.businesstag.BusinessTagAddAction; +import io.kumare.iqr.mod.biz.action.businesstag.BusinessTagAddArgument; +import io.kumare.iqr.mod.biz.action.businessworker.BusinessWorkerAddAction; +import io.kumare.iqr.mod.biz.action.businessworker.BusinessWorkerAddArgument; +import io.kumare.iqr.mod.biz.store.BizTaxonomies; +import io.kumare.iqr.mod.biz.store.BizWorkerRoles; +// entity +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; +import io.kumare.iqr.mod.biz.store.businesstag.BusinessTagEntity; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; +import io.kumare.lib.base.server.spring.action.Actions; + +/** + * + * @author afatecha + */ +public class BusinessAddAction extends AppAction> { + + // ::: vars + // + private BusinessEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, BizErrors.business_notfound); + + // relations + //V.ifNull(model.getState(), BizErrors.business_state_notfound); + // fields + //V.ifEmpty(model.getEntityKey(), BizErrors.business_entitykey_empty); + //V.ifEmpty(model.getAlias(), BizErrors.business_alias_empty); + //V.ifEmpty(model.getStateValue(), BizErrors.business_statevalue_empty); + V.ifEmpty(model.getName(), BizErrors.business_name_empty); + //V.ifEmpty(model.getDescription(), BizErrors.business_description_empty); + } + + @Override + protected void doAction() { + // controllers + var state = BizTaxonomies.businessState.ensureDefault(getContext()); + + // model + var model = makeModel(state); + + // add + entity = saveEntity(model); + + // add others + addProfile(getArgument().getProfile()); + addManager(getArgument().getManager()); + addTags(); + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private BusinessEntity makeModel(TaxonEntity state) { + + var argModel = getArgument().getEntity(); + var model = new BusinessEntity(); + + // relations + model.setState(state); + model.setStateValue(state.getValue()); + + // fields + model.setEntityKey(generateKey()); + model.setAlias(argModel.getAlias()); + model.setName(argModel.getName()); + model.setDescription(argModel.getDescription()); + model.setActive(true); + + return model; + } + + private String generateKey() { + return null; + } + + // ::: save + // + private BusinessEntity saveEntity(BusinessEntity model) { + + var store = AppModules.biz.getController().getBusinessStore(); + + var saved = store.add(getContext(), model); + getContext().attach(saved.getId(), saved); + return saved; + } + + // ::: adds + // + private void addProfile(BusinessProfileAddArgument argument) { + argument.getEntity().setBusiness(entity); + Actions.perform(getContext(), new BusinessProfileAddAction(), argument); + } + + private void addManager(BusinessWorkerAddArgument argument) { + + var worker = argument.getEntity(); + worker + .business(entity) + .role(new TaxonEntity() + .taxaKey(BizTaxonomies.businessWorkerRole.getKey()) + .entityKey(BizWorkerRoles.manager.getKey())); + + var addUser = new AuthUserAddArgument(); + addUser.entity(new AuthUserEntity() + .email(worker.getEmail()) + .phone(worker.getPhone()) + .name(worker.getName()) + .visible(true) + .entityKey(worker.getEntityKey())); + + argument.setAuthUser(addUser); + + Actions.perform(getContext(), new BusinessWorkerAddAction(), argument); + } + + private void addTags() { + var tags = BizTaxonomies.businessDefaultTag.list(getContext()); + + tags.forEach(i -> { + var arg = new BusinessTagAddArgument(); + arg.entity(new BusinessTagEntity().name(i.getName())); + Actions.perform(getContext(), new BusinessTagAddAction(), arg); + }); + } +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessAddArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessAddArgument.java new file mode 100644 index 0000000..a8a84c9 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessAddArgument.java @@ -0,0 +1,49 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.business; + +// app +import io.kumare.iqr.mod.biz.action.businessprofile.BusinessProfileAddArgument; +import io.kumare.iqr.mod.biz.action.businessworker.BusinessWorkerAddArgument; +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; + +/** + * + * @author afatecha + */ +public class BusinessAddArgument extends BusinessActionArgument { + + // ::: vars + // + private BusinessProfileAddArgument profile; + private BusinessWorkerAddArgument manager; + + // ::: constructors + // + public BusinessAddArgument() { + } + + public BusinessAddArgument(BusinessEntity entity) { + super(entity); + } + + // ::: fields + // + public BusinessProfileAddArgument getProfile() { + return profile; + } + + public void setProfile(BusinessProfileAddArgument profile) { + this.profile = profile; + } + + public BusinessWorkerAddArgument getManager() { + return manager; + } + + public void setManager(BusinessWorkerAddArgument manager) { + this.manager = manager; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessDeleteAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessDeleteAction.java new file mode 100644 index 0000000..97b46d9 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessDeleteAction.java @@ -0,0 +1,59 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.business; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; + +/** + * + * @author afatecha + */ +public class BusinessDeleteAction extends AppAction> { + + // ::: vars + // + private BusinessEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), BizErrors.business_notfound); + V.ifNull(getArgument().getEntity().getId(), BizErrors.business_notfound); + } + + @Override + protected void doAction() { + + var argModel = getArgument().getEntity(); + + deleteEntity(argModel); + } + + @Override + protected void setResultOnly() { + } + + // ::: delete + // + private void deleteEntity(BusinessEntity model) { + + var store = AppModules.biz.getController().getBusinessStore(); + + store.deleteById(getContext(), model.getId()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessEditAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessEditAction.java new file mode 100644 index 0000000..1bf0cbd --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessEditAction.java @@ -0,0 +1,110 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.business; + +// lib +import io.kumare.lib.v.V; +// app +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +import io.kumare.iqr.mod.biz.action.businessprofile.BusinessProfileEditAction; +import io.kumare.iqr.mod.biz.action.businessprofile.BusinessProfileEditArgument; +// entity +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; +import io.kumare.lib.base.server.spring.action.Actions; + +/** + * + * @author afatecha + */ +public class BusinessEditAction extends AppAction> { + + // ::: vars + // + private BusinessEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, BizErrors.business_notfound); + + // fields + //V.ifEmpty(model.getEntityKey(), BizErrors.business_entitykey_empty); + //V.ifEmpty(model.getAlias(), BizErrors.business_alias_empty); + //V.ifEmpty(model.getStateValue(), BizErrors.business_statevalue_empty); + //V.ifEmpty(model.getName(), BizErrors.business_name_empty); + //V.ifEmpty(model.getDescription(), BizErrors.business_description_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + var biz = AppModules.biz.getController(); + var businessStore = biz.getBusinessStore(); + + // edit + entity = businessStore.ensure(getContext(), argModel, BizErrors.business_notfound); + + editEntity(); + + entity = saveEntity(); + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private void editEntity() { + + var model = getArgument().getEntity(); + + // fields + //entity.setEntityKey(V.firstNotEmpty(model.getEntityKey(), entity.getEntityKey())); + entity.setAlias(V.firstNotEmpty(model.getAlias(), entity.getAlias())); + //entity.setStateValue(V.firstNotEmpty(model.getStateValue(), entity.getStateValue())); + entity.setName(V.firstNotEmpty(model.getName(), entity.getName())); + entity.setDescription(V.firstNotEmpty(model.getDescription(), entity.getDescription())); + + } + + // ::: save + // + private BusinessEntity saveEntity() { + + var store = AppModules.biz.getController().getBusinessStore(); + + var saved = store.edit(getContext(), entity); + getContext().attach(saved.getId(), saved); + return saved; + } + + // ::: edit others + // + public void editProfile(BusinessProfileEditArgument argument) { + if (argument != null) { + argument.getEntity().setBusiness(entity); + Actions.perform(getContext(), new BusinessProfileEditAction(), argument); + } + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessEditArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessEditArgument.java new file mode 100644 index 0000000..f235fb5 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessEditArgument.java @@ -0,0 +1,39 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.business; + +// app +import io.kumare.iqr.mod.biz.action.businessprofile.BusinessProfileEditArgument; +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; + +/** + * + * @author afatecha + */ +public class BusinessEditArgument extends BusinessActionArgument { + + // ::: vars + // + private BusinessProfileEditArgument profile; + + // ::: constructors + // + public BusinessEditArgument() { + } + + public BusinessEditArgument(BusinessEntity entity) { + super(entity); + } + + // ::: fields + // + public BusinessProfileEditArgument getProfile() { + return profile; + } + + public void setProfile(BusinessProfileEditArgument profile) { + this.profile = profile; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessEnableAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessEnableAction.java new file mode 100644 index 0000000..da6e12c --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessEnableAction.java @@ -0,0 +1,60 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.business; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; + + +/** + * + * @author afatecha + */ +public class BusinessEnableAction extends AppAction { + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), BizErrors.business_notfound); + V.ifNull(getArgument().getEntity().getId(), BizErrors.business_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + + enableEntity(model); + } + + @Override + protected void setResultOnly() { + } + + // ::: enable + // + private void enableEntity(BusinessEntity model) { + + var store = AppModules.biz.getController().getBusinessStore(); + + if (getArgument().getEntity().isActive()) { + store.enableById(getContext(), model.getId()); + } else { + store.disableById(getContext(), model.getId()); + } + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessFindAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessFindAction.java new file mode 100644 index 0000000..2dd483b --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessFindAction.java @@ -0,0 +1,70 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.business; + +// java +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; + + +/** + * + * @author afatecha + */ +public class BusinessFindAction extends AppAction { + + // ::: vars + // + private BusinessEntity entity; + + // ::: public api + // + public BusinessEntity getEntity() { + return entity; + } + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), BizErrors.business_notfound); + V.ifNull(getArgument().getEntity().getId(), BizErrors.business_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + entity = findEntity(model); + } + + @Override + protected void setResultOnly() { + var result = new HashMap(); + result.put("entity", entity); + setResult(result); + } + + // ::: find + // + private BusinessEntity findEntity(BusinessEntity model) { + + var store = AppModules.biz.getController().getBusinessStore(); + return store.findById(getContext(), model.getId()); + } + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessListAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessListAction.java new file mode 100644 index 0000000..14ecfa0 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessListAction.java @@ -0,0 +1,148 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.business; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.LinkedList; +import java.util.Map; +// spring +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// entity +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; +import io.kumare.iqr.mod.biz.store.business.BusinessMapBuilder; + + +/** + * + * @author afatecha + */ +public class BusinessListAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private final List entities = new LinkedList<>(); + + // ::: public api + // + public List getEntities() { + return entities; + } + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + } + + @Override + protected void doAction() { + + result.put("pageable", getArgument().isPageable()); + result.put("wrapped", getArgument().isWrapped()); + + if (getArgument().isPageable()) { + + var page = makePage(); + entities.addAll(page.toList()); + + if (getArgument().isWrapped()) { + result.put("page", makeWrappedPage(page)); + } else { + result.put("page", page); + } + + } else { + + var list = makeList(); + entities.addAll(list); + + if (getArgument().isWrapped()) { + result.put("list", makeWrappedList()); + } else { + result.put("list", list); + } + } + + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: page + // + private Page makePage() { + + var page = getArgument().getPageNumber(); + var size = getArgument().getPageSize(); + //var sort = getArgument().getSort(); + + var pageable = PageRequest.of(page, size); + + var store = AppModules.biz.getController().getBusinessStore(); + return store.getRepository().findAll(pageable); + } + + // ::: wrapped page + // + private Map makeWrappedPage(Page found) { + + var page = new HashMap(); + var content = new LinkedList(); + + wrapList(entities, content); + + page.put("size", found.getSize()); + page.put("number", found.getNumber()); + page.put("totalElements", found.getTotalElements()); + page.put("totalPages", found.getTotalPages()); + page.put("content", content); + + return page; + } + + + // ::: list + // + + private List makeList() { + + var store = AppModules.biz.getController().getBusinessStore(); + + return store.listAll(getContext()); + } + + // ::: wrapped list + private List makeWrappedList() { + var list = new LinkedList(); + + wrapList(entities, list); + + return list; + } + + // ::: wrapper + // + private void wrapList(List found, List output) { + + var builder = new BusinessMapBuilder().addListGroup(); + builder.getStateBuilder().addMainGroup(); + + output.addAll(builder.build(getContext(), found)); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessListArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessListArgument.java new file mode 100644 index 0000000..6d02f92 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessListArgument.java @@ -0,0 +1,33 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.business; + +// app +import io.kumare.iqr.app.action.AppListActionArgument; +// store +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; + +/** + * + * @author afatecha + */ +public class BusinessListArgument extends AppListActionArgument { + + // ::: vars + // + + // ::: constructors + // + public BusinessListArgument() { + } + + public BusinessListArgument(BusinessEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessPreloadAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessPreloadAction.java new file mode 100644 index 0000000..cf70301 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessPreloadAction.java @@ -0,0 +1,97 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.business; + +// java +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +import io.kumare.iqr.mod.biz.store.BizTaxonomies; +// entity +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; +// relations + +/** + * + * @author afatecha + */ +public class BusinessPreloadAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private Map params = new HashMap<>(); + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifEmpty(getArgument().getAction(), BizErrors.business_preload_empty); + } + + @Override + protected void doAction() { + if (getArgument().getParams() != null) { + params = getArgument().getParams(); + } + + switch (getArgument().getAction()) { + case "find" -> + prepareFind(); + case "list" -> + prepareList(); + case "add" -> + prepareAdd(); + case "edit" -> + prepareEdit(); + } + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: preload + // + private void prepareAdd() { + var activities = BizTaxonomies.businessActivity.list(getContext()); + result.put("activities", activities); + } + + private void prepareEdit() { + var entity = findEntity(); + result.put("entity", entity); + result.put("state", entity.getState()); + } + + private void prepareList() { + } + + private void prepareFind() { + var entity = findEntity(); + result.put("entity", entity); + result.put("state", entity.getState()); + } + + // ::: queries + // + private BusinessEntity findEntity() { + var store = AppModules.biz.getController().getBusinessStore(); + + var id = (String) params.get("id"); + if (id == null && getArgument().getEntity() != null) { + id = getArgument().getEntity().getId(); + } + return store.findById(getContext(), id); + } +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessPreloadArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessPreloadArgument.java new file mode 100644 index 0000000..11e1845 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/business/BusinessPreloadArgument.java @@ -0,0 +1,26 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.business; + +/** + * + * @author afatecha + */ +public class BusinessPreloadArgument extends BusinessActionArgument { + + // ::: vars + // + private String action; + + // ::: fields + // + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImageActionArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImageActionArgument.java new file mode 100644 index 0000000..cf94a4e --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImageActionArgument.java @@ -0,0 +1,29 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessimage; + +// base +import io.kumare.iqr.app.action.AppEntityActionArgument; +// entity +import io.kumare.iqr.mod.biz.store.businessimage.BusinessImageEntity; + +/** + * + * @author afatecha + */ +public class BusinessImageActionArgument extends AppEntityActionArgument { + + // ::: constructors + // + public BusinessImageActionArgument() { + } + + public BusinessImageActionArgument(BusinessImageEntity entity) { + super(entity); + } + + // ::: api + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImageAddAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImageAddAction.java new file mode 100644 index 0000000..dbee95a --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImageAddAction.java @@ -0,0 +1,121 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessimage; + + +// lib +import io.kumare.lib.base.server.spring.action.Actions; +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businessimage.BusinessImageEntity; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; + + +/** + * + * @author afatecha + */ +public class BusinessImageAddAction extends AppAction> { + + // ::: vars + // + private BusinessImageEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, BizErrors.businessimage_notfound); + + // relations + V.ifNull(model.getBusiness(), BizErrors.businessimage_business_notfound); + V.ifNull(model.getType(), BizErrors.businessimage_type_notfound); + + // fields + V.ifEmpty(model.getTypeValue(), BizErrors.businessimage_typevalue_empty); + V.ifEmpty(model.getBytes(), BizErrors.businessimage_bytes_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + var biz = AppModules.biz.getController(); + var taxonomy = AppModules.taxonomy.getController(); + + var businessStore = biz.getBusinessStore(); + var taxonStore = taxonomy.getTaxonStore(); + + var business = businessStore.ensure(getContext(), argModel.getBusiness(), BizErrors.businessimage_business_notfound); + var type = taxonStore.ensure(getContext(), argModel.getType(), BizErrors.businessimage_type_notfound); + + // model + var model = makeModel(business, type); + + // add + entity = saveEntity(model); + + // add others + + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private BusinessImageEntity makeModel(BusinessEntity business, TaxonEntity type) { + + var argModel = getArgument().getEntity(); + var model = new BusinessImageEntity(); + + // relations + model.setBusiness(business); + model.setType(type); + + // fields + model.setTypeValue(argModel.getTypeValue()); + model.setBytes(argModel.getBytes()); + model.setActive(true); + + + + return model; + } + + // ::: save + // + private BusinessImageEntity saveEntity(BusinessImageEntity model) { + + var store = AppModules.biz.getController().getBusinessImageStore(); + + var saved = store.add(getContext(), model); + getContext().attach(saved.getId(), saved); + return saved; + } + + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImageAddArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImageAddArgument.java new file mode 100644 index 0000000..75ed559 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImageAddArgument.java @@ -0,0 +1,34 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessimage; + + +// app +import io.kumare.iqr.mod.biz.store.businessimage.BusinessImageEntity; + + +/** + * + * @author afatecha + */ +public class BusinessImageAddArgument extends BusinessImageActionArgument { + + // ::: vars + // + + + // ::: constructors + // + public BusinessImageAddArgument() { + } + + public BusinessImageAddArgument(BusinessImageEntity entity) { + super(entity); + } + + // ::: fields + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImageDeleteAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImageDeleteAction.java new file mode 100644 index 0000000..63fc48e --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImageDeleteAction.java @@ -0,0 +1,59 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessimage; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businessimage.BusinessImageEntity; + +/** + * + * @author afatecha + */ +public class BusinessImageDeleteAction extends AppAction> { + + // ::: vars + // + private BusinessImageEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), BizErrors.businessimage_notfound); + V.ifNull(getArgument().getEntity().getId(), BizErrors.businessimage_notfound); + } + + @Override + protected void doAction() { + + var argModel = getArgument().getEntity(); + + deleteEntity(argModel); + } + + @Override + protected void setResultOnly() { + } + + // ::: delete + // + private void deleteEntity(BusinessImageEntity model) { + + var store = AppModules.biz.getController().getBusinessImageStore(); + + store.deleteById(getContext(), model.getId()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImageEditAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImageEditAction.java new file mode 100644 index 0000000..1011c5d --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImageEditAction.java @@ -0,0 +1,95 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessimage; + +// lib +import io.kumare.lib.v.V; +// app +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businessimage.BusinessImageEntity; + +/** + * + * @author afatecha + */ +public class BusinessImageEditAction extends AppAction> { + + // ::: vars + // + private BusinessImageEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, BizErrors.businessimage_notfound); + + // fields + V.ifEmpty(model.getTypeValue(), BizErrors.businessimage_typevalue_empty); + V.ifEmpty(model.getBytes(), BizErrors.businessimage_bytes_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + + var biz = AppModules.biz.getController(); + var businessImageStore = biz.getBusinessImageStore(); + + // edit + entity = businessImageStore.ensure(getContext(), argModel, BizErrors.businessimage_notfound); + + editEntity(); + + entity = saveEntity(); + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private void editEntity() { + + var model = getArgument().getEntity(); + + // fields + entity.setTypeValue(V.firstNotEmpty(model.getTypeValue(), entity.getTypeValue())); + entity.setBytes(V.firstNotEmpty(model.getBytes(), entity.getBytes())); + + + } + + // ::: save + // + private BusinessImageEntity saveEntity() { + + var store = AppModules.biz.getController().getBusinessImageStore(); + + var saved = store.edit(getContext(), entity); + getContext().attach(saved.getId(), saved); + return saved; + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImageEditArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImageEditArgument.java new file mode 100644 index 0000000..d8cf47b --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImageEditArgument.java @@ -0,0 +1,32 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessimage; + +// app +import io.kumare.iqr.mod.biz.store.businessimage.BusinessImageEntity; + +/** + * + * @author afatecha + */ +public class BusinessImageEditArgument extends BusinessImageActionArgument { + + // ::: vars + // + + + // ::: constructors + // + public BusinessImageEditArgument() { + } + + public BusinessImageEditArgument(BusinessImageEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImageEnableAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImageEnableAction.java new file mode 100644 index 0000000..941c5ae --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImageEnableAction.java @@ -0,0 +1,60 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessimage; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businessimage.BusinessImageEntity; + + +/** + * + * @author afatecha + */ +public class BusinessImageEnableAction extends AppAction { + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), BizErrors.businessimage_notfound); + V.ifNull(getArgument().getEntity().getId(), BizErrors.businessimage_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + + enableEntity(model); + } + + @Override + protected void setResultOnly() { + } + + // ::: enable + // + private void enableEntity(BusinessImageEntity model) { + + var store = AppModules.biz.getController().getBusinessImageStore(); + + if (getArgument().getEntity().isActive()) { + store.enableById(getContext(), model.getId()); + } else { + store.disableById(getContext(), model.getId()); + } + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImageFindAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImageFindAction.java new file mode 100644 index 0000000..7387c71 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImageFindAction.java @@ -0,0 +1,64 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessimage; + +// java +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businessimage.BusinessImageEntity; + + +/** + * + * @author afatecha + */ +public class BusinessImageFindAction extends AppAction { + + // ::: vars + // + private BusinessImageEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), BizErrors.businessimage_notfound); + V.ifNull(getArgument().getEntity().getId(), BizErrors.businessimage_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + entity = findEntity(model); + } + + @Override + protected void setResultOnly() { + var result = new HashMap(); + result.put("entity", entity); + setResult(result); + } + + // ::: find + // + private BusinessImageEntity findEntity(BusinessImageEntity model) { + + var store = AppModules.biz.getController().getBusinessImageStore(); + return store.findById(getContext(), model.getId()); + } + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImageListAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImageListAction.java new file mode 100644 index 0000000..e18cdc6 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImageListAction.java @@ -0,0 +1,149 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessimage; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.LinkedList; +import java.util.Map; +// spring +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// entity +import io.kumare.iqr.mod.biz.store.businessimage.BusinessImageEntity; +import io.kumare.iqr.mod.biz.store.businessimage.BusinessImageMapBuilder; + + +/** + * + * @author afatecha + */ +public class BusinessImageListAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private final List entities = new LinkedList<>(); + + // ::: public api + // + public List getEntities() { + return entities; + } + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + } + + @Override + protected void doAction() { + + result.put("pageable", getArgument().isPageable()); + result.put("wrapped", getArgument().isWrapped()); + + if (getArgument().isPageable()) { + + var page = makePage(); + entities.addAll(page.toList()); + + if (getArgument().isWrapped()) { + result.put("page", makeWrappedPage(page)); + } else { + result.put("page", page); + } + + } else { + + var list = makeList(); + entities.addAll(list); + + if (getArgument().isWrapped()) { + result.put("list", makeWrappedList()); + } else { + result.put("list", list); + } + } + + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: page + // + private Page makePage() { + + var page = getArgument().getPageNumber(); + var size = getArgument().getPageSize(); + //var sort = getArgument().getSort(); + + var pageable = PageRequest.of(page, size); + + var store = AppModules.biz.getController().getBusinessImageStore(); + return store.getRepository().findAll(pageable); + } + + // ::: wrapped page + // + private Map makeWrappedPage(Page found) { + + var page = new HashMap(); + var content = new LinkedList(); + + wrapList(entities, content); + + page.put("size", found.getSize()); + page.put("number", found.getNumber()); + page.put("totalElements", found.getTotalElements()); + page.put("totalPages", found.getTotalPages()); + page.put("content", content); + + return page; + } + + + // ::: list + // + + private List makeList() { + + var store = AppModules.biz.getController().getBusinessImageStore(); + + return store.listAll(getContext()); + } + + // ::: wrapped list + private List makeWrappedList() { + var list = new LinkedList(); + + wrapList(entities, list); + + return list; + } + + // ::: wrapper + // + private void wrapList(List found, List output) { + + var builder = new BusinessImageMapBuilder().addListGroup(); + builder.getBusinessBuilder().addMainGroup(); + builder.getTypeBuilder().addMainGroup(); + + output.addAll(builder.build(getContext(), found)); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImageListArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImageListArgument.java new file mode 100644 index 0000000..6855dc2 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImageListArgument.java @@ -0,0 +1,33 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessimage; + +// app +import io.kumare.iqr.app.action.AppListActionArgument; +// store +import io.kumare.iqr.mod.biz.store.businessimage.BusinessImageEntity; + +/** + * + * @author afatecha + */ +public class BusinessImageListArgument extends AppListActionArgument { + + // ::: vars + // + + // ::: constructors + // + public BusinessImageListArgument() { + } + + public BusinessImageListArgument(BusinessImageEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImagePreloadAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImagePreloadAction.java new file mode 100644 index 0000000..514c893 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImagePreloadAction.java @@ -0,0 +1,114 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessimage; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businessimage.BusinessImageEntity; +// relations +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; + +/** + * + * @author afatecha + */ +public class BusinessImagePreloadAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private Map params = new HashMap<>(); + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifEmpty(getArgument().getAction(), BizErrors.businessimage_preload_empty); + } + + @Override + protected void doAction() { + if(getArgument().getParams() != null) { + params = getArgument().getParams(); + } + + switch (getArgument().getAction()) { + case "find" -> + prepareFind(); + case "list" -> + prepareList(); + case "add" -> + prepareAdd(); + case "edit" -> + prepareEdit(); + } + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: preload + // + private void prepareAdd() { + result.put("taxons", listTaxons()); + result.put("businesss", listBusinesss()); + } + + private void prepareEdit() { + var entity = findEntity(); + result.put("entity", entity); + result.put("business", entity.getBusiness()); + result.put("type", entity.getType()); + } + + private void prepareList() { + } + + private void prepareFind() { + var entity = findEntity(); + result.put("entity", entity); + result.put("business", entity.getBusiness()); + result.put("type", entity.getType()); + } + + // ::: queries + // + private BusinessImageEntity findEntity() { + var store = AppModules.biz.getController().getBusinessImageStore(); + + var id = (String) params.get("id"); + if(id == null && getArgument().getEntity() != null) { + id = getArgument().getEntity().getId(); + } + return store.findById(getContext(), id); + } + + public List listBusinesss() { + var store = AppModules.biz.getController().getBusinessStore(); + + return store.listAll(getContext()); + } + public List listTaxons() { + var store = AppModules.taxonomy.getController().getTaxonStore(); + + return store.listAll(getContext()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImagePreloadArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImagePreloadArgument.java new file mode 100644 index 0000000..aa6a8db --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessimage/BusinessImagePreloadArgument.java @@ -0,0 +1,26 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessimage; + +/** + * + * @author afatecha + */ +public class BusinessImagePreloadArgument extends BusinessImageActionArgument { + + // ::: vars + // + private String action; + + // ::: fields + // + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfileActionArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfileActionArgument.java new file mode 100644 index 0000000..5b732eb --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfileActionArgument.java @@ -0,0 +1,29 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessprofile; + +// base +import io.kumare.iqr.app.action.AppEntityActionArgument; +// entity +import io.kumare.iqr.mod.biz.store.businessprofile.BusinessProfileEntity; + +/** + * + * @author afatecha + */ +public class BusinessProfileActionArgument extends AppEntityActionArgument { + + // ::: constructors + // + public BusinessProfileActionArgument() { + } + + public BusinessProfileActionArgument(BusinessProfileEntity entity) { + super(entity); + } + + // ::: api + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfileAddAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfileAddAction.java new file mode 100644 index 0000000..676d2e9 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfileAddAction.java @@ -0,0 +1,133 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessprofile; + + +// lib +import io.kumare.lib.base.server.spring.action.Actions; +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +import io.kumare.iqr.mod.biz.store.BizTaxonomies; +// entity +import io.kumare.iqr.mod.biz.store.businessprofile.BusinessProfileEntity; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; +import io.kumare.iqr.mod.biz.store.businessimage.BusinessImageEntity; + + +/** + * + * @author afatecha + */ +public class BusinessProfileAddAction extends AppAction> { + + // ::: vars + // + private BusinessProfileEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, BizErrors.businessprofile_notfound); + + // relations + V.ifNull(model.getBusiness(), BizErrors.businessprofile_business_notfound); + //V.ifNull(model.getImage(), BizErrors.businessprofile_image_notfound); + V.ifNull(model.getActivity(), BizErrors.businessprofile_activity_notfound); + + // fields + //V.ifEmpty(model.getActivityValue(), BizErrors.businessprofile_activityvalue_empty); + //V.ifEmpty(model.getGpsLatitude(), BizErrors.businessprofile_gpslatitude_empty); + //V.ifEmpty(model.getGpsLongitude(), BizErrors.businessprofile_gpslongitude_empty); + //V.ifEmpty(model.getWebsite(), BizErrors.businessprofile_website_empty); + //V.ifEmpty(model.getPhone(), BizErrors.businessprofile_phone_empty); + //V.ifEmpty(model.getAddress(), BizErrors.businessprofile_address_empty); + //V.ifEmpty(model.getExtraInfo(), BizErrors.businessprofile_extrainfo_empty); + //V.ifEmpty(model.getDescription(), BizErrors.businessprofile_description_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + var biz = AppModules.biz.getController(); + var businessStore = biz.getBusinessStore(); + + var business = businessStore.ensure(getContext(), argModel.getBusiness(), BizErrors.businessprofile_business_notfound); + var activity = BizTaxonomies.businessActivity.ensureDefault(getContext()); + + // model + var model = makeModel(business, activity); + + // add + entity = saveEntity(model); + + // add others + + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private BusinessProfileEntity makeModel(BusinessEntity business, TaxonEntity activity) { + + var argModel = getArgument().getEntity(); + var model = new BusinessProfileEntity(); + + // relations + model.setBusiness(business); + model.setActivity(activity); + model.setActivityValue(activity.getValue()); + + // fields + model.setGpsLatitude(argModel.getGpsLatitude()); + model.setGpsLongitude(argModel.getGpsLongitude()); + model.setWebsite(argModel.getWebsite()); + model.setPhone(argModel.getPhone()); + model.setAddress(argModel.getAddress()); + model.setExtraInfo(argModel.getExtraInfo()); + model.setDescription(argModel.getDescription()); + model.setActive(true); + + + + return model; + } + + // ::: save + // + private BusinessProfileEntity saveEntity(BusinessProfileEntity model) { + + var store = AppModules.biz.getController().getBusinessProfileStore(); + + var saved = store.add(getContext(), model); + getContext().attach(saved.getId(), saved); + return saved; + } + + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfileAddArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfileAddArgument.java new file mode 100644 index 0000000..4593895 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfileAddArgument.java @@ -0,0 +1,34 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessprofile; + + +// app +import io.kumare.iqr.mod.biz.store.businessprofile.BusinessProfileEntity; + + +/** + * + * @author afatecha + */ +public class BusinessProfileAddArgument extends BusinessProfileActionArgument { + + // ::: vars + // + + + // ::: constructors + // + public BusinessProfileAddArgument() { + } + + public BusinessProfileAddArgument(BusinessProfileEntity entity) { + super(entity); + } + + // ::: fields + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfileDeleteAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfileDeleteAction.java new file mode 100644 index 0000000..54766ef --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfileDeleteAction.java @@ -0,0 +1,59 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessprofile; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businessprofile.BusinessProfileEntity; + +/** + * + * @author afatecha + */ +public class BusinessProfileDeleteAction extends AppAction> { + + // ::: vars + // + private BusinessProfileEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), BizErrors.businessprofile_notfound); + V.ifNull(getArgument().getEntity().getId(), BizErrors.businessprofile_notfound); + } + + @Override + protected void doAction() { + + var argModel = getArgument().getEntity(); + + deleteEntity(argModel); + } + + @Override + protected void setResultOnly() { + } + + // ::: delete + // + private void deleteEntity(BusinessProfileEntity model) { + + var store = AppModules.biz.getController().getBusinessProfileStore(); + + store.deleteById(getContext(), model.getId()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfileEditAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfileEditAction.java new file mode 100644 index 0000000..c5a5150 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfileEditAction.java @@ -0,0 +1,107 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessprofile; + +// lib +import io.kumare.lib.v.V; +// app +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businessprofile.BusinessProfileEntity; + +/** + * + * @author afatecha + */ +public class BusinessProfileEditAction extends AppAction> { + + // ::: vars + // + private BusinessProfileEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, BizErrors.businessprofile_notfound); + + // fields + V.ifEmpty(model.getActivityValue(), BizErrors.businessprofile_activityvalue_empty); + V.ifEmpty(model.getGpsLatitude(), BizErrors.businessprofile_gpslatitude_empty); + V.ifEmpty(model.getGpsLongitude(), BizErrors.businessprofile_gpslongitude_empty); + V.ifEmpty(model.getWebsite(), BizErrors.businessprofile_website_empty); + V.ifEmpty(model.getPhone(), BizErrors.businessprofile_phone_empty); + V.ifEmpty(model.getAddress(), BizErrors.businessprofile_address_empty); + V.ifEmpty(model.getExtraInfo(), BizErrors.businessprofile_extrainfo_empty); + V.ifEmpty(model.getDescription(), BizErrors.businessprofile_description_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + + var biz = AppModules.biz.getController(); + var businessProfileStore = biz.getBusinessProfileStore(); + + // edit + entity = businessProfileStore.ensure(getContext(), argModel, BizErrors.businessprofile_notfound); + + editEntity(); + + entity = saveEntity(); + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private void editEntity() { + + var model = getArgument().getEntity(); + + // fields + entity.setActivityValue(V.firstNotEmpty(model.getActivityValue(), entity.getActivityValue())); + entity.setGpsLatitude(V.firstNotEmpty(model.getGpsLatitude(), entity.getGpsLatitude())); + entity.setGpsLongitude(V.firstNotEmpty(model.getGpsLongitude(), entity.getGpsLongitude())); + entity.setWebsite(V.firstNotEmpty(model.getWebsite(), entity.getWebsite())); + entity.setPhone(V.firstNotEmpty(model.getPhone(), entity.getPhone())); + entity.setAddress(V.firstNotEmpty(model.getAddress(), entity.getAddress())); + entity.setExtraInfo(V.firstNotEmpty(model.getExtraInfo(), entity.getExtraInfo())); + entity.setDescription(V.firstNotEmpty(model.getDescription(), entity.getDescription())); + + + } + + // ::: save + // + private BusinessProfileEntity saveEntity() { + + var store = AppModules.biz.getController().getBusinessProfileStore(); + + var saved = store.edit(getContext(), entity); + getContext().attach(saved.getId(), saved); + return saved; + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfileEditArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfileEditArgument.java new file mode 100644 index 0000000..2a71600 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfileEditArgument.java @@ -0,0 +1,32 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessprofile; + +// app +import io.kumare.iqr.mod.biz.store.businessprofile.BusinessProfileEntity; + +/** + * + * @author afatecha + */ +public class BusinessProfileEditArgument extends BusinessProfileActionArgument { + + // ::: vars + // + + + // ::: constructors + // + public BusinessProfileEditArgument() { + } + + public BusinessProfileEditArgument(BusinessProfileEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfileEnableAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfileEnableAction.java new file mode 100644 index 0000000..46f0aec --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfileEnableAction.java @@ -0,0 +1,60 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessprofile; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businessprofile.BusinessProfileEntity; + + +/** + * + * @author afatecha + */ +public class BusinessProfileEnableAction extends AppAction { + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), BizErrors.businessprofile_notfound); + V.ifNull(getArgument().getEntity().getId(), BizErrors.businessprofile_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + + enableEntity(model); + } + + @Override + protected void setResultOnly() { + } + + // ::: enable + // + private void enableEntity(BusinessProfileEntity model) { + + var store = AppModules.biz.getController().getBusinessProfileStore(); + + if (getArgument().getEntity().isActive()) { + store.enableById(getContext(), model.getId()); + } else { + store.disableById(getContext(), model.getId()); + } + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfileFindAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfileFindAction.java new file mode 100644 index 0000000..bf8586e --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfileFindAction.java @@ -0,0 +1,64 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessprofile; + +// java +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businessprofile.BusinessProfileEntity; + + +/** + * + * @author afatecha + */ +public class BusinessProfileFindAction extends AppAction { + + // ::: vars + // + private BusinessProfileEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), BizErrors.businessprofile_notfound); + V.ifNull(getArgument().getEntity().getId(), BizErrors.businessprofile_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + entity = findEntity(model); + } + + @Override + protected void setResultOnly() { + var result = new HashMap(); + result.put("entity", entity); + setResult(result); + } + + // ::: find + // + private BusinessProfileEntity findEntity(BusinessProfileEntity model) { + + var store = AppModules.biz.getController().getBusinessProfileStore(); + return store.findById(getContext(), model.getId()); + } + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfileListAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfileListAction.java new file mode 100644 index 0000000..92f8842 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfileListAction.java @@ -0,0 +1,149 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessprofile; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.LinkedList; +import java.util.Map; +// spring +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// entity +import io.kumare.iqr.mod.biz.store.businessprofile.BusinessProfileEntity; +import io.kumare.iqr.mod.biz.store.businessprofile.BusinessProfileMapBuilder; + + +/** + * + * @author afatecha + */ +public class BusinessProfileListAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private final List entities = new LinkedList<>(); + + // ::: public api + // + public List getEntities() { + return entities; + } + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + } + + @Override + protected void doAction() { + + result.put("pageable", getArgument().isPageable()); + result.put("wrapped", getArgument().isWrapped()); + + if (getArgument().isPageable()) { + + var page = makePage(); + entities.addAll(page.toList()); + + if (getArgument().isWrapped()) { + result.put("page", makeWrappedPage(page)); + } else { + result.put("page", page); + } + + } else { + + var list = makeList(); + entities.addAll(list); + + if (getArgument().isWrapped()) { + result.put("list", makeWrappedList()); + } else { + result.put("list", list); + } + } + + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: page + // + private Page makePage() { + + var page = getArgument().getPageNumber(); + var size = getArgument().getPageSize(); + //var sort = getArgument().getSort(); + + var pageable = PageRequest.of(page, size); + + var store = AppModules.biz.getController().getBusinessProfileStore(); + return store.getRepository().findAll(pageable); + } + + // ::: wrapped page + // + private Map makeWrappedPage(Page found) { + + var page = new HashMap(); + var content = new LinkedList(); + + wrapList(entities, content); + + page.put("size", found.getSize()); + page.put("number", found.getNumber()); + page.put("totalElements", found.getTotalElements()); + page.put("totalPages", found.getTotalPages()); + page.put("content", content); + + return page; + } + + + // ::: list + // + + private List makeList() { + + var store = AppModules.biz.getController().getBusinessProfileStore(); + + return store.listAll(getContext()); + } + + // ::: wrapped list + private List makeWrappedList() { + var list = new LinkedList(); + + wrapList(entities, list); + + return list; + } + + // ::: wrapper + // + private void wrapList(List found, List output) { + + var builder = new BusinessProfileMapBuilder().addListGroup(); + builder.getBusinessBuilder().addMainGroup(); + builder.getActivityBuilder().addMainGroup(); + + output.addAll(builder.build(getContext(), found)); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfileListArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfileListArgument.java new file mode 100644 index 0000000..0200fd9 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfileListArgument.java @@ -0,0 +1,33 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessprofile; + +// app +import io.kumare.iqr.app.action.AppListActionArgument; +// store +import io.kumare.iqr.mod.biz.store.businessprofile.BusinessProfileEntity; + +/** + * + * @author afatecha + */ +public class BusinessProfileListArgument extends AppListActionArgument { + + // ::: vars + // + + // ::: constructors + // + public BusinessProfileListArgument() { + } + + public BusinessProfileListArgument(BusinessProfileEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfilePreloadAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfilePreloadAction.java new file mode 100644 index 0000000..e948fc2 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfilePreloadAction.java @@ -0,0 +1,114 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessprofile; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businessprofile.BusinessProfileEntity; +// relations +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; + +/** + * + * @author afatecha + */ +public class BusinessProfilePreloadAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private Map params = new HashMap<>(); + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifEmpty(getArgument().getAction(), BizErrors.businessprofile_preload_empty); + } + + @Override + protected void doAction() { + if (getArgument().getParams() != null) { + params = getArgument().getParams(); + } + + switch (getArgument().getAction()) { + case "find" -> + prepareFind(); + case "list" -> + prepareList(); + case "add" -> + prepareAdd(); + case "edit" -> + prepareEdit(); + } + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: preload + // + private void prepareAdd() { + result.put("taxons", listTaxons()); + result.put("businesss", listBusinesss()); + } + + private void prepareEdit() { + var entity = findEntity(); + result.put("entity", entity); + result.put("business", entity.getBusiness()); + result.put("activity", entity.getActivity()); + } + + private void prepareList() { + } + + private void prepareFind() { + var entity = findEntity(); + result.put("entity", entity); + result.put("business", entity.getBusiness()); + result.put("activity", entity.getActivity()); + } + + // ::: queries + // + private BusinessProfileEntity findEntity() { + var store = AppModules.biz.getController().getBusinessProfileStore(); + + var id = (String) params.get("id"); + if (id == null && getArgument().getEntity() != null) { + id = getArgument().getEntity().getId(); + } + return store.findById(getContext(), id); + } + + public List listBusinesss() { + var store = AppModules.biz.getController().getBusinessStore(); + + return store.listAll(getContext()); + } + + public List listTaxons() { + var store = AppModules.taxonomy.getController().getTaxonStore(); + + return store.listAll(getContext()); + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfilePreloadArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfilePreloadArgument.java new file mode 100644 index 0000000..6b2ff81 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessprofile/BusinessProfilePreloadArgument.java @@ -0,0 +1,26 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessprofile; + +/** + * + * @author afatecha + */ +public class BusinessProfilePreloadArgument extends BusinessProfileActionArgument { + + // ::: vars + // + private String action; + + // ::: fields + // + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoActionArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoActionArgument.java new file mode 100644 index 0000000..adc15d9 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoActionArgument.java @@ -0,0 +1,29 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesspromo; + +// base +import io.kumare.iqr.app.action.AppEntityActionArgument; +// entity +import io.kumare.iqr.mod.biz.store.businesspromo.BusinessPromoEntity; + +/** + * + * @author afatecha + */ +public class BusinessPromoActionArgument extends AppEntityActionArgument { + + // ::: constructors + // + public BusinessPromoActionArgument() { + } + + public BusinessPromoActionArgument(BusinessPromoEntity entity) { + super(entity); + } + + // ::: api + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoAddAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoAddAction.java new file mode 100644 index 0000000..1c65200 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoAddAction.java @@ -0,0 +1,149 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesspromo; + +// java +import java.util.List; +// lib +import io.kumare.lib.base.server.spring.action.Actions; +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businesspromo.BusinessPromoEntity; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; +import io.kumare.iqr.mod.biz.store.businessimage.BusinessImageEntity; +import io.kumare.iqr.mod.biz.action.businesspromoitem.BusinessPromoItemAddAction; +import io.kumare.iqr.mod.biz.action.businesspromoitem.BusinessPromoItemAddArgument; + +/** + * + * @author afatecha + */ +public class BusinessPromoAddAction extends AppAction> { + + // ::: vars + // + private BusinessPromoEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, BizErrors.businesspromo_notfound); + + // relations + V.ifNull(model.getBusiness(), BizErrors.businesspromo_business_notfound); + V.ifNull(model.getImage(), BizErrors.businesspromo_image_notfound); + V.ifNull(model.getState(), BizErrors.businesspromo_state_notfound); + + // fields + V.ifEmpty(model.getStateValue(), BizErrors.businesspromo_statevalue_empty); + V.ifEmpty(model.getStarted(), BizErrors.businesspromo_started_empty); + V.ifEmpty(model.getEnded(), BizErrors.businesspromo_ended_empty); + V.ifEmpty(model.getScheduleStart(), BizErrors.businesspromo_schedulestart_empty); + V.ifEmpty(model.getScheduleEnd(), BizErrors.businesspromo_scheduleend_empty); + V.ifEmpty(model.getTitle(), BizErrors.businesspromo_title_empty); + V.ifEmpty(model.getBodyInfo(), BizErrors.businesspromo_bodyinfo_empty); + V.ifEmpty(model.getFooterInfo(), BizErrors.businesspromo_footerinfo_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + var biz = AppModules.biz.getController(); + var taxonomy = AppModules.taxonomy.getController(); + + var businessStore = biz.getBusinessStore(); + var businessImageStore = biz.getBusinessImageStore(); + var taxonStore = taxonomy.getTaxonStore(); + + var business = businessStore.ensure(getContext(), argModel.getBusiness(), BizErrors.businesspromo_business_notfound); + var image = businessImageStore.ensure(getContext(), argModel.getImage(), BizErrors.businesspromo_image_notfound); + var state = taxonStore.ensure(getContext(), argModel.getState(), BizErrors.businesspromo_state_notfound); + + // model + var model = makeModel(business, image, state); + + // add + entity = saveEntity(model); + + // add others + addItems(getArgument().getItems()); + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private BusinessPromoEntity makeModel(BusinessEntity business, BusinessImageEntity image, TaxonEntity state) { + + var argModel = getArgument().getEntity(); + var model = new BusinessPromoEntity(); + + // relations + model.setBusiness(business); + model.setImage(image); + model.setState(state); + + // fields + model.setStateValue(argModel.getStateValue()); + model.setStarted(argModel.getStarted()); + model.setEnded(argModel.getEnded()); + model.setScheduleStart(argModel.getScheduleStart()); + model.setScheduleEnd(argModel.getScheduleEnd()); + model.setTitle(argModel.getTitle()); + model.setBodyInfo(argModel.getBodyInfo()); + model.setFooterInfo(argModel.getFooterInfo()); + model.setActive(true); + + + + return model; + } + + // ::: save + // + private BusinessPromoEntity saveEntity(BusinessPromoEntity model) { + + var store = AppModules.biz.getController().getBusinessPromoStore(); + + var saved = store.add(getContext(), model); + getContext().attach(saved.getId(), saved); + return saved; + } + + // ::: add items + // + private void addItems(List list) { + if(list != null) { + list.forEach(i->{ + i.getEntity().promo(entity); + Actions.perform(getContext(), new BusinessPromoItemAddAction(), i); + }); + } + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoAddArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoAddArgument.java new file mode 100644 index 0000000..b95dc01 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoAddArgument.java @@ -0,0 +1,41 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesspromo; + +// java +import java.util.List; +// app +import io.kumare.iqr.mod.biz.store.businesspromo.BusinessPromoEntity; +import io.kumare.iqr.mod.biz.action.businesspromoitem.BusinessPromoItemAddArgument; + +/** + * + * @author afatecha + */ +public class BusinessPromoAddArgument extends BusinessPromoActionArgument { + + // ::: vars + // + private List items; + + // ::: constructors + // + public BusinessPromoAddArgument() { + } + + public BusinessPromoAddArgument(BusinessPromoEntity entity) { + super(entity); + } + + // ::: fields + // + public List getItems() { + return items; + } + + public void setItems(List list) { + this.items = list; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoDeleteAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoDeleteAction.java new file mode 100644 index 0000000..9472192 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoDeleteAction.java @@ -0,0 +1,59 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesspromo; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businesspromo.BusinessPromoEntity; + +/** + * + * @author afatecha + */ +public class BusinessPromoDeleteAction extends AppAction> { + + // ::: vars + // + private BusinessPromoEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), BizErrors.businesspromo_notfound); + V.ifNull(getArgument().getEntity().getId(), BizErrors.businesspromo_notfound); + } + + @Override + protected void doAction() { + + var argModel = getArgument().getEntity(); + + deleteEntity(argModel); + } + + @Override + protected void setResultOnly() { + } + + // ::: delete + // + private void deleteEntity(BusinessPromoEntity model) { + + var store = AppModules.biz.getController().getBusinessPromoStore(); + + store.deleteById(getContext(), model.getId()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoEditAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoEditAction.java new file mode 100644 index 0000000..a8211a3 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoEditAction.java @@ -0,0 +1,107 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesspromo; + +// lib +import io.kumare.lib.v.V; +// app +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businesspromo.BusinessPromoEntity; + +/** + * + * @author afatecha + */ +public class BusinessPromoEditAction extends AppAction> { + + // ::: vars + // + private BusinessPromoEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, BizErrors.businesspromo_notfound); + + // fields + V.ifEmpty(model.getStateValue(), BizErrors.businesspromo_statevalue_empty); + V.ifEmpty(model.getStarted(), BizErrors.businesspromo_started_empty); + V.ifEmpty(model.getEnded(), BizErrors.businesspromo_ended_empty); + V.ifEmpty(model.getScheduleStart(), BizErrors.businesspromo_schedulestart_empty); + V.ifEmpty(model.getScheduleEnd(), BizErrors.businesspromo_scheduleend_empty); + V.ifEmpty(model.getTitle(), BizErrors.businesspromo_title_empty); + V.ifEmpty(model.getBodyInfo(), BizErrors.businesspromo_bodyinfo_empty); + V.ifEmpty(model.getFooterInfo(), BizErrors.businesspromo_footerinfo_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + + var biz = AppModules.biz.getController(); + var businessPromoStore = biz.getBusinessPromoStore(); + + // edit + entity = businessPromoStore.ensure(getContext(), argModel, BizErrors.businesspromo_notfound); + + editEntity(); + + entity = saveEntity(); + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private void editEntity() { + + var model = getArgument().getEntity(); + + // fields + entity.setStateValue(V.firstNotEmpty(model.getStateValue(), entity.getStateValue())); + entity.setStarted(V.firstNotEmpty(model.getStarted(), entity.getStarted())); + entity.setEnded(V.firstNotEmpty(model.getEnded(), entity.getEnded())); + entity.setScheduleStart(V.firstNotEmpty(model.getScheduleStart(), entity.getScheduleStart())); + entity.setScheduleEnd(V.firstNotEmpty(model.getScheduleEnd(), entity.getScheduleEnd())); + entity.setTitle(V.firstNotEmpty(model.getTitle(), entity.getTitle())); + entity.setBodyInfo(V.firstNotEmpty(model.getBodyInfo(), entity.getBodyInfo())); + entity.setFooterInfo(V.firstNotEmpty(model.getFooterInfo(), entity.getFooterInfo())); + + + } + + // ::: save + // + private BusinessPromoEntity saveEntity() { + + var store = AppModules.biz.getController().getBusinessPromoStore(); + + var saved = store.edit(getContext(), entity); + getContext().attach(saved.getId(), saved); + return saved; + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoEditArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoEditArgument.java new file mode 100644 index 0000000..97eeccd --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoEditArgument.java @@ -0,0 +1,32 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesspromo; + +// app +import io.kumare.iqr.mod.biz.store.businesspromo.BusinessPromoEntity; + +/** + * + * @author afatecha + */ +public class BusinessPromoEditArgument extends BusinessPromoActionArgument { + + // ::: vars + // + + + // ::: constructors + // + public BusinessPromoEditArgument() { + } + + public BusinessPromoEditArgument(BusinessPromoEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoEnableAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoEnableAction.java new file mode 100644 index 0000000..d28c556 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoEnableAction.java @@ -0,0 +1,60 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesspromo; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businesspromo.BusinessPromoEntity; + + +/** + * + * @author afatecha + */ +public class BusinessPromoEnableAction extends AppAction { + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), BizErrors.businesspromo_notfound); + V.ifNull(getArgument().getEntity().getId(), BizErrors.businesspromo_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + + enableEntity(model); + } + + @Override + protected void setResultOnly() { + } + + // ::: enable + // + private void enableEntity(BusinessPromoEntity model) { + + var store = AppModules.biz.getController().getBusinessPromoStore(); + + if (getArgument().getEntity().isActive()) { + store.enableById(getContext(), model.getId()); + } else { + store.disableById(getContext(), model.getId()); + } + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoFindAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoFindAction.java new file mode 100644 index 0000000..80a07aa --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoFindAction.java @@ -0,0 +1,64 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesspromo; + +// java +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businesspromo.BusinessPromoEntity; + + +/** + * + * @author afatecha + */ +public class BusinessPromoFindAction extends AppAction { + + // ::: vars + // + private BusinessPromoEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), BizErrors.businesspromo_notfound); + V.ifNull(getArgument().getEntity().getId(), BizErrors.businesspromo_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + entity = findEntity(model); + } + + @Override + protected void setResultOnly() { + var result = new HashMap(); + result.put("entity", entity); + setResult(result); + } + + // ::: find + // + private BusinessPromoEntity findEntity(BusinessPromoEntity model) { + + var store = AppModules.biz.getController().getBusinessPromoStore(); + return store.findById(getContext(), model.getId()); + } + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoListAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoListAction.java new file mode 100644 index 0000000..ceb96fb --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoListAction.java @@ -0,0 +1,150 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesspromo; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.LinkedList; +import java.util.Map; +// spring +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// entity +import io.kumare.iqr.mod.biz.store.businesspromo.BusinessPromoEntity; +import io.kumare.iqr.mod.biz.store.businesspromo.BusinessPromoMapBuilder; + + +/** + * + * @author afatecha + */ +public class BusinessPromoListAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private final List entities = new LinkedList<>(); + + // ::: public api + // + public List getEntities() { + return entities; + } + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + } + + @Override + protected void doAction() { + + result.put("pageable", getArgument().isPageable()); + result.put("wrapped", getArgument().isWrapped()); + + if (getArgument().isPageable()) { + + var page = makePage(); + entities.addAll(page.toList()); + + if (getArgument().isWrapped()) { + result.put("page", makeWrappedPage(page)); + } else { + result.put("page", page); + } + + } else { + + var list = makeList(); + entities.addAll(list); + + if (getArgument().isWrapped()) { + result.put("list", makeWrappedList()); + } else { + result.put("list", list); + } + } + + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: page + // + private Page makePage() { + + var page = getArgument().getPageNumber(); + var size = getArgument().getPageSize(); + //var sort = getArgument().getSort(); + + var pageable = PageRequest.of(page, size); + + var store = AppModules.biz.getController().getBusinessPromoStore(); + return store.getRepository().findAll(pageable); + } + + // ::: wrapped page + // + private Map makeWrappedPage(Page found) { + + var page = new HashMap(); + var content = new LinkedList(); + + wrapList(entities, content); + + page.put("size", found.getSize()); + page.put("number", found.getNumber()); + page.put("totalElements", found.getTotalElements()); + page.put("totalPages", found.getTotalPages()); + page.put("content", content); + + return page; + } + + + // ::: list + // + + private List makeList() { + + var store = AppModules.biz.getController().getBusinessPromoStore(); + + return store.listAll(getContext()); + } + + // ::: wrapped list + private List makeWrappedList() { + var list = new LinkedList(); + + wrapList(entities, list); + + return list; + } + + // ::: wrapper + // + private void wrapList(List found, List output) { + + var builder = new BusinessPromoMapBuilder().addListGroup(); + builder.getBusinessBuilder().addMainGroup(); + builder.getImageBuilder().addMainGroup(); + builder.getStateBuilder().addMainGroup(); + + output.addAll(builder.build(getContext(), found)); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoListArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoListArgument.java new file mode 100644 index 0000000..a6a5100 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoListArgument.java @@ -0,0 +1,33 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesspromo; + +// app +import io.kumare.iqr.app.action.AppListActionArgument; +// store +import io.kumare.iqr.mod.biz.store.businesspromo.BusinessPromoEntity; + +/** + * + * @author afatecha + */ +public class BusinessPromoListArgument extends AppListActionArgument { + + // ::: vars + // + + // ::: constructors + // + public BusinessPromoListArgument() { + } + + public BusinessPromoListArgument(BusinessPromoEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoPreloadAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoPreloadAction.java new file mode 100644 index 0000000..c1bceff --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoPreloadAction.java @@ -0,0 +1,123 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesspromo; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businesspromo.BusinessPromoEntity; +// relations +import io.kumare.iqr.mod.biz.store.businessimage.BusinessImageEntity; +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; + +/** + * + * @author afatecha + */ +public class BusinessPromoPreloadAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private Map params = new HashMap<>(); + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifEmpty(getArgument().getAction(), BizErrors.businesspromo_preload_empty); + } + + @Override + protected void doAction() { + if(getArgument().getParams() != null) { + params = getArgument().getParams(); + } + + switch (getArgument().getAction()) { + case "find" -> + prepareFind(); + case "list" -> + prepareList(); + case "add" -> + prepareAdd(); + case "edit" -> + prepareEdit(); + } + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: preload + // + private void prepareAdd() { + result.put("taxons", listTaxons()); + result.put("businessImages", listBusinessImages()); + result.put("businesss", listBusinesss()); + } + + private void prepareEdit() { + var entity = findEntity(); + result.put("entity", entity); + result.put("business", entity.getBusiness()); + result.put("image", entity.getImage()); + result.put("state", entity.getState()); + } + + private void prepareList() { + } + + private void prepareFind() { + var entity = findEntity(); + result.put("entity", entity); + result.put("business", entity.getBusiness()); + result.put("image", entity.getImage()); + result.put("state", entity.getState()); + } + + // ::: queries + // + private BusinessPromoEntity findEntity() { + var store = AppModules.biz.getController().getBusinessPromoStore(); + + var id = (String) params.get("id"); + if(id == null && getArgument().getEntity() != null) { + id = getArgument().getEntity().getId(); + } + return store.findById(getContext(), id); + } + + public List listBusinessImages() { + var store = AppModules.biz.getController().getBusinessImageStore(); + + return store.listAll(getContext()); + } + public List listBusinesss() { + var store = AppModules.biz.getController().getBusinessStore(); + + return store.listAll(getContext()); + } + public List listTaxons() { + var store = AppModules.taxonomy.getController().getTaxonStore(); + + return store.listAll(getContext()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoPreloadArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoPreloadArgument.java new file mode 100644 index 0000000..caf8adf --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromo/BusinessPromoPreloadArgument.java @@ -0,0 +1,26 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesspromo; + +/** + * + * @author afatecha + */ +public class BusinessPromoPreloadArgument extends BusinessPromoActionArgument { + + // ::: vars + // + private String action; + + // ::: fields + // + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemActionArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemActionArgument.java new file mode 100644 index 0000000..913d272 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemActionArgument.java @@ -0,0 +1,29 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesspromoitem; + +// base +import io.kumare.iqr.app.action.AppEntityActionArgument; +// entity +import io.kumare.iqr.mod.biz.store.businesspromoitem.BusinessPromoItemEntity; + +/** + * + * @author afatecha + */ +public class BusinessPromoItemActionArgument extends AppEntityActionArgument { + + // ::: constructors + // + public BusinessPromoItemActionArgument() { + } + + public BusinessPromoItemActionArgument(BusinessPromoItemEntity entity) { + super(entity); + } + + // ::: api + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemAddAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemAddAction.java new file mode 100644 index 0000000..b863462 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemAddAction.java @@ -0,0 +1,129 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesspromoitem; + + +// lib +import io.kumare.lib.base.server.spring.action.Actions; +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businesspromoitem.BusinessPromoItemEntity; +import io.kumare.iqr.mod.biz.store.businesspromo.BusinessPromoEntity; +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; +import io.kumare.iqr.mod.biz.store.businessimage.BusinessImageEntity; + + +/** + * + * @author afatecha + */ +public class BusinessPromoItemAddAction extends AppAction> { + + // ::: vars + // + private BusinessPromoItemEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, BizErrors.businesspromoitem_notfound); + + // relations + V.ifNull(model.getBusiness(), BizErrors.businesspromoitem_business_notfound); + V.ifNull(model.getPromo(), BizErrors.businesspromoitem_promo_notfound); + V.ifNull(model.getImage(), BizErrors.businesspromoitem_image_notfound); + + // fields + V.ifEmpty(model.getTitle(), BizErrors.businesspromoitem_title_empty); + V.ifEmpty(model.getDescription(), BizErrors.businesspromoitem_description_empty); + V.ifEmpty(model.getPoints(), BizErrors.businesspromoitem_points_empty); + V.ifEmpty(model.getCondition(), BizErrors.businesspromoitem_condition_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + var biz = AppModules.biz.getController(); + + var businessPromoStore = biz.getBusinessPromoStore(); + var businessStore = biz.getBusinessStore(); + var businessImageStore = biz.getBusinessImageStore(); + + var business = businessStore.ensure(getContext(), argModel.getBusiness(), BizErrors.businesspromoitem_business_notfound); + var promo = businessPromoStore.ensure(getContext(), argModel.getPromo(), BizErrors.businesspromoitem_promo_notfound); + var image = businessImageStore.ensure(getContext(), argModel.getImage(), BizErrors.businesspromoitem_image_notfound); + + // model + var model = makeModel(business, promo, image); + + // add + entity = saveEntity(model); + + // add others + + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private BusinessPromoItemEntity makeModel(BusinessEntity business, BusinessPromoEntity promo, BusinessImageEntity image) { + + var argModel = getArgument().getEntity(); + var model = new BusinessPromoItemEntity(); + + // relations + model.setBusiness(business); + model.setPromo(promo); + model.setImage(image); + + // fields + model.setTitle(argModel.getTitle()); + model.setDescription(argModel.getDescription()); + model.setPoints(argModel.getPoints()); + model.setCondition(argModel.getCondition()); + model.setActive(true); + + + + return model; + } + + // ::: save + // + private BusinessPromoItemEntity saveEntity(BusinessPromoItemEntity model) { + + var store = AppModules.biz.getController().getBusinessPromoItemStore(); + + var saved = store.add(getContext(), model); + getContext().attach(saved.getId(), saved); + return saved; + } + + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemAddArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemAddArgument.java new file mode 100644 index 0000000..a20a0a1 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemAddArgument.java @@ -0,0 +1,34 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesspromoitem; + + +// app +import io.kumare.iqr.mod.biz.store.businesspromoitem.BusinessPromoItemEntity; + + +/** + * + * @author afatecha + */ +public class BusinessPromoItemAddArgument extends BusinessPromoItemActionArgument { + + // ::: vars + // + + + // ::: constructors + // + public BusinessPromoItemAddArgument() { + } + + public BusinessPromoItemAddArgument(BusinessPromoItemEntity entity) { + super(entity); + } + + // ::: fields + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemDeleteAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemDeleteAction.java new file mode 100644 index 0000000..25f77d9 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemDeleteAction.java @@ -0,0 +1,59 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesspromoitem; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businesspromoitem.BusinessPromoItemEntity; + +/** + * + * @author afatecha + */ +public class BusinessPromoItemDeleteAction extends AppAction> { + + // ::: vars + // + private BusinessPromoItemEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), BizErrors.businesspromoitem_notfound); + V.ifNull(getArgument().getEntity().getId(), BizErrors.businesspromoitem_notfound); + } + + @Override + protected void doAction() { + + var argModel = getArgument().getEntity(); + + deleteEntity(argModel); + } + + @Override + protected void setResultOnly() { + } + + // ::: delete + // + private void deleteEntity(BusinessPromoItemEntity model) { + + var store = AppModules.biz.getController().getBusinessPromoItemStore(); + + store.deleteById(getContext(), model.getId()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemEditAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemEditAction.java new file mode 100644 index 0000000..e4aeb0f --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemEditAction.java @@ -0,0 +1,99 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesspromoitem; + +// lib +import io.kumare.lib.v.V; +// app +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businesspromoitem.BusinessPromoItemEntity; + +/** + * + * @author afatecha + */ +public class BusinessPromoItemEditAction extends AppAction> { + + // ::: vars + // + private BusinessPromoItemEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, BizErrors.businesspromoitem_notfound); + + // fields + V.ifEmpty(model.getTitle(), BizErrors.businesspromoitem_title_empty); + V.ifEmpty(model.getDescription(), BizErrors.businesspromoitem_description_empty); + V.ifEmpty(model.getPoints(), BizErrors.businesspromoitem_points_empty); + V.ifEmpty(model.getCondition(), BizErrors.businesspromoitem_condition_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + + var biz = AppModules.biz.getController(); + var businessPromoItemStore = biz.getBusinessPromoItemStore(); + + // edit + entity = businessPromoItemStore.ensure(getContext(), argModel, BizErrors.businesspromoitem_notfound); + + editEntity(); + + entity = saveEntity(); + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private void editEntity() { + + var model = getArgument().getEntity(); + + // fields + entity.setTitle(V.firstNotEmpty(model.getTitle(), entity.getTitle())); + entity.setDescription(V.firstNotEmpty(model.getDescription(), entity.getDescription())); + entity.setPoints(V.firstNotEmpty(model.getPoints(), entity.getPoints())); + entity.setCondition(V.firstNotEmpty(model.getCondition(), entity.getCondition())); + + + } + + // ::: save + // + private BusinessPromoItemEntity saveEntity() { + + var store = AppModules.biz.getController().getBusinessPromoItemStore(); + + var saved = store.edit(getContext(), entity); + getContext().attach(saved.getId(), saved); + return saved; + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemEditArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemEditArgument.java new file mode 100644 index 0000000..b0b6650 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemEditArgument.java @@ -0,0 +1,32 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesspromoitem; + +// app +import io.kumare.iqr.mod.biz.store.businesspromoitem.BusinessPromoItemEntity; + +/** + * + * @author afatecha + */ +public class BusinessPromoItemEditArgument extends BusinessPromoItemActionArgument { + + // ::: vars + // + + + // ::: constructors + // + public BusinessPromoItemEditArgument() { + } + + public BusinessPromoItemEditArgument(BusinessPromoItemEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemEnableAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemEnableAction.java new file mode 100644 index 0000000..2c97339 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemEnableAction.java @@ -0,0 +1,60 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesspromoitem; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businesspromoitem.BusinessPromoItemEntity; + + +/** + * + * @author afatecha + */ +public class BusinessPromoItemEnableAction extends AppAction { + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), BizErrors.businesspromoitem_notfound); + V.ifNull(getArgument().getEntity().getId(), BizErrors.businesspromoitem_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + + enableEntity(model); + } + + @Override + protected void setResultOnly() { + } + + // ::: enable + // + private void enableEntity(BusinessPromoItemEntity model) { + + var store = AppModules.biz.getController().getBusinessPromoItemStore(); + + if (getArgument().getEntity().isActive()) { + store.enableById(getContext(), model.getId()); + } else { + store.disableById(getContext(), model.getId()); + } + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemFindAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemFindAction.java new file mode 100644 index 0000000..32070e3 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemFindAction.java @@ -0,0 +1,64 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesspromoitem; + +// java +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businesspromoitem.BusinessPromoItemEntity; + + +/** + * + * @author afatecha + */ +public class BusinessPromoItemFindAction extends AppAction { + + // ::: vars + // + private BusinessPromoItemEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), BizErrors.businesspromoitem_notfound); + V.ifNull(getArgument().getEntity().getId(), BizErrors.businesspromoitem_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + entity = findEntity(model); + } + + @Override + protected void setResultOnly() { + var result = new HashMap(); + result.put("entity", entity); + setResult(result); + } + + // ::: find + // + private BusinessPromoItemEntity findEntity(BusinessPromoItemEntity model) { + + var store = AppModules.biz.getController().getBusinessPromoItemStore(); + return store.findById(getContext(), model.getId()); + } + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemListAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemListAction.java new file mode 100644 index 0000000..6b84481 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemListAction.java @@ -0,0 +1,150 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesspromoitem; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.LinkedList; +import java.util.Map; +// spring +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// entity +import io.kumare.iqr.mod.biz.store.businesspromoitem.BusinessPromoItemEntity; +import io.kumare.iqr.mod.biz.store.businesspromoitem.BusinessPromoItemMapBuilder; + + +/** + * + * @author afatecha + */ +public class BusinessPromoItemListAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private final List entities = new LinkedList<>(); + + // ::: public api + // + public List getEntities() { + return entities; + } + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + } + + @Override + protected void doAction() { + + result.put("pageable", getArgument().isPageable()); + result.put("wrapped", getArgument().isWrapped()); + + if (getArgument().isPageable()) { + + var page = makePage(); + entities.addAll(page.toList()); + + if (getArgument().isWrapped()) { + result.put("page", makeWrappedPage(page)); + } else { + result.put("page", page); + } + + } else { + + var list = makeList(); + entities.addAll(list); + + if (getArgument().isWrapped()) { + result.put("list", makeWrappedList()); + } else { + result.put("list", list); + } + } + + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: page + // + private Page makePage() { + + var page = getArgument().getPageNumber(); + var size = getArgument().getPageSize(); + //var sort = getArgument().getSort(); + + var pageable = PageRequest.of(page, size); + + var store = AppModules.biz.getController().getBusinessPromoItemStore(); + return store.getRepository().findAll(pageable); + } + + // ::: wrapped page + // + private Map makeWrappedPage(Page found) { + + var page = new HashMap(); + var content = new LinkedList(); + + wrapList(entities, content); + + page.put("size", found.getSize()); + page.put("number", found.getNumber()); + page.put("totalElements", found.getTotalElements()); + page.put("totalPages", found.getTotalPages()); + page.put("content", content); + + return page; + } + + + // ::: list + // + + private List makeList() { + + var store = AppModules.biz.getController().getBusinessPromoItemStore(); + + return store.listAll(getContext()); + } + + // ::: wrapped list + private List makeWrappedList() { + var list = new LinkedList(); + + wrapList(entities, list); + + return list; + } + + // ::: wrapper + // + private void wrapList(List found, List output) { + + var builder = new BusinessPromoItemMapBuilder().addListGroup(); + builder.getBusinessBuilder().addMainGroup(); + builder.getPromoBuilder().addMainGroup(); + builder.getImageBuilder().addMainGroup(); + + output.addAll(builder.build(getContext(), found)); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemListArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemListArgument.java new file mode 100644 index 0000000..7e171f4 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemListArgument.java @@ -0,0 +1,33 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesspromoitem; + +// app +import io.kumare.iqr.app.action.AppListActionArgument; +// store +import io.kumare.iqr.mod.biz.store.businesspromoitem.BusinessPromoItemEntity; + +/** + * + * @author afatecha + */ +public class BusinessPromoItemListArgument extends AppListActionArgument { + + // ::: vars + // + + // ::: constructors + // + public BusinessPromoItemListArgument() { + } + + public BusinessPromoItemListArgument(BusinessPromoItemEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemPreloadAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemPreloadAction.java new file mode 100644 index 0000000..3c46adc --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemPreloadAction.java @@ -0,0 +1,123 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesspromoitem; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businesspromoitem.BusinessPromoItemEntity; +// relations +import io.kumare.iqr.mod.biz.store.businessimage.BusinessImageEntity; +import io.kumare.iqr.mod.biz.store.businesspromo.BusinessPromoEntity; +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; + +/** + * + * @author afatecha + */ +public class BusinessPromoItemPreloadAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private Map params = new HashMap<>(); + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifEmpty(getArgument().getAction(), BizErrors.businesspromoitem_preload_empty); + } + + @Override + protected void doAction() { + if(getArgument().getParams() != null) { + params = getArgument().getParams(); + } + + switch (getArgument().getAction()) { + case "find" -> + prepareFind(); + case "list" -> + prepareList(); + case "add" -> + prepareAdd(); + case "edit" -> + prepareEdit(); + } + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: preload + // + private void prepareAdd() { + result.put("businessPromos", listBusinessPromos()); + result.put("businessImages", listBusinessImages()); + result.put("businesss", listBusinesss()); + } + + private void prepareEdit() { + var entity = findEntity(); + result.put("entity", entity); + result.put("business", entity.getBusiness()); + result.put("promo", entity.getPromo()); + result.put("image", entity.getImage()); + } + + private void prepareList() { + } + + private void prepareFind() { + var entity = findEntity(); + result.put("entity", entity); + result.put("business", entity.getBusiness()); + result.put("promo", entity.getPromo()); + result.put("image", entity.getImage()); + } + + // ::: queries + // + private BusinessPromoItemEntity findEntity() { + var store = AppModules.biz.getController().getBusinessPromoItemStore(); + + var id = (String) params.get("id"); + if(id == null && getArgument().getEntity() != null) { + id = getArgument().getEntity().getId(); + } + return store.findById(getContext(), id); + } + + public List listBusinessPromos() { + var store = AppModules.biz.getController().getBusinessPromoStore(); + + return store.listAll(getContext()); + } + public List listBusinessImages() { + var store = AppModules.biz.getController().getBusinessImageStore(); + + return store.listAll(getContext()); + } + public List listBusinesss() { + var store = AppModules.biz.getController().getBusinessStore(); + + return store.listAll(getContext()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemPreloadArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemPreloadArgument.java new file mode 100644 index 0000000..d548cf4 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesspromoitem/BusinessPromoItemPreloadArgument.java @@ -0,0 +1,26 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesspromoitem; + +/** + * + * @author afatecha + */ +public class BusinessPromoItemPreloadArgument extends BusinessPromoItemActionArgument { + + // ::: vars + // + private String action; + + // ::: fields + // + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingActionArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingActionArgument.java new file mode 100644 index 0000000..193126d --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingActionArgument.java @@ -0,0 +1,29 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesssetting; + +// base +import io.kumare.iqr.app.action.AppEntityActionArgument; +// entity +import io.kumare.iqr.mod.biz.store.businesssetting.BusinessSettingEntity; + +/** + * + * @author afatecha + */ +public class BusinessSettingActionArgument extends AppEntityActionArgument { + + // ::: constructors + // + public BusinessSettingActionArgument() { + } + + public BusinessSettingActionArgument(BusinessSettingEntity entity) { + super(entity); + } + + // ::: api + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingAddAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingAddAction.java new file mode 100644 index 0000000..6957297 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingAddAction.java @@ -0,0 +1,117 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesssetting; + + +// lib +import io.kumare.lib.base.server.spring.action.Actions; +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businesssetting.BusinessSettingEntity; +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; + + +/** + * + * @author afatecha + */ +public class BusinessSettingAddAction extends AppAction> { + + // ::: vars + // + private BusinessSettingEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, BizErrors.businesssetting_notfound); + + // relations + V.ifNull(model.getBusiness(), BizErrors.businesssetting_business_notfound); + + // fields + V.ifEmpty(model.getPointExchange(), BizErrors.businesssetting_pointexchange_empty); + V.ifEmpty(model.getLeadCaptureReward(), BizErrors.businesssetting_leadcapturereward_empty); + V.ifEmpty(model.getCustomerCaptureReward(), BizErrors.businesssetting_customercapturereward_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + var biz = AppModules.biz.getController(); + + var businessStore = biz.getBusinessStore(); + + var business = businessStore.ensure(getContext(), argModel.getBusiness(), BizErrors.businesssetting_business_notfound); + + // model + var model = makeModel(business); + + // add + entity = saveEntity(model); + + // add others + + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private BusinessSettingEntity makeModel(BusinessEntity business) { + + var argModel = getArgument().getEntity(); + var model = new BusinessSettingEntity(); + + // relations + model.setBusiness(business); + + // fields + model.setPointExchange(argModel.getPointExchange()); + model.setLeadCaptureReward(argModel.getLeadCaptureReward()); + model.setCustomerCaptureReward(argModel.getCustomerCaptureReward()); + model.setActive(true); + + + + return model; + } + + // ::: save + // + private BusinessSettingEntity saveEntity(BusinessSettingEntity model) { + + var store = AppModules.biz.getController().getBusinessSettingStore(); + + var saved = store.add(getContext(), model); + getContext().attach(saved.getId(), saved); + return saved; + } + + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingAddArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingAddArgument.java new file mode 100644 index 0000000..281791c --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingAddArgument.java @@ -0,0 +1,34 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesssetting; + + +// app +import io.kumare.iqr.mod.biz.store.businesssetting.BusinessSettingEntity; + + +/** + * + * @author afatecha + */ +public class BusinessSettingAddArgument extends BusinessSettingActionArgument { + + // ::: vars + // + + + // ::: constructors + // + public BusinessSettingAddArgument() { + } + + public BusinessSettingAddArgument(BusinessSettingEntity entity) { + super(entity); + } + + // ::: fields + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingDeleteAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingDeleteAction.java new file mode 100644 index 0000000..8857d95 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingDeleteAction.java @@ -0,0 +1,59 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesssetting; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businesssetting.BusinessSettingEntity; + +/** + * + * @author afatecha + */ +public class BusinessSettingDeleteAction extends AppAction> { + + // ::: vars + // + private BusinessSettingEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), BizErrors.businesssetting_notfound); + V.ifNull(getArgument().getEntity().getId(), BizErrors.businesssetting_notfound); + } + + @Override + protected void doAction() { + + var argModel = getArgument().getEntity(); + + deleteEntity(argModel); + } + + @Override + protected void setResultOnly() { + } + + // ::: delete + // + private void deleteEntity(BusinessSettingEntity model) { + + var store = AppModules.biz.getController().getBusinessSettingStore(); + + store.deleteById(getContext(), model.getId()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingEditAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingEditAction.java new file mode 100644 index 0000000..ad36b9c --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingEditAction.java @@ -0,0 +1,97 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesssetting; + +// lib +import io.kumare.lib.v.V; +// app +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businesssetting.BusinessSettingEntity; + +/** + * + * @author afatecha + */ +public class BusinessSettingEditAction extends AppAction> { + + // ::: vars + // + private BusinessSettingEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, BizErrors.businesssetting_notfound); + + // fields + V.ifEmpty(model.getPointExchange(), BizErrors.businesssetting_pointexchange_empty); + V.ifEmpty(model.getLeadCaptureReward(), BizErrors.businesssetting_leadcapturereward_empty); + V.ifEmpty(model.getCustomerCaptureReward(), BizErrors.businesssetting_customercapturereward_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + + var biz = AppModules.biz.getController(); + var businessSettingStore = biz.getBusinessSettingStore(); + + // edit + entity = businessSettingStore.ensure(getContext(), argModel, BizErrors.businesssetting_notfound); + + editEntity(); + + entity = saveEntity(); + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private void editEntity() { + + var model = getArgument().getEntity(); + + // fields + entity.setPointExchange(V.firstNotEmpty(model.getPointExchange(), entity.getPointExchange())); + entity.setLeadCaptureReward(V.firstNotEmpty(model.getLeadCaptureReward(), entity.getLeadCaptureReward())); + entity.setCustomerCaptureReward(V.firstNotEmpty(model.getCustomerCaptureReward(), entity.getCustomerCaptureReward())); + + + } + + // ::: save + // + private BusinessSettingEntity saveEntity() { + + var store = AppModules.biz.getController().getBusinessSettingStore(); + + var saved = store.edit(getContext(), entity); + getContext().attach(saved.getId(), saved); + return saved; + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingEditArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingEditArgument.java new file mode 100644 index 0000000..91f45dd --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingEditArgument.java @@ -0,0 +1,32 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesssetting; + +// app +import io.kumare.iqr.mod.biz.store.businesssetting.BusinessSettingEntity; + +/** + * + * @author afatecha + */ +public class BusinessSettingEditArgument extends BusinessSettingActionArgument { + + // ::: vars + // + + + // ::: constructors + // + public BusinessSettingEditArgument() { + } + + public BusinessSettingEditArgument(BusinessSettingEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingEnableAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingEnableAction.java new file mode 100644 index 0000000..ebb07c8 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingEnableAction.java @@ -0,0 +1,60 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesssetting; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businesssetting.BusinessSettingEntity; + + +/** + * + * @author afatecha + */ +public class BusinessSettingEnableAction extends AppAction { + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), BizErrors.businesssetting_notfound); + V.ifNull(getArgument().getEntity().getId(), BizErrors.businesssetting_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + + enableEntity(model); + } + + @Override + protected void setResultOnly() { + } + + // ::: enable + // + private void enableEntity(BusinessSettingEntity model) { + + var store = AppModules.biz.getController().getBusinessSettingStore(); + + if (getArgument().getEntity().isActive()) { + store.enableById(getContext(), model.getId()); + } else { + store.disableById(getContext(), model.getId()); + } + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingFindAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingFindAction.java new file mode 100644 index 0000000..83570c7 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingFindAction.java @@ -0,0 +1,64 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesssetting; + +// java +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businesssetting.BusinessSettingEntity; + + +/** + * + * @author afatecha + */ +public class BusinessSettingFindAction extends AppAction { + + // ::: vars + // + private BusinessSettingEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), BizErrors.businesssetting_notfound); + V.ifNull(getArgument().getEntity().getId(), BizErrors.businesssetting_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + entity = findEntity(model); + } + + @Override + protected void setResultOnly() { + var result = new HashMap(); + result.put("entity", entity); + setResult(result); + } + + // ::: find + // + private BusinessSettingEntity findEntity(BusinessSettingEntity model) { + + var store = AppModules.biz.getController().getBusinessSettingStore(); + return store.findById(getContext(), model.getId()); + } + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingListAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingListAction.java new file mode 100644 index 0000000..449169a --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingListAction.java @@ -0,0 +1,148 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesssetting; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.LinkedList; +import java.util.Map; +// spring +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// entity +import io.kumare.iqr.mod.biz.store.businesssetting.BusinessSettingEntity; +import io.kumare.iqr.mod.biz.store.businesssetting.BusinessSettingMapBuilder; + + +/** + * + * @author afatecha + */ +public class BusinessSettingListAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private final List entities = new LinkedList<>(); + + // ::: public api + // + public List getEntities() { + return entities; + } + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + } + + @Override + protected void doAction() { + + result.put("pageable", getArgument().isPageable()); + result.put("wrapped", getArgument().isWrapped()); + + if (getArgument().isPageable()) { + + var page = makePage(); + entities.addAll(page.toList()); + + if (getArgument().isWrapped()) { + result.put("page", makeWrappedPage(page)); + } else { + result.put("page", page); + } + + } else { + + var list = makeList(); + entities.addAll(list); + + if (getArgument().isWrapped()) { + result.put("list", makeWrappedList()); + } else { + result.put("list", list); + } + } + + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: page + // + private Page makePage() { + + var page = getArgument().getPageNumber(); + var size = getArgument().getPageSize(); + //var sort = getArgument().getSort(); + + var pageable = PageRequest.of(page, size); + + var store = AppModules.biz.getController().getBusinessSettingStore(); + return store.getRepository().findAll(pageable); + } + + // ::: wrapped page + // + private Map makeWrappedPage(Page found) { + + var page = new HashMap(); + var content = new LinkedList(); + + wrapList(entities, content); + + page.put("size", found.getSize()); + page.put("number", found.getNumber()); + page.put("totalElements", found.getTotalElements()); + page.put("totalPages", found.getTotalPages()); + page.put("content", content); + + return page; + } + + + // ::: list + // + + private List makeList() { + + var store = AppModules.biz.getController().getBusinessSettingStore(); + + return store.listAll(getContext()); + } + + // ::: wrapped list + private List makeWrappedList() { + var list = new LinkedList(); + + wrapList(entities, list); + + return list; + } + + // ::: wrapper + // + private void wrapList(List found, List output) { + + var builder = new BusinessSettingMapBuilder().addListGroup(); + builder.getBusinessBuilder().addMainGroup(); + + output.addAll(builder.build(getContext(), found)); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingListArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingListArgument.java new file mode 100644 index 0000000..3cbb260 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingListArgument.java @@ -0,0 +1,33 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesssetting; + +// app +import io.kumare.iqr.app.action.AppListActionArgument; +// store +import io.kumare.iqr.mod.biz.store.businesssetting.BusinessSettingEntity; + +/** + * + * @author afatecha + */ +public class BusinessSettingListArgument extends AppListActionArgument { + + // ::: vars + // + + // ::: constructors + // + public BusinessSettingListArgument() { + } + + public BusinessSettingListArgument(BusinessSettingEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingPreloadAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingPreloadAction.java new file mode 100644 index 0000000..e9fac28 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingPreloadAction.java @@ -0,0 +1,105 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesssetting; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businesssetting.BusinessSettingEntity; +// relations +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; + +/** + * + * @author afatecha + */ +public class BusinessSettingPreloadAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private Map params = new HashMap<>(); + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifEmpty(getArgument().getAction(), BizErrors.businesssetting_preload_empty); + } + + @Override + protected void doAction() { + if(getArgument().getParams() != null) { + params = getArgument().getParams(); + } + + switch (getArgument().getAction()) { + case "find" -> + prepareFind(); + case "list" -> + prepareList(); + case "add" -> + prepareAdd(); + case "edit" -> + prepareEdit(); + } + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: preload + // + private void prepareAdd() { + result.put("businesss", listBusinesss()); + } + + private void prepareEdit() { + var entity = findEntity(); + result.put("entity", entity); + result.put("business", entity.getBusiness()); + } + + private void prepareList() { + } + + private void prepareFind() { + var entity = findEntity(); + result.put("entity", entity); + result.put("business", entity.getBusiness()); + } + + // ::: queries + // + private BusinessSettingEntity findEntity() { + var store = AppModules.biz.getController().getBusinessSettingStore(); + + var id = (String) params.get("id"); + if(id == null && getArgument().getEntity() != null) { + id = getArgument().getEntity().getId(); + } + return store.findById(getContext(), id); + } + + public List listBusinesss() { + var store = AppModules.biz.getController().getBusinessStore(); + + return store.listAll(getContext()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingPreloadArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingPreloadArgument.java new file mode 100644 index 0000000..a1de782 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesssetting/BusinessSettingPreloadArgument.java @@ -0,0 +1,26 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesssetting; + +/** + * + * @author afatecha + */ +public class BusinessSettingPreloadArgument extends BusinessSettingActionArgument { + + // ::: vars + // + private String action; + + // ::: fields + // + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagActionArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagActionArgument.java new file mode 100644 index 0000000..0337387 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagActionArgument.java @@ -0,0 +1,29 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesstag; + +// base +import io.kumare.iqr.app.action.AppEntityActionArgument; +// entity +import io.kumare.iqr.mod.biz.store.businesstag.BusinessTagEntity; + +/** + * + * @author afatecha + */ +public class BusinessTagActionArgument extends AppEntityActionArgument { + + // ::: constructors + // + public BusinessTagActionArgument() { + } + + public BusinessTagActionArgument(BusinessTagEntity entity) { + super(entity); + } + + // ::: api + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagAddAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagAddAction.java new file mode 100644 index 0000000..0237abb --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagAddAction.java @@ -0,0 +1,114 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesstag; + + +// lib +import io.kumare.lib.base.server.spring.action.Actions; +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businesstag.BusinessTagEntity; + + + +/** + * + * @author afatecha + */ +public class BusinessTagAddAction extends AppAction> { + + // ::: vars + // + private BusinessTagEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, BizErrors.businesstag_notfound); + + // relations + + // fields + V.ifEmpty(model.getEntityKey(), BizErrors.businesstag_entitykey_empty); + V.ifEmpty(model.getName(), BizErrors.businesstag_name_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + + + + + + + // model + var model = makeModel(); + + // add + entity = saveEntity(model); + + // add others + + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private BusinessTagEntity makeModel() { + + var argModel = getArgument().getEntity(); + var model = new BusinessTagEntity(); + + // relations + + + // fields + model.setEntityKey(argModel.getEntityKey()); + model.setName(argModel.getName()); + model.setActive(true); + + + + return model; + } + + // ::: save + // + private BusinessTagEntity saveEntity(BusinessTagEntity model) { + + var store = AppModules.biz.getController().getBusinessTagStore(); + + var saved = store.add(getContext(), model); + getContext().attach(saved.getId(), saved); + return saved; + } + + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagAddArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagAddArgument.java new file mode 100644 index 0000000..4d9d197 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagAddArgument.java @@ -0,0 +1,34 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesstag; + + +// app +import io.kumare.iqr.mod.biz.store.businesstag.BusinessTagEntity; + + +/** + * + * @author afatecha + */ +public class BusinessTagAddArgument extends BusinessTagActionArgument { + + // ::: vars + // + + + // ::: constructors + // + public BusinessTagAddArgument() { + } + + public BusinessTagAddArgument(BusinessTagEntity entity) { + super(entity); + } + + // ::: fields + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagDeleteAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagDeleteAction.java new file mode 100644 index 0000000..6890dbd --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagDeleteAction.java @@ -0,0 +1,59 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesstag; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businesstag.BusinessTagEntity; + +/** + * + * @author afatecha + */ +public class BusinessTagDeleteAction extends AppAction> { + + // ::: vars + // + private BusinessTagEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), BizErrors.businesstag_notfound); + V.ifNull(getArgument().getEntity().getId(), BizErrors.businesstag_notfound); + } + + @Override + protected void doAction() { + + var argModel = getArgument().getEntity(); + + deleteEntity(argModel); + } + + @Override + protected void setResultOnly() { + } + + // ::: delete + // + private void deleteEntity(BusinessTagEntity model) { + + var store = AppModules.biz.getController().getBusinessTagStore(); + + store.deleteById(getContext(), model.getId()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagEditAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagEditAction.java new file mode 100644 index 0000000..8a370bc --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagEditAction.java @@ -0,0 +1,95 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesstag; + +// lib +import io.kumare.lib.v.V; +// app +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businesstag.BusinessTagEntity; + +/** + * + * @author afatecha + */ +public class BusinessTagEditAction extends AppAction> { + + // ::: vars + // + private BusinessTagEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, BizErrors.businesstag_notfound); + + // fields + V.ifEmpty(model.getEntityKey(), BizErrors.businesstag_entitykey_empty); + V.ifEmpty(model.getName(), BizErrors.businesstag_name_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + + var biz = AppModules.biz.getController(); + var businessTagStore = biz.getBusinessTagStore(); + + // edit + entity = businessTagStore.ensure(getContext(), argModel, BizErrors.businesstag_notfound); + + editEntity(); + + entity = saveEntity(); + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private void editEntity() { + + var model = getArgument().getEntity(); + + // fields + entity.setEntityKey(V.firstNotEmpty(model.getEntityKey(), entity.getEntityKey())); + entity.setName(V.firstNotEmpty(model.getName(), entity.getName())); + + + } + + // ::: save + // + private BusinessTagEntity saveEntity() { + + var store = AppModules.biz.getController().getBusinessTagStore(); + + var saved = store.edit(getContext(), entity); + getContext().attach(saved.getId(), saved); + return saved; + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagEditArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagEditArgument.java new file mode 100644 index 0000000..167f7e1 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagEditArgument.java @@ -0,0 +1,32 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesstag; + +// app +import io.kumare.iqr.mod.biz.store.businesstag.BusinessTagEntity; + +/** + * + * @author afatecha + */ +public class BusinessTagEditArgument extends BusinessTagActionArgument { + + // ::: vars + // + + + // ::: constructors + // + public BusinessTagEditArgument() { + } + + public BusinessTagEditArgument(BusinessTagEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagEnableAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagEnableAction.java new file mode 100644 index 0000000..847c9ea --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagEnableAction.java @@ -0,0 +1,60 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesstag; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businesstag.BusinessTagEntity; + + +/** + * + * @author afatecha + */ +public class BusinessTagEnableAction extends AppAction { + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), BizErrors.businesstag_notfound); + V.ifNull(getArgument().getEntity().getId(), BizErrors.businesstag_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + + enableEntity(model); + } + + @Override + protected void setResultOnly() { + } + + // ::: enable + // + private void enableEntity(BusinessTagEntity model) { + + var store = AppModules.biz.getController().getBusinessTagStore(); + + if (getArgument().getEntity().isActive()) { + store.enableById(getContext(), model.getId()); + } else { + store.disableById(getContext(), model.getId()); + } + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagFindAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagFindAction.java new file mode 100644 index 0000000..338153c --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagFindAction.java @@ -0,0 +1,64 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesstag; + +// java +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businesstag.BusinessTagEntity; + + +/** + * + * @author afatecha + */ +public class BusinessTagFindAction extends AppAction { + + // ::: vars + // + private BusinessTagEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), BizErrors.businesstag_notfound); + V.ifNull(getArgument().getEntity().getId(), BizErrors.businesstag_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + entity = findEntity(model); + } + + @Override + protected void setResultOnly() { + var result = new HashMap(); + result.put("entity", entity); + setResult(result); + } + + // ::: find + // + private BusinessTagEntity findEntity(BusinessTagEntity model) { + + var store = AppModules.biz.getController().getBusinessTagStore(); + return store.findById(getContext(), model.getId()); + } + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagListAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagListAction.java new file mode 100644 index 0000000..68f6157 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagListAction.java @@ -0,0 +1,148 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesstag; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.LinkedList; +import java.util.Map; +// spring +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// entity +import io.kumare.iqr.mod.biz.store.businesstag.BusinessTagEntity; +import io.kumare.iqr.mod.biz.store.businesstag.BusinessTagMapBuilder; + + +/** + * + * @author afatecha + */ +public class BusinessTagListAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private final List entities = new LinkedList<>(); + + // ::: public api + // + public List getEntities() { + return entities; + } + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + } + + @Override + protected void doAction() { + + result.put("pageable", getArgument().isPageable()); + result.put("wrapped", getArgument().isWrapped()); + + if (getArgument().isPageable()) { + + var page = makePage(); + entities.addAll(page.toList()); + + if (getArgument().isWrapped()) { + result.put("page", makeWrappedPage(page)); + } else { + result.put("page", page); + } + + } else { + + var list = makeList(); + entities.addAll(list); + + if (getArgument().isWrapped()) { + result.put("list", makeWrappedList()); + } else { + result.put("list", list); + } + } + + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: page + // + private Page makePage() { + + var page = getArgument().getPageNumber(); + var size = getArgument().getPageSize(); + //var sort = getArgument().getSort(); + + var pageable = PageRequest.of(page, size); + + var store = AppModules.biz.getController().getBusinessTagStore(); + return store.getRepository().findAll(pageable); + } + + // ::: wrapped page + // + private Map makeWrappedPage(Page found) { + + var page = new HashMap(); + var content = new LinkedList(); + + wrapList(entities, content); + + page.put("size", found.getSize()); + page.put("number", found.getNumber()); + page.put("totalElements", found.getTotalElements()); + page.put("totalPages", found.getTotalPages()); + page.put("content", content); + + return page; + } + + + // ::: list + // + + private List makeList() { + + var store = AppModules.biz.getController().getBusinessTagStore(); + + return store.listAll(getContext()); + } + + // ::: wrapped list + private List makeWrappedList() { + var list = new LinkedList(); + + wrapList(entities, list); + + return list; + } + + // ::: wrapper + // + private void wrapList(List found, List output) { + + var builder = new BusinessTagMapBuilder().addListGroup(); + + + output.addAll(builder.build(getContext(), found)); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagListArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagListArgument.java new file mode 100644 index 0000000..e8c4453 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagListArgument.java @@ -0,0 +1,33 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesstag; + +// app +import io.kumare.iqr.app.action.AppListActionArgument; +// store +import io.kumare.iqr.mod.biz.store.businesstag.BusinessTagEntity; + +/** + * + * @author afatecha + */ +public class BusinessTagListArgument extends AppListActionArgument { + + // ::: vars + // + + // ::: constructors + // + public BusinessTagListArgument() { + } + + public BusinessTagListArgument(BusinessTagEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagPreloadAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagPreloadAction.java new file mode 100644 index 0000000..3a58daa --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagPreloadAction.java @@ -0,0 +1,101 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesstag; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businesstag.BusinessTagEntity; +// relations + + +/** + * + * @author afatecha + */ +public class BusinessTagPreloadAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private Map params = new HashMap<>(); + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifEmpty(getArgument().getAction(), BizErrors.businesstag_preload_empty); + } + + @Override + protected void doAction() { + if(getArgument().getParams() != null) { + params = getArgument().getParams(); + } + + switch (getArgument().getAction()) { + case "find" -> + prepareFind(); + case "list" -> + prepareList(); + case "add" -> + prepareAdd(); + case "edit" -> + prepareEdit(); + } + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: preload + // + private void prepareAdd() { + + } + + private void prepareEdit() { + var entity = findEntity(); + result.put("entity", entity); + + } + + private void prepareList() { + } + + private void prepareFind() { + var entity = findEntity(); + result.put("entity", entity); + + } + + // ::: queries + // + private BusinessTagEntity findEntity() { + var store = AppModules.biz.getController().getBusinessTagStore(); + + var id = (String) params.get("id"); + if(id == null && getArgument().getEntity() != null) { + id = getArgument().getEntity().getId(); + } + return store.findById(getContext(), id); + } + + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagPreloadArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagPreloadArgument.java new file mode 100644 index 0000000..7792cc2 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businesstag/BusinessTagPreloadArgument.java @@ -0,0 +1,26 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businesstag; + +/** + * + * @author afatecha + */ +public class BusinessTagPreloadArgument extends BusinessTagActionArgument { + + // ::: vars + // + private String action; + + // ::: fields + // + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerActionArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerActionArgument.java new file mode 100644 index 0000000..cb865d3 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerActionArgument.java @@ -0,0 +1,29 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessworker; + +// base +import io.kumare.iqr.app.action.AppEntityActionArgument; +// entity +import io.kumare.iqr.mod.biz.store.businessworker.BusinessWorkerEntity; + +/** + * + * @author afatecha + */ +public class BusinessWorkerActionArgument extends AppEntityActionArgument { + + // ::: constructors + // + public BusinessWorkerActionArgument() { + } + + public BusinessWorkerActionArgument(BusinessWorkerEntity entity) { + super(entity); + } + + // ::: api + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerAddAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerAddAction.java new file mode 100644 index 0000000..f41357b --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerAddAction.java @@ -0,0 +1,146 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessworker; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +import io.kumare.iqr.mod.authentication.action.authuser.AuthUserAddArgument; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businessworker.BusinessWorkerEntity; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; +import io.kumare.iqr.mod.biz.store.BizTaxonomies; +import io.kumare.iqr.mod.biz.store.BizWorkerRoles; + +/** + * + * @author afatecha + */ +public class BusinessWorkerAddAction extends AppAction> { + + // ::: vars + // + private BusinessWorkerEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, BizErrors.businessworker_notfound); + + // relations + V.ifNull(model.getBusiness(), BizErrors.businessworker_business_notfound); + //V.ifNull(model.getAuthUser(), BizErrors.businessworker_authuser_notfound); + V.ifNull(model.getRole(), BizErrors.businessworker_role_notfound); + //V.ifNull(model.getState(), BizErrors.businessworker_state_notfound); + + // fields + //V.ifEmpty(model.getEntityKey(), BizErrors.businessworker_entitykey_empty); + //V.ifEmpty(model.getRoleValue(), BizErrors.businessworker_rolevalue_empty); + //V.ifEmpty(model.getStateValue(), BizErrors.businessworker_statevalue_empty); + //V.ifEmpty(model.getEmail(), BizErrors.businessworker_email_empty); + //V.ifEmpty(model.getPhone(), BizErrors.businessworker_phone_empty); + V.ifEmpty(model.getName(), BizErrors.businessworker_name_empty); + //V.ifEmpty(model.getDescription(), BizErrors.businessworker_description_empty); + + // other arguments + V.ifNull(getArgument().getAuthUser(), BizErrors.businessworker_authuser_notfound); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + var biz = AppModules.biz.getController(); + var businessStore = biz.getBusinessStore(); + + var business = businessStore.ensure(getContext(), + argModel.getBusiness(), + BizErrors.businessworker_business_notfound); + + var roleKey = argModel.getRole().getEntityKey(); + var role = BizTaxonomies.businessWorkerRole.ensureByKey(getContext(), roleKey); + var state = BizTaxonomies.businessWorkerState.ensureDefault(getContext()); + + // model + var model = makeModel(business, role, state); + + // add + entity = saveEntity(model); + + // add others + addAuthUser(getArgument().getAuthUser()); + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private BusinessWorkerEntity makeModel(BusinessEntity business, TaxonEntity role, TaxonEntity state) { + + var argModel = getArgument().getEntity(); + var model = new BusinessWorkerEntity(); + + // relations + model.setBusiness(business); + model.setRole(role); + model.setRoleValue(role.getValue()); + model.setState(state); + model.setStateValue(state.getValue()); + + // fields + model.setEntityKey(generateKey()); + model.setEmail(argModel.getEmail()); + model.setPhone(argModel.getPhone()); + model.setName(argModel.getName()); + model.setDescription(argModel.getDescription()); + model.setActive(true); + + return model; + } + + private String generateKey() { + return "XXX-CHANGE-XXX";// base64 de un json... + //"http://iqr.site/pub/w/ID" + //"http://iqr.site/pub/c/blabalbal" + } + + // ::: save + // + private BusinessWorkerEntity saveEntity(BusinessWorkerEntity model) { + + var store = AppModules.biz.getController().getBusinessWorkerStore(); + + var saved = store.add(getContext(), model); + getContext().attach(saved.getId(), saved); + return saved; + } + + // ::: add others + // + private void addAuthUser(AuthUserAddArgument authUser) { + // XXX DO IT + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerAddArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerAddArgument.java new file mode 100644 index 0000000..6966e05 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerAddArgument.java @@ -0,0 +1,39 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessworker; + +// app +import io.kumare.iqr.mod.authentication.action.authuser.AuthUserAddArgument; +import io.kumare.iqr.mod.biz.store.businessworker.BusinessWorkerEntity; + +/** + * + * @author afatecha + */ +public class BusinessWorkerAddArgument extends BusinessWorkerActionArgument { + + // ::: vars + // + private AuthUserAddArgument authUser; + + // ::: constructors + // + public BusinessWorkerAddArgument() { + } + + public BusinessWorkerAddArgument(BusinessWorkerEntity entity) { + super(entity); + } + + // ::: fields + // + public AuthUserAddArgument getAuthUser() { + return authUser; + } + + public void setAuthUser(AuthUserAddArgument authUser) { + this.authUser = authUser; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerDeleteAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerDeleteAction.java new file mode 100644 index 0000000..6d08f61 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerDeleteAction.java @@ -0,0 +1,59 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessworker; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businessworker.BusinessWorkerEntity; + +/** + * + * @author afatecha + */ +public class BusinessWorkerDeleteAction extends AppAction> { + + // ::: vars + // + private BusinessWorkerEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), BizErrors.businessworker_notfound); + V.ifNull(getArgument().getEntity().getId(), BizErrors.businessworker_notfound); + } + + @Override + protected void doAction() { + + var argModel = getArgument().getEntity(); + + deleteEntity(argModel); + } + + @Override + protected void setResultOnly() { + } + + // ::: delete + // + private void deleteEntity(BusinessWorkerEntity model) { + + var store = AppModules.biz.getController().getBusinessWorkerStore(); + + store.deleteById(getContext(), model.getId()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerEditAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerEditAction.java new file mode 100644 index 0000000..13beda2 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerEditAction.java @@ -0,0 +1,105 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessworker; + +// lib +import io.kumare.lib.v.V; +// app +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businessworker.BusinessWorkerEntity; + +/** + * + * @author afatecha + */ +public class BusinessWorkerEditAction extends AppAction> { + + // ::: vars + // + private BusinessWorkerEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, BizErrors.businessworker_notfound); + + // fields + V.ifEmpty(model.getEntityKey(), BizErrors.businessworker_entitykey_empty); + V.ifEmpty(model.getRoleValue(), BizErrors.businessworker_rolevalue_empty); + V.ifEmpty(model.getStateValue(), BizErrors.businessworker_statevalue_empty); + V.ifEmpty(model.getEmail(), BizErrors.businessworker_email_empty); + V.ifEmpty(model.getPhone(), BizErrors.businessworker_phone_empty); + V.ifEmpty(model.getName(), BizErrors.businessworker_name_empty); + V.ifEmpty(model.getDescription(), BizErrors.businessworker_description_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + + var biz = AppModules.biz.getController(); + var businessWorkerStore = biz.getBusinessWorkerStore(); + + // edit + entity = businessWorkerStore.ensure(getContext(), argModel, BizErrors.businessworker_notfound); + + editEntity(); + + entity = saveEntity(); + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private void editEntity() { + + var model = getArgument().getEntity(); + + // fields + entity.setEntityKey(V.firstNotEmpty(model.getEntityKey(), entity.getEntityKey())); + entity.setRoleValue(V.firstNotEmpty(model.getRoleValue(), entity.getRoleValue())); + entity.setStateValue(V.firstNotEmpty(model.getStateValue(), entity.getStateValue())); + entity.setEmail(V.firstNotEmpty(model.getEmail(), entity.getEmail())); + entity.setPhone(V.firstNotEmpty(model.getPhone(), entity.getPhone())); + entity.setName(V.firstNotEmpty(model.getName(), entity.getName())); + entity.setDescription(V.firstNotEmpty(model.getDescription(), entity.getDescription())); + + + } + + // ::: save + // + private BusinessWorkerEntity saveEntity() { + + var store = AppModules.biz.getController().getBusinessWorkerStore(); + + var saved = store.edit(getContext(), entity); + getContext().attach(saved.getId(), saved); + return saved; + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerEditArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerEditArgument.java new file mode 100644 index 0000000..418ef6a --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerEditArgument.java @@ -0,0 +1,32 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessworker; + +// app +import io.kumare.iqr.mod.biz.store.businessworker.BusinessWorkerEntity; + +/** + * + * @author afatecha + */ +public class BusinessWorkerEditArgument extends BusinessWorkerActionArgument { + + // ::: vars + // + + + // ::: constructors + // + public BusinessWorkerEditArgument() { + } + + public BusinessWorkerEditArgument(BusinessWorkerEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerEnableAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerEnableAction.java new file mode 100644 index 0000000..e9689b5 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerEnableAction.java @@ -0,0 +1,60 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessworker; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businessworker.BusinessWorkerEntity; + + +/** + * + * @author afatecha + */ +public class BusinessWorkerEnableAction extends AppAction { + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), BizErrors.businessworker_notfound); + V.ifNull(getArgument().getEntity().getId(), BizErrors.businessworker_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + + enableEntity(model); + } + + @Override + protected void setResultOnly() { + } + + // ::: enable + // + private void enableEntity(BusinessWorkerEntity model) { + + var store = AppModules.biz.getController().getBusinessWorkerStore(); + + if (getArgument().getEntity().isActive()) { + store.enableById(getContext(), model.getId()); + } else { + store.disableById(getContext(), model.getId()); + } + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerFindAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerFindAction.java new file mode 100644 index 0000000..02d34be --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerFindAction.java @@ -0,0 +1,64 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessworker; + +// java +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businessworker.BusinessWorkerEntity; + + +/** + * + * @author afatecha + */ +public class BusinessWorkerFindAction extends AppAction { + + // ::: vars + // + private BusinessWorkerEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), BizErrors.businessworker_notfound); + V.ifNull(getArgument().getEntity().getId(), BizErrors.businessworker_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + entity = findEntity(model); + } + + @Override + protected void setResultOnly() { + var result = new HashMap(); + result.put("entity", entity); + setResult(result); + } + + // ::: find + // + private BusinessWorkerEntity findEntity(BusinessWorkerEntity model) { + + var store = AppModules.biz.getController().getBusinessWorkerStore(); + return store.findById(getContext(), model.getId()); + } + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerListAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerListAction.java new file mode 100644 index 0000000..bbc592b --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerListAction.java @@ -0,0 +1,150 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessworker; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.LinkedList; +import java.util.Map; +// spring +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// entity +import io.kumare.iqr.mod.biz.store.businessworker.BusinessWorkerEntity; +import io.kumare.iqr.mod.biz.store.businessworker.BusinessWorkerMapBuilder; + + +/** + * + * @author afatecha + */ +public class BusinessWorkerListAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private final List entities = new LinkedList<>(); + + // ::: public api + // + public List getEntities() { + return entities; + } + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + } + + @Override + protected void doAction() { + + result.put("pageable", getArgument().isPageable()); + result.put("wrapped", getArgument().isWrapped()); + + if (getArgument().isPageable()) { + + var page = makePage(); + entities.addAll(page.toList()); + + if (getArgument().isWrapped()) { + result.put("page", makeWrappedPage(page)); + } else { + result.put("page", page); + } + + } else { + + var list = makeList(); + entities.addAll(list); + + if (getArgument().isWrapped()) { + result.put("list", makeWrappedList()); + } else { + result.put("list", list); + } + } + + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: page + // + private Page makePage() { + + var page = getArgument().getPageNumber(); + var size = getArgument().getPageSize(); + //var sort = getArgument().getSort(); + + var pageable = PageRequest.of(page, size); + + var store = AppModules.biz.getController().getBusinessWorkerStore(); + return store.getRepository().findAll(pageable); + } + + // ::: wrapped page + // + private Map makeWrappedPage(Page found) { + + var page = new HashMap(); + var content = new LinkedList(); + + wrapList(entities, content); + + page.put("size", found.getSize()); + page.put("number", found.getNumber()); + page.put("totalElements", found.getTotalElements()); + page.put("totalPages", found.getTotalPages()); + page.put("content", content); + + return page; + } + + + // ::: list + // + + private List makeList() { + + var store = AppModules.biz.getController().getBusinessWorkerStore(); + + return store.listAll(getContext()); + } + + // ::: wrapped list + private List makeWrappedList() { + var list = new LinkedList(); + + wrapList(entities, list); + + return list; + } + + // ::: wrapper + // + private void wrapList(List found, List output) { + + var builder = new BusinessWorkerMapBuilder().addListGroup(); + builder.getBusinessBuilder().addMainGroup(); + builder.getRoleBuilder().addMainGroup(); + builder.getStateBuilder().addMainGroup(); + + output.addAll(builder.build(getContext(), found)); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerListArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerListArgument.java new file mode 100644 index 0000000..04f3b4d --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerListArgument.java @@ -0,0 +1,33 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessworker; + +// app +import io.kumare.iqr.app.action.AppListActionArgument; +// store +import io.kumare.iqr.mod.biz.store.businessworker.BusinessWorkerEntity; + +/** + * + * @author afatecha + */ +public class BusinessWorkerListArgument extends AppListActionArgument { + + // ::: vars + // + + // ::: constructors + // + public BusinessWorkerListArgument() { + } + + public BusinessWorkerListArgument(BusinessWorkerEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerPreloadAction.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerPreloadAction.java new file mode 100644 index 0000000..9b53436 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerPreloadAction.java @@ -0,0 +1,118 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessworker; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.biz.BizErrors; +// entity +import io.kumare.iqr.mod.biz.store.businessworker.BusinessWorkerEntity; +// relations +import io.kumare.iqr.mod.authentication.store.authuser.AuthUserEntity; +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; + +/** + * + * @author afatecha + */ +public class BusinessWorkerPreloadAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private Map params = new HashMap<>(); + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifEmpty(getArgument().getAction(), BizErrors.businessworker_preload_empty); + } + + @Override + protected void doAction() { + if (getArgument().getParams() != null) { + params = getArgument().getParams(); + } + + switch (getArgument().getAction()) { + case "find" -> + prepareFind(); + case "list" -> + prepareList(); + case "add" -> + prepareAdd(); + case "edit" -> + prepareEdit(); + } + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: preload + // + private void prepareAdd() { + result.put("taxons", listTaxons()); + result.put("businesss", listBusinesses()); + } + + private void prepareEdit() { + var entity = findEntity(); + result.put("entity", entity); + result.put("business", entity.getBusiness()); + result.put("role", entity.getRole()); + result.put("state", entity.getState()); + } + + private void prepareList() { + } + + private void prepareFind() { + var entity = findEntity(); + result.put("entity", entity); + result.put("business", entity.getBusiness()); + result.put("role", entity.getRole()); + result.put("state", entity.getState()); + } + + // ::: queries + // + private BusinessWorkerEntity findEntity() { + var store = AppModules.biz.getController().getBusinessWorkerStore(); + + var id = (String) params.get("id"); + if (id == null && getArgument().getEntity() != null) { + id = getArgument().getEntity().getId(); + } + return store.findById(getContext(), id); + } + + public List listBusinesses() { + var store = AppModules.biz.getController().getBusinessStore(); + + return store.listAll(getContext()); + } + + public List listTaxons() { + var store = AppModules.taxonomy.getController().getTaxonStore(); + + return store.listAll(getContext()); + } + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerPreloadArgument.java b/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerPreloadArgument.java new file mode 100644 index 0000000..2b17a4c --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/action/businessworker/BusinessWorkerPreloadArgument.java @@ -0,0 +1,26 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.action.businessworker; + +/** + * + * @author afatecha + */ +public class BusinessWorkerPreloadArgument extends BusinessWorkerActionArgument { + + // ::: vars + // + private String action; + + // ::: fields + // + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/AbstractBusinessImageRest.java b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/AbstractBusinessImageRest.java new file mode 100644 index 0000000..1bed712 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/AbstractBusinessImageRest.java @@ -0,0 +1,214 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.endpoint.rest; + +// java +import java.util.Map; +// openapi +import io.swagger.v3.oas.annotations.*; +import io.swagger.v3.oas.annotations.media.*; +import io.swagger.v3.oas.annotations.responses.*; +// spring +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +// base +import io.kumare.lib.app.api.operation.TransactionType; +import io.kumare.lib.app.api.security.PermissionReference; +// app +import io.kumare.iqr.app.endpoint.rest.AppEndpointRest; +import io.kumare.iqr.app.action.*; +// module +import io.kumare.iqr.mod.biz.BizPermissions; +import io.kumare.iqr.mod.biz.store.businessimage.BusinessImageEntity; +import io.kumare.iqr.mod.biz.action.businessimage.*; + +/** +* +* @author afatecha +*/ +public abstract class AbstractBusinessImageRest extends AppEndpointRest { + + // ::: DEFAULT PERMISSIONS + // + protected PermissionReference getPermission(String action, String ref, Object extra) { + switch (action) { + case null -> { + return null; + } + case "add" -> { + return BizPermissions.business_image_worker.toReference(ref); + } + case "edit" -> { + return BizPermissions.business_image_worker.toReference(ref); + } + case "enable" -> { + return BizPermissions.business_image_manager.toReference(ref); + } + case "disable" -> { + return BizPermissions.business_image_manager.toReference(ref); + } + case "delete" -> { + return BizPermissions.business_image_manager.toReference(ref); + } + case "find" -> { + return BizPermissions.business_image_viewer.toReference(ref); + } + case "list" -> { + return BizPermissions.business_image_viewer.toReference(ref); + } + default -> { + return null; + } + } + } + + + // ::: ADD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "business image add operation", description = "") + // + @PostMapping + public ResponseEntity add(@RequestBody BusinessImageAddArgument arg) { + + var permission = getPermission("add", null, arg); + return handle(new BusinessImageAddAction(), arg, permission, TransactionType.service); + } + + // ::: EDIT + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "business image edit operation", description = "") + // + @PutMapping("/{id}") + public ResponseEntity edit(@PathVariable("id") String id, + @RequestBody BusinessImageEditArgument arg) { + + arg.getEntity().id(id); + + var permission = getPermission("edit", id, arg); + return handle(new BusinessImageEditAction(), arg, permission, TransactionType.service); + } + + // ::: FIND + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "business image find operation", description = "") + // + @GetMapping("/{id}") + public ResponseEntity find(@PathVariable("id") String id, + @ModelAttribute BusinessImageActionArgument arg) { + + + arg = arg == null ? new BusinessImageActionArgument() : arg; + + arg.entity(new BusinessImageEntity(id)); + + var permission = getPermission("find", id, arg); + return handle(new BusinessImageFindAction(), arg, permission); + } + + // ::: ENABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "business image enable operation", description = "") + // + @PutMapping("/{id}/enable") + public ResponseEntity enable(@PathVariable("id") String id) { + + var arg = new BusinessImageActionArgument(); + arg.setEntity(new BusinessImageEntity(id)); + arg.getEntity().setActive(true); + + var permission = getPermission("disable", id, arg); + return handle(new BusinessImageEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: DISABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "business image disable operation", description = "") + // + @PutMapping("/{id}/disable") + public ResponseEntity disable(@PathVariable("id") String id) { + + var arg = new BusinessImageActionArgument(); + arg.setEntity(new BusinessImageEntity(id)); + arg.getEntity().setActive(false); + + var permission = getPermission("disable", id, arg); + return handle(new BusinessImageEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: LIST + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "business image list operation", description = "") + // + @GetMapping + public ResponseEntity list(@ModelAttribute BusinessImageListArgument arg) { + + arg = arg == null ? new BusinessImageListArgument() : arg; + + var permission = getPermission("list", null, arg); + return handle(new BusinessImageListAction(), arg, permission); + } + + // ::: DELETE + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "business image delete operation", description = "") + // + @DeleteMapping("/{id}") + public ResponseEntity delete(@PathVariable("id") String id) { + + var arg = new BusinessImageActionArgument(); + + arg.setEntity(new BusinessImageEntity(id)); + + var permission = getPermission("delete", id, arg); + return handle(new BusinessImageDeleteAction(), arg, permission, TransactionType.service); + } + + // ::: PRELOAD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "business image preload operation", description = "") + // + @PostMapping("/preload") + public ResponseEntity preload(@RequestBody BusinessImagePreloadArgument arg) { + + var permission = getPermission(arg.getAction(), null, arg); + return handle(new BusinessImagePreloadAction(), arg, permission); + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/AbstractBusinessProfileRest.java b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/AbstractBusinessProfileRest.java new file mode 100644 index 0000000..abcc77f --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/AbstractBusinessProfileRest.java @@ -0,0 +1,215 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.endpoint.rest; + +// java +import java.util.Map; +// openapi +import io.swagger.v3.oas.annotations.*; +import io.swagger.v3.oas.annotations.media.*; +import io.swagger.v3.oas.annotations.responses.*; +// spring +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +// base +import io.kumare.lib.app.api.operation.TransactionType; +import io.kumare.lib.app.api.security.PermissionReference; +// app +import io.kumare.iqr.app.endpoint.rest.AppEndpointRest; +import io.kumare.iqr.app.action.*; +// module +import io.kumare.iqr.mod.biz.BizPermissions; +import io.kumare.iqr.mod.biz.store.businessprofile.BusinessProfileEntity; +import io.kumare.iqr.mod.biz.action.businessprofile.*; + +/** +* +* @author afatecha +*/ +public abstract class AbstractBusinessProfileRest extends AppEndpointRest { + + // ::: DEFAULT PERMISSIONS + // + protected PermissionReference getPermission(String action, String ref, Object extra) { + switch (action) { + case null -> { + return null; + } + case "add" -> { + return BizPermissions.business_profile_worker.toReference(ref); + } + case "edit" -> { + return BizPermissions.business_profile_worker.toReference(ref); + } + case "enable" -> { + return BizPermissions.business_profile_manager.toReference(ref); + } + case "disable" -> { + return BizPermissions.business_profile_manager.toReference(ref); + } + case "delete" -> { + return BizPermissions.business_profile_manager.toReference(ref); + } + case "find" -> { + return BizPermissions.business_profile_viewer.toReference(ref); + } + case "list" -> { + return BizPermissions.business_profile_viewer.toReference(ref); + } + default -> { + return null; + } + } + } + + + // ::: ADD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "business profile add operation", description = "") + // + @PostMapping + public ResponseEntity add(@RequestBody BusinessProfileAddArgument arg) { + + var permission = getPermission("add", null, arg); + return handle(new BusinessProfileAddAction(), arg, permission, TransactionType.service); + } + + // ::: EDIT + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "business profile edit operation", description = "") + // + @PutMapping("/{id}") + public ResponseEntity edit(@PathVariable("id") String id, + @RequestBody BusinessProfileEditArgument arg) { + + arg.getEntity().id(id); + + var permission = getPermission("edit", id, arg); + return handle(new BusinessProfileEditAction(), arg, permission, TransactionType.service); + } + + // ::: FIND + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "business profile find operation", description = "") + // + @GetMapping("/{id}") + public ResponseEntity find(@PathVariable("id") String id, + @ModelAttribute BusinessProfileActionArgument arg) { + + + arg = arg == null ? new BusinessProfileActionArgument() : arg; + + arg.entity(new BusinessProfileEntity(id)); + + var permission = getPermission("find", id, arg); + return handle(new BusinessProfileFindAction(), arg, permission); + } + + // ::: ENABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "business profile enable operation", description = "") + // + @PutMapping("/{id}/enable") + public ResponseEntity enable(@PathVariable("id") String id) { + + var arg = new BusinessProfileActionArgument(); + arg.setEntity(new BusinessProfileEntity(id)); + arg.getEntity().setActive(true); + + var permission = getPermission("disable", id, arg); + return handle(new BusinessProfileEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: DISABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "business profile disable operation", description = "") + // + @PutMapping("/{id}/disable") + public ResponseEntity disable(@PathVariable("id") String id) { + + var arg = new BusinessProfileActionArgument(); + arg.setEntity(new BusinessProfileEntity(id)); + arg.getEntity().setActive(false); + + var permission = getPermission("disable", id, arg); + return handle(new BusinessProfileEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: LIST + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "business profile list operation", description = "") + // + @GetMapping + public ResponseEntity list(@ModelAttribute BusinessProfileListArgument arg) { + + arg = arg == null ? new BusinessProfileListArgument() : arg; + + var permission = getPermission("list", null, arg); + return handle(new BusinessProfileListAction(), arg, permission); + } + + // ::: DELETE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "business profile delete operation", description = "") + // + @DeleteMapping("/{id}") + public ResponseEntity delete(@PathVariable("id") String id) { + + var arg = new BusinessProfileActionArgument(); + + arg.setEntity(new BusinessProfileEntity(id)); + + var permission = getPermission("delete", id, arg); + return handle(new BusinessProfileDeleteAction(), arg, permission, TransactionType.service); + }*/ + + // ::: PRELOAD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "business profile preload operation", description = "") + // + @PostMapping("/preload") + public ResponseEntity preload(@RequestBody BusinessProfilePreloadArgument arg) { + + var permission = getPermission(arg.getAction(), null, arg); + return handle(new BusinessProfilePreloadAction(), arg, permission); + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/AbstractBusinessPromoItemRest.java b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/AbstractBusinessPromoItemRest.java new file mode 100644 index 0000000..c65336a --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/AbstractBusinessPromoItemRest.java @@ -0,0 +1,214 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.endpoint.rest; + +// java +import java.util.Map; +// openapi +import io.swagger.v3.oas.annotations.*; +import io.swagger.v3.oas.annotations.media.*; +import io.swagger.v3.oas.annotations.responses.*; +// spring +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +// base +import io.kumare.lib.app.api.operation.TransactionType; +import io.kumare.lib.app.api.security.PermissionReference; +// app +import io.kumare.iqr.app.endpoint.rest.AppEndpointRest; +import io.kumare.iqr.app.action.*; +// module +import io.kumare.iqr.mod.biz.BizPermissions; +import io.kumare.iqr.mod.biz.store.businesspromoitem.BusinessPromoItemEntity; +import io.kumare.iqr.mod.biz.action.businesspromoitem.*; + +/** +* +* @author afatecha +*/ +public abstract class AbstractBusinessPromoItemRest extends AppEndpointRest { + + // ::: DEFAULT PERMISSIONS + // + protected PermissionReference getPermission(String action, String ref, Object extra) { + switch (action) { + case null -> { + return null; + } + case "add" -> { + return BizPermissions.business_promo_item_worker.toReference(ref); + } + case "edit" -> { + return BizPermissions.business_promo_item_worker.toReference(ref); + } + case "enable" -> { + return BizPermissions.business_promo_item_manager.toReference(ref); + } + case "disable" -> { + return BizPermissions.business_promo_item_manager.toReference(ref); + } + case "delete" -> { + return BizPermissions.business_promo_item_manager.toReference(ref); + } + case "find" -> { + return BizPermissions.business_promo_item_viewer.toReference(ref); + } + case "list" -> { + return BizPermissions.business_promo_item_viewer.toReference(ref); + } + default -> { + return null; + } + } + } + + + // ::: ADD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "business promo item add operation", description = "") + // + @PostMapping + public ResponseEntity add(@RequestBody BusinessPromoItemAddArgument arg) { + + var permission = getPermission("add", null, arg); + return handle(new BusinessPromoItemAddAction(), arg, permission, TransactionType.service); + } + + // ::: EDIT + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "business promo item edit operation", description = "") + // + @PutMapping("/{id}") + public ResponseEntity edit(@PathVariable("id") String id, + @RequestBody BusinessPromoItemEditArgument arg) { + + arg.getEntity().id(id); + + var permission = getPermission("edit", id, arg); + return handle(new BusinessPromoItemEditAction(), arg, permission, TransactionType.service); + } + + // ::: FIND + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "business promo item find operation", description = "") + // + @GetMapping("/{id}") + public ResponseEntity find(@PathVariable("id") String id, + @ModelAttribute BusinessPromoItemActionArgument arg) { + + + arg = arg == null ? new BusinessPromoItemActionArgument() : arg; + + arg.entity(new BusinessPromoItemEntity(id)); + + var permission = getPermission("find", id, arg); + return handle(new BusinessPromoItemFindAction(), arg, permission); + } + + // ::: ENABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "business promo item enable operation", description = "") + // + @PutMapping("/{id}/enable") + public ResponseEntity enable(@PathVariable("id") String id) { + + var arg = new BusinessPromoItemActionArgument(); + arg.setEntity(new BusinessPromoItemEntity(id)); + arg.getEntity().setActive(true); + + var permission = getPermission("disable", id, arg); + return handle(new BusinessPromoItemEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: DISABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "business promo item disable operation", description = "") + // + @PutMapping("/{id}/disable") + public ResponseEntity disable(@PathVariable("id") String id) { + + var arg = new BusinessPromoItemActionArgument(); + arg.setEntity(new BusinessPromoItemEntity(id)); + arg.getEntity().setActive(false); + + var permission = getPermission("disable", id, arg); + return handle(new BusinessPromoItemEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: LIST + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "business promo item list operation", description = "") + // + @GetMapping + public ResponseEntity list(@ModelAttribute BusinessPromoItemListArgument arg) { + + arg = arg == null ? new BusinessPromoItemListArgument() : arg; + + var permission = getPermission("list", null, arg); + return handle(new BusinessPromoItemListAction(), arg, permission); + } + + // ::: DELETE + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "business promo item delete operation", description = "") + // + @DeleteMapping("/{id}") + public ResponseEntity delete(@PathVariable("id") String id) { + + var arg = new BusinessPromoItemActionArgument(); + + arg.setEntity(new BusinessPromoItemEntity(id)); + + var permission = getPermission("delete", id, arg); + return handle(new BusinessPromoItemDeleteAction(), arg, permission, TransactionType.service); + } + + // ::: PRELOAD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "business promo item preload operation", description = "") + // + @PostMapping("/preload") + public ResponseEntity preload(@RequestBody BusinessPromoItemPreloadArgument arg) { + + var permission = getPermission(arg.getAction(), null, arg); + return handle(new BusinessPromoItemPreloadAction(), arg, permission); + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/AbstractBusinessPromoRest.java b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/AbstractBusinessPromoRest.java new file mode 100644 index 0000000..6465fc2 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/AbstractBusinessPromoRest.java @@ -0,0 +1,214 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.endpoint.rest; + +// java +import java.util.Map; +// openapi +import io.swagger.v3.oas.annotations.*; +import io.swagger.v3.oas.annotations.media.*; +import io.swagger.v3.oas.annotations.responses.*; +// spring +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +// base +import io.kumare.lib.app.api.operation.TransactionType; +import io.kumare.lib.app.api.security.PermissionReference; +// app +import io.kumare.iqr.app.endpoint.rest.AppEndpointRest; +import io.kumare.iqr.app.action.*; +// module +import io.kumare.iqr.mod.biz.BizPermissions; +import io.kumare.iqr.mod.biz.store.businesspromo.BusinessPromoEntity; +import io.kumare.iqr.mod.biz.action.businesspromo.*; + +/** +* +* @author afatecha +*/ +public abstract class AbstractBusinessPromoRest extends AppEndpointRest { + + // ::: DEFAULT PERMISSIONS + // + protected PermissionReference getPermission(String action, String ref, Object extra) { + switch (action) { + case null -> { + return null; + } + case "add" -> { + return BizPermissions.business_promo_worker.toReference(ref); + } + case "edit" -> { + return BizPermissions.business_promo_worker.toReference(ref); + } + case "enable" -> { + return BizPermissions.business_promo_manager.toReference(ref); + } + case "disable" -> { + return BizPermissions.business_promo_manager.toReference(ref); + } + case "delete" -> { + return BizPermissions.business_promo_manager.toReference(ref); + } + case "find" -> { + return BizPermissions.business_promo_viewer.toReference(ref); + } + case "list" -> { + return BizPermissions.business_promo_viewer.toReference(ref); + } + default -> { + return null; + } + } + } + + + // ::: ADD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "business promo add operation", description = "") + // + @PostMapping + public ResponseEntity add(@RequestBody BusinessPromoAddArgument arg) { + + var permission = getPermission("add", null, arg); + return handle(new BusinessPromoAddAction(), arg, permission, TransactionType.service); + } + + // ::: EDIT + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "business promo edit operation", description = "") + // + @PutMapping("/{id}") + public ResponseEntity edit(@PathVariable("id") String id, + @RequestBody BusinessPromoEditArgument arg) { + + arg.getEntity().id(id); + + var permission = getPermission("edit", id, arg); + return handle(new BusinessPromoEditAction(), arg, permission, TransactionType.service); + } + + // ::: FIND + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "business promo find operation", description = "") + // + @GetMapping("/{id}") + public ResponseEntity find(@PathVariable("id") String id, + @ModelAttribute BusinessPromoActionArgument arg) { + + + arg = arg == null ? new BusinessPromoActionArgument() : arg; + + arg.entity(new BusinessPromoEntity(id)); + + var permission = getPermission("find", id, arg); + return handle(new BusinessPromoFindAction(), arg, permission); + } + + // ::: ENABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "business promo enable operation", description = "") + // + @PutMapping("/{id}/enable") + public ResponseEntity enable(@PathVariable("id") String id) { + + var arg = new BusinessPromoActionArgument(); + arg.setEntity(new BusinessPromoEntity(id)); + arg.getEntity().setActive(true); + + var permission = getPermission("disable", id, arg); + return handle(new BusinessPromoEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: DISABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "business promo disable operation", description = "") + // + @PutMapping("/{id}/disable") + public ResponseEntity disable(@PathVariable("id") String id) { + + var arg = new BusinessPromoActionArgument(); + arg.setEntity(new BusinessPromoEntity(id)); + arg.getEntity().setActive(false); + + var permission = getPermission("disable", id, arg); + return handle(new BusinessPromoEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: LIST + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "business promo list operation", description = "") + // + @GetMapping + public ResponseEntity list(@ModelAttribute BusinessPromoListArgument arg) { + + arg = arg == null ? new BusinessPromoListArgument() : arg; + + var permission = getPermission("list", null, arg); + return handle(new BusinessPromoListAction(), arg, permission); + } + + // ::: DELETE + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "business promo delete operation", description = "") + // + @DeleteMapping("/{id}") + public ResponseEntity delete(@PathVariable("id") String id) { + + var arg = new BusinessPromoActionArgument(); + + arg.setEntity(new BusinessPromoEntity(id)); + + var permission = getPermission("delete", id, arg); + return handle(new BusinessPromoDeleteAction(), arg, permission, TransactionType.service); + } + + // ::: PRELOAD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "business promo preload operation", description = "") + // + @PostMapping("/preload") + public ResponseEntity preload(@RequestBody BusinessPromoPreloadArgument arg) { + + var permission = getPermission(arg.getAction(), null, arg); + return handle(new BusinessPromoPreloadAction(), arg, permission); + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/AbstractBusinessRest.java b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/AbstractBusinessRest.java new file mode 100644 index 0000000..f892730 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/AbstractBusinessRest.java @@ -0,0 +1,215 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.endpoint.rest; + +// java +import java.util.Map; +// openapi +import io.swagger.v3.oas.annotations.*; +import io.swagger.v3.oas.annotations.media.*; +import io.swagger.v3.oas.annotations.responses.*; +// spring +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +// base +import io.kumare.lib.app.api.operation.TransactionType; +import io.kumare.lib.app.api.security.PermissionReference; +// app +import io.kumare.iqr.app.endpoint.rest.AppEndpointRest; +import io.kumare.iqr.app.action.*; +// module +import io.kumare.iqr.mod.biz.BizPermissions; +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; +import io.kumare.iqr.mod.biz.action.business.*; + +/** +* +* @author afatecha +*/ +public abstract class AbstractBusinessRest extends AppEndpointRest { + + // ::: DEFAULT PERMISSIONS + // + protected PermissionReference getPermission(String action, String ref, Object extra) { + switch (action) { + case null -> { + return null; + } + case "add" -> { + return BizPermissions.business_worker.toReference(ref); + } + case "edit" -> { + return BizPermissions.business_worker.toReference(ref); + } + case "enable" -> { + return BizPermissions.business_manager.toReference(ref); + } + case "disable" -> { + return BizPermissions.business_manager.toReference(ref); + } + case "delete" -> { + return BizPermissions.business_manager.toReference(ref); + } + case "find" -> { + return BizPermissions.business_viewer.toReference(ref); + } + case "list" -> { + return BizPermissions.business_viewer.toReference(ref); + } + default -> { + return null; + } + } + } + + + // ::: ADD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "business add operation", description = "") + // + @PostMapping + public ResponseEntity add(@RequestBody BusinessAddArgument arg) { + + var permission = getPermission("add", null, arg); + return handle(new BusinessAddAction(), arg, permission, TransactionType.service); + } + + // ::: EDIT + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "business edit operation", description = "") + // + @PutMapping("/{id}") + public ResponseEntity edit(@PathVariable("id") String id, + @RequestBody BusinessEditArgument arg) { + + arg.getEntity().id(id); + + var permission = getPermission("edit", id, arg); + return handle(new BusinessEditAction(), arg, permission, TransactionType.service); + } + + // ::: FIND + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "business find operation", description = "") + // + @GetMapping("/{id}") + public ResponseEntity find(@PathVariable("id") String id, + @ModelAttribute BusinessActionArgument arg) { + + + arg = arg == null ? new BusinessActionArgument() : arg; + + arg.entity(new BusinessEntity(id)); + + var permission = getPermission("find", id, arg); + return handle(new BusinessFindAction(), arg, permission); + } + + // ::: ENABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "business enable operation", description = "") + // + @PutMapping("/{id}/enable") + public ResponseEntity enable(@PathVariable("id") String id) { + + var arg = new BusinessActionArgument(); + arg.setEntity(new BusinessEntity(id)); + arg.getEntity().setActive(true); + + var permission = getPermission("disable", id, arg); + return handle(new BusinessEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: DISABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "business disable operation", description = "") + // + @PutMapping("/{id}/disable") + public ResponseEntity disable(@PathVariable("id") String id) { + + var arg = new BusinessActionArgument(); + arg.setEntity(new BusinessEntity(id)); + arg.getEntity().setActive(false); + + var permission = getPermission("disable", id, arg); + return handle(new BusinessEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: LIST + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "business list operation", description = "") + // + @GetMapping + public ResponseEntity list(@ModelAttribute BusinessListArgument arg) { + + arg = arg == null ? new BusinessListArgument() : arg; + + var permission = getPermission("list", null, arg); + return handle(new BusinessListAction(), arg, permission); + } + + // ::: DELETE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "business delete operation", description = "") + // + @DeleteMapping("/{id}") + public ResponseEntity delete(@PathVariable("id") String id) { + + var arg = new BusinessActionArgument(); + + arg.setEntity(new BusinessEntity(id)); + + var permission = getPermission("delete", id, arg); + return handle(new BusinessDeleteAction(), arg, permission, TransactionType.service); + }*/ + + // ::: PRELOAD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "business preload operation", description = "") + // + @PostMapping("/preload") + public ResponseEntity preload(@RequestBody BusinessPreloadArgument arg) { + + var permission = getPermission(arg.getAction(), null, arg); + return handle(new BusinessPreloadAction(), arg, permission); + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/AbstractBusinessSettingRest.java b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/AbstractBusinessSettingRest.java new file mode 100644 index 0000000..2c28df3 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/AbstractBusinessSettingRest.java @@ -0,0 +1,214 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.endpoint.rest; + +// java +import java.util.Map; +// openapi +import io.swagger.v3.oas.annotations.*; +import io.swagger.v3.oas.annotations.media.*; +import io.swagger.v3.oas.annotations.responses.*; +// spring +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +// base +import io.kumare.lib.app.api.operation.TransactionType; +import io.kumare.lib.app.api.security.PermissionReference; +// app +import io.kumare.iqr.app.endpoint.rest.AppEndpointRest; +import io.kumare.iqr.app.action.*; +// module +import io.kumare.iqr.mod.biz.BizPermissions; +import io.kumare.iqr.mod.biz.store.businesssetting.BusinessSettingEntity; +import io.kumare.iqr.mod.biz.action.businesssetting.*; + +/** +* +* @author afatecha +*/ +public abstract class AbstractBusinessSettingRest extends AppEndpointRest { + + // ::: DEFAULT PERMISSIONS + // + protected PermissionReference getPermission(String action, String ref, Object extra) { + switch (action) { + case null -> { + return null; + } + case "add" -> { + return BizPermissions.business_setting_worker.toReference(ref); + } + case "edit" -> { + return BizPermissions.business_setting_worker.toReference(ref); + } + case "enable" -> { + return BizPermissions.business_setting_manager.toReference(ref); + } + case "disable" -> { + return BizPermissions.business_setting_manager.toReference(ref); + } + case "delete" -> { + return BizPermissions.business_setting_manager.toReference(ref); + } + case "find" -> { + return BizPermissions.business_setting_viewer.toReference(ref); + } + case "list" -> { + return BizPermissions.business_setting_viewer.toReference(ref); + } + default -> { + return null; + } + } + } + + + // ::: ADD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "business setting add operation", description = "") + // + @PostMapping + public ResponseEntity add(@RequestBody BusinessSettingAddArgument arg) { + + var permission = getPermission("add", null, arg); + return handle(new BusinessSettingAddAction(), arg, permission, TransactionType.service); + } + + // ::: EDIT + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "business setting edit operation", description = "") + // + @PutMapping("/{id}") + public ResponseEntity edit(@PathVariable("id") String id, + @RequestBody BusinessSettingEditArgument arg) { + + arg.getEntity().id(id); + + var permission = getPermission("edit", id, arg); + return handle(new BusinessSettingEditAction(), arg, permission, TransactionType.service); + } + + // ::: FIND + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "business setting find operation", description = "") + // + @GetMapping("/{id}") + public ResponseEntity find(@PathVariable("id") String id, + @ModelAttribute BusinessSettingActionArgument arg) { + + + arg = arg == null ? new BusinessSettingActionArgument() : arg; + + arg.entity(new BusinessSettingEntity(id)); + + var permission = getPermission("find", id, arg); + return handle(new BusinessSettingFindAction(), arg, permission); + } + + // ::: ENABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "business setting enable operation", description = "") + // + @PutMapping("/{id}/enable") + public ResponseEntity enable(@PathVariable("id") String id) { + + var arg = new BusinessSettingActionArgument(); + arg.setEntity(new BusinessSettingEntity(id)); + arg.getEntity().setActive(true); + + var permission = getPermission("disable", id, arg); + return handle(new BusinessSettingEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: DISABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "business setting disable operation", description = "") + // + @PutMapping("/{id}/disable") + public ResponseEntity disable(@PathVariable("id") String id) { + + var arg = new BusinessSettingActionArgument(); + arg.setEntity(new BusinessSettingEntity(id)); + arg.getEntity().setActive(false); + + var permission = getPermission("disable", id, arg); + return handle(new BusinessSettingEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: LIST + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "business setting list operation", description = "") + // + @GetMapping + public ResponseEntity list(@ModelAttribute BusinessSettingListArgument arg) { + + arg = arg == null ? new BusinessSettingListArgument() : arg; + + var permission = getPermission("list", null, arg); + return handle(new BusinessSettingListAction(), arg, permission); + } + + // ::: DELETE + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "business setting delete operation", description = "") + // + @DeleteMapping("/{id}") + public ResponseEntity delete(@PathVariable("id") String id) { + + var arg = new BusinessSettingActionArgument(); + + arg.setEntity(new BusinessSettingEntity(id)); + + var permission = getPermission("delete", id, arg); + return handle(new BusinessSettingDeleteAction(), arg, permission, TransactionType.service); + } + + // ::: PRELOAD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "business setting preload operation", description = "") + // + @PostMapping("/preload") + public ResponseEntity preload(@RequestBody BusinessSettingPreloadArgument arg) { + + var permission = getPermission(arg.getAction(), null, arg); + return handle(new BusinessSettingPreloadAction(), arg, permission); + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/AbstractBusinessTagRest.java b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/AbstractBusinessTagRest.java new file mode 100644 index 0000000..3112541 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/AbstractBusinessTagRest.java @@ -0,0 +1,214 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.endpoint.rest; + +// java +import java.util.Map; +// openapi +import io.swagger.v3.oas.annotations.*; +import io.swagger.v3.oas.annotations.media.*; +import io.swagger.v3.oas.annotations.responses.*; +// spring +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +// base +import io.kumare.lib.app.api.operation.TransactionType; +import io.kumare.lib.app.api.security.PermissionReference; +// app +import io.kumare.iqr.app.endpoint.rest.AppEndpointRest; +import io.kumare.iqr.app.action.*; +// module +import io.kumare.iqr.mod.biz.BizPermissions; +import io.kumare.iqr.mod.biz.store.businesstag.BusinessTagEntity; +import io.kumare.iqr.mod.biz.action.businesstag.*; + +/** +* +* @author afatecha +*/ +public abstract class AbstractBusinessTagRest extends AppEndpointRest { + + // ::: DEFAULT PERMISSIONS + // + protected PermissionReference getPermission(String action, String ref, Object extra) { + switch (action) { + case null -> { + return null; + } + case "add" -> { + return BizPermissions.business_tag_worker.toReference(ref); + } + case "edit" -> { + return BizPermissions.business_tag_worker.toReference(ref); + } + case "enable" -> { + return BizPermissions.business_tag_manager.toReference(ref); + } + case "disable" -> { + return BizPermissions.business_tag_manager.toReference(ref); + } + case "delete" -> { + return BizPermissions.business_tag_manager.toReference(ref); + } + case "find" -> { + return BizPermissions.business_tag_viewer.toReference(ref); + } + case "list" -> { + return BizPermissions.business_tag_viewer.toReference(ref); + } + default -> { + return null; + } + } + } + + + // ::: ADD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "business tag add operation", description = "") + // + @PostMapping + public ResponseEntity add(@RequestBody BusinessTagAddArgument arg) { + + var permission = getPermission("add", null, arg); + return handle(new BusinessTagAddAction(), arg, permission, TransactionType.service); + } + + // ::: EDIT + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "business tag edit operation", description = "") + // + @PutMapping("/{id}") + public ResponseEntity edit(@PathVariable("id") String id, + @RequestBody BusinessTagEditArgument arg) { + + arg.getEntity().id(id); + + var permission = getPermission("edit", id, arg); + return handle(new BusinessTagEditAction(), arg, permission, TransactionType.service); + } + + // ::: FIND + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "business tag find operation", description = "") + // + @GetMapping("/{id}") + public ResponseEntity find(@PathVariable("id") String id, + @ModelAttribute BusinessTagActionArgument arg) { + + + arg = arg == null ? new BusinessTagActionArgument() : arg; + + arg.entity(new BusinessTagEntity(id)); + + var permission = getPermission("find", id, arg); + return handle(new BusinessTagFindAction(), arg, permission); + } + + // ::: ENABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "business tag enable operation", description = "") + // + @PutMapping("/{id}/enable") + public ResponseEntity enable(@PathVariable("id") String id) { + + var arg = new BusinessTagActionArgument(); + arg.setEntity(new BusinessTagEntity(id)); + arg.getEntity().setActive(true); + + var permission = getPermission("disable", id, arg); + return handle(new BusinessTagEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: DISABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "business tag disable operation", description = "") + // + @PutMapping("/{id}/disable") + public ResponseEntity disable(@PathVariable("id") String id) { + + var arg = new BusinessTagActionArgument(); + arg.setEntity(new BusinessTagEntity(id)); + arg.getEntity().setActive(false); + + var permission = getPermission("disable", id, arg); + return handle(new BusinessTagEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: LIST + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "business tag list operation", description = "") + // + @GetMapping + public ResponseEntity list(@ModelAttribute BusinessTagListArgument arg) { + + arg = arg == null ? new BusinessTagListArgument() : arg; + + var permission = getPermission("list", null, arg); + return handle(new BusinessTagListAction(), arg, permission); + } + + // ::: DELETE + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "business tag delete operation", description = "") + // + @DeleteMapping("/{id}") + public ResponseEntity delete(@PathVariable("id") String id) { + + var arg = new BusinessTagActionArgument(); + + arg.setEntity(new BusinessTagEntity(id)); + + var permission = getPermission("delete", id, arg); + return handle(new BusinessTagDeleteAction(), arg, permission, TransactionType.service); + } + + // ::: PRELOAD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "business tag preload operation", description = "") + // + @PostMapping("/preload") + public ResponseEntity preload(@RequestBody BusinessTagPreloadArgument arg) { + + var permission = getPermission(arg.getAction(), null, arg); + return handle(new BusinessTagPreloadAction(), arg, permission); + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/AbstractBusinessWorkerRest.java b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/AbstractBusinessWorkerRest.java new file mode 100644 index 0000000..1947af1 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/AbstractBusinessWorkerRest.java @@ -0,0 +1,214 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.endpoint.rest; + +// java +import java.util.Map; +// openapi +import io.swagger.v3.oas.annotations.*; +import io.swagger.v3.oas.annotations.media.*; +import io.swagger.v3.oas.annotations.responses.*; +// spring +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +// base +import io.kumare.lib.app.api.operation.TransactionType; +import io.kumare.lib.app.api.security.PermissionReference; +// app +import io.kumare.iqr.app.endpoint.rest.AppEndpointRest; +import io.kumare.iqr.app.action.*; +// module +import io.kumare.iqr.mod.biz.BizPermissions; +import io.kumare.iqr.mod.biz.store.businessworker.BusinessWorkerEntity; +import io.kumare.iqr.mod.biz.action.businessworker.*; + +/** +* +* @author afatecha +*/ +public abstract class AbstractBusinessWorkerRest extends AppEndpointRest { + + // ::: DEFAULT PERMISSIONS + // + protected PermissionReference getPermission(String action, String ref, Object extra) { + switch (action) { + case null -> { + return null; + } + case "add" -> { + return BizPermissions.business_worker_worker.toReference(ref); + } + case "edit" -> { + return BizPermissions.business_worker_worker.toReference(ref); + } + case "enable" -> { + return BizPermissions.business_worker_manager.toReference(ref); + } + case "disable" -> { + return BizPermissions.business_worker_manager.toReference(ref); + } + case "delete" -> { + return BizPermissions.business_worker_manager.toReference(ref); + } + case "find" -> { + return BizPermissions.business_worker_viewer.toReference(ref); + } + case "list" -> { + return BizPermissions.business_worker_viewer.toReference(ref); + } + default -> { + return null; + } + } + } + + + // ::: ADD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "business worker add operation", description = "") + // + @PostMapping + public ResponseEntity add(@RequestBody BusinessWorkerAddArgument arg) { + + var permission = getPermission("add", null, arg); + return handle(new BusinessWorkerAddAction(), arg, permission, TransactionType.service); + } + + // ::: EDIT + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "business worker edit operation", description = "") + // + @PutMapping("/{id}") + public ResponseEntity edit(@PathVariable("id") String id, + @RequestBody BusinessWorkerEditArgument arg) { + + arg.getEntity().id(id); + + var permission = getPermission("edit", id, arg); + return handle(new BusinessWorkerEditAction(), arg, permission, TransactionType.service); + } + + // ::: FIND + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "business worker find operation", description = "") + // + @GetMapping("/{id}") + public ResponseEntity find(@PathVariable("id") String id, + @ModelAttribute BusinessWorkerActionArgument arg) { + + + arg = arg == null ? new BusinessWorkerActionArgument() : arg; + + arg.entity(new BusinessWorkerEntity(id)); + + var permission = getPermission("find", id, arg); + return handle(new BusinessWorkerFindAction(), arg, permission); + } + + // ::: ENABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "business worker enable operation", description = "") + // + @PutMapping("/{id}/enable") + public ResponseEntity enable(@PathVariable("id") String id) { + + var arg = new BusinessWorkerActionArgument(); + arg.setEntity(new BusinessWorkerEntity(id)); + arg.getEntity().setActive(true); + + var permission = getPermission("disable", id, arg); + return handle(new BusinessWorkerEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: DISABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "business worker disable operation", description = "") + // + @PutMapping("/{id}/disable") + public ResponseEntity disable(@PathVariable("id") String id) { + + var arg = new BusinessWorkerActionArgument(); + arg.setEntity(new BusinessWorkerEntity(id)); + arg.getEntity().setActive(false); + + var permission = getPermission("disable", id, arg); + return handle(new BusinessWorkerEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: LIST + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "business worker list operation", description = "") + // + @GetMapping + public ResponseEntity list(@ModelAttribute BusinessWorkerListArgument arg) { + + arg = arg == null ? new BusinessWorkerListArgument() : arg; + + var permission = getPermission("list", null, arg); + return handle(new BusinessWorkerListAction(), arg, permission); + } + + // ::: DELETE + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "business worker delete operation", description = "") + // + @DeleteMapping("/{id}") + public ResponseEntity delete(@PathVariable("id") String id) { + + var arg = new BusinessWorkerActionArgument(); + + arg.setEntity(new BusinessWorkerEntity(id)); + + var permission = getPermission("delete", id, arg); + return handle(new BusinessWorkerDeleteAction(), arg, permission, TransactionType.service); + } + + // ::: PRELOAD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "business worker preload operation", description = "") + // + @PostMapping("/preload") + public ResponseEntity preload(@RequestBody BusinessWorkerPreloadArgument arg) { + + var permission = getPermission(arg.getAction(), null, arg); + return handle(new BusinessWorkerPreloadAction(), arg, permission); + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/BizTaxonomyRest.java b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/BizTaxonomyRest.java new file mode 100644 index 0000000..41b0885 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/BizTaxonomyRest.java @@ -0,0 +1,25 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.endpoint.rest; + +// java +import io.kumare.iqr.mod.taxonomy.endpoint.rest.AbstractTaxonRest; +import io.swagger.v3.oas.annotations.tags.*; +// spring +import org.springframework.web.bind.annotation.*; + +/** +* +* @author afatecha +*/ + +// openapi +@Tag(name = "workforce taxonomy rest endpoint") +// +@RestController +@RequestMapping("/biz/{taxaKey}-taxons") +public class BizTaxonomyRest extends AbstractTaxonRest { + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/BusinessImageRest.java b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/BusinessImageRest.java new file mode 100644 index 0000000..bd54892 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/BusinessImageRest.java @@ -0,0 +1,24 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.endpoint.rest; + +// java +import io.swagger.v3.oas.annotations.tags.*; +// spring +import org.springframework.web.bind.annotation.*; + +/** +* +* @author afatecha +*/ + +// openapi +//@Tag(name = "business image rest endpoint") +// +//@RestController +//@RequestMapping("/biz/business/{businessId}/images") +public class BusinessImageRest extends AbstractBusinessImageRest { + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/BusinessProfileRest.java b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/BusinessProfileRest.java new file mode 100644 index 0000000..df1e5de --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/BusinessProfileRest.java @@ -0,0 +1,24 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.endpoint.rest; + +// java +import io.swagger.v3.oas.annotations.tags.*; +// spring +import org.springframework.web.bind.annotation.*; + +/** +* +* @author afatecha +*/ + +// openapi +//@Tag(name = "business profile rest endpoint") +// +//@RestController +//@RequestMapping("/biz/business-profiles") +public class BusinessProfileRest extends AbstractBusinessProfileRest { + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/BusinessPromoItemRest.java b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/BusinessPromoItemRest.java new file mode 100644 index 0000000..2251296 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/BusinessPromoItemRest.java @@ -0,0 +1,24 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.endpoint.rest; + +// java +import io.swagger.v3.oas.annotations.tags.*; +// spring +import org.springframework.web.bind.annotation.*; + +/** +* +* @author afatecha +*/ + +// openapi +//@Tag(name = "business promo item rest endpoint") +// +//@RestController +//@RequestMapping("/biz/business-promo-items") +public class BusinessPromoItemRest extends AbstractBusinessPromoItemRest { + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/BusinessPromoRest.java b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/BusinessPromoRest.java new file mode 100644 index 0000000..ebae6f0 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/BusinessPromoRest.java @@ -0,0 +1,24 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.endpoint.rest; + +// java +import io.swagger.v3.oas.annotations.tags.*; +// spring +import org.springframework.web.bind.annotation.*; + +/** +* +* @author afatecha +*/ + +// openapi +//@Tag(name = "business promo rest endpoint") +// +//@RestController +//@RequestMapping("/biz/business-promos") +public class BusinessPromoRest extends AbstractBusinessPromoRest { + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/BusinessRest.java b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/BusinessRest.java new file mode 100644 index 0000000..ae3cebc --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/BusinessRest.java @@ -0,0 +1,24 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.endpoint.rest; + +// java +import io.swagger.v3.oas.annotations.tags.*; +// spring +import org.springframework.web.bind.annotation.*; + +/** +* +* @author afatecha +*/ + +// openapi +@Tag(name = "business rest endpoint") +// +@RestController +@RequestMapping("/biz/businesses") +public class BusinessRest extends AbstractBusinessRest { + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/BusinessSettingRest.java b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/BusinessSettingRest.java new file mode 100644 index 0000000..2332c4e --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/BusinessSettingRest.java @@ -0,0 +1,24 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.endpoint.rest; + +// java +import io.swagger.v3.oas.annotations.tags.*; +// spring +import org.springframework.web.bind.annotation.*; + +/** +* +* @author afatecha +*/ + +// openapi +//@Tag(name = "business setting rest endpoint") +// +//@RestController +//@RequestMapping("/biz/business-settings") +public class BusinessSettingRest extends AbstractBusinessSettingRest { + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/BusinessTagRest.java b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/BusinessTagRest.java new file mode 100644 index 0000000..899da8d --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/BusinessTagRest.java @@ -0,0 +1,24 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.endpoint.rest; + +// java +import io.swagger.v3.oas.annotations.tags.*; +// spring +import org.springframework.web.bind.annotation.*; + +/** +* +* @author afatecha +*/ + +// openapi +//@Tag(name = "business tag rest endpoint") +// +//@RestController +//@RequestMapping("/biz/business-tags") +public class BusinessTagRest extends AbstractBusinessTagRest { + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/BusinessWorkerRest.java b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/BusinessWorkerRest.java new file mode 100644 index 0000000..dec6e69 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/endpoint/rest/BusinessWorkerRest.java @@ -0,0 +1,24 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.endpoint.rest; + +// java +import io.swagger.v3.oas.annotations.tags.*; +// spring +import org.springframework.web.bind.annotation.*; + +/** +* +* @author afatecha +*/ + +// openapi +//@Tag(name = "business worker rest endpoint") +// +//@RestController +//@RequestMapping("/biz/business-workers") +public class BusinessWorkerRest extends AbstractBusinessWorkerRest { + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/BizEntities.java b/src/main/java/io/kumare/iqr/mod/biz/store/BizEntities.java new file mode 100644 index 0000000..460bc65 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/BizEntities.java @@ -0,0 +1,120 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store; + +// base +// base +import io.kumare.lib.app.api.module.ServiceModule; +import io.kumare.lib.app.api.store.EntityStore; +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app +import io.kumare.iqr.app.AppEngine; +import io.kumare.iqr.app.module.AppModules; +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; +import io.kumare.iqr.mod.biz.store.business.BusinessStore; +import io.kumare.iqr.mod.biz.store.businessprofile.BusinessProfileEntity; +import io.kumare.iqr.mod.biz.store.businessprofile.BusinessProfileStore; +import io.kumare.iqr.mod.biz.store.businesssetting.BusinessSettingEntity; +import io.kumare.iqr.mod.biz.store.businesssetting.BusinessSettingStore; +import io.kumare.iqr.mod.biz.store.businesspromo.BusinessPromoEntity; +import io.kumare.iqr.mod.biz.store.businesspromo.BusinessPromoStore; +import io.kumare.iqr.mod.biz.store.businesspromoitem.BusinessPromoItemEntity; +import io.kumare.iqr.mod.biz.store.businesspromoitem.BusinessPromoItemStore; +import io.kumare.iqr.mod.biz.store.businessimage.BusinessImageEntity; +import io.kumare.iqr.mod.biz.store.businessimage.BusinessImageStore; +import io.kumare.iqr.mod.biz.store.businessworker.BusinessWorkerEntity; +import io.kumare.iqr.mod.biz.store.businessworker.BusinessWorkerStore; +import io.kumare.iqr.mod.biz.store.businesstag.BusinessTagEntity; +import io.kumare.iqr.mod.biz.store.businesstag.BusinessTagStore; + + +/** + * + * @author afatecha + */ +public enum BizEntities implements EntityDescriptor { + + business(BusinessEntity.class, BusinessStore.class), + businessProfile(BusinessProfileEntity.class, BusinessProfileStore.class), + businessSetting(BusinessSettingEntity.class, BusinessSettingStore.class), + businessPromo(BusinessPromoEntity.class, BusinessPromoStore.class), + businessPromoItem(BusinessPromoItemEntity.class, BusinessPromoItemStore.class), + businessImage(BusinessImageEntity.class, BusinessImageStore.class), + businessWorker(BusinessWorkerEntity.class, BusinessWorkerStore.class), + businessTag(BusinessTagEntity.class, BusinessTagStore.class); + + // ::: vars + // + private final Class entityClass; + private final Class storeClass; + + // ::: constructor + // + BizEntities(Class entityClass, Class storeClass) { + this.entityClass = entityClass; + this.storeClass = storeClass; + } + + // ::: entity descriptor api + // + @Override + public String getName() { + return name(); + } + + @Override + public ServiceModule getModule() { + return AppModules.biz; + } + + @Override + public Class getEntityClass() { + return entityClass; + } + + @Override + public Class getStoreClass() { + return storeClass; + } + + @Override + public EntityStore getStore() { + return (EntityStore) AppEngine.getEngine().getInnerContext().getBean(storeClass); + } + + // ::: statics + // + public static boolean hasDescriptor(String name) { + try { + var value = valueOf(name); + return value != null; + + } catch (Throwable t) { + return false; + } + } + + public static EntityDescriptor descriptorOf(String name) { + try { + return valueOf(name); + + } catch (Throwable t) { + return null; + } + } + + public static EntityDescriptor descriptorOf(Class entityClass) { + try { + for (var i : values()) { + if (i.entityClass == entityClass) { + return i; + } + } + + } catch (Throwable t) { + } + + return null; + } +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/BizTaxonomies.java b/src/main/java/io/kumare/iqr/mod/biz/store/BizTaxonomies.java new file mode 100644 index 0000000..72b0c5a --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/BizTaxonomies.java @@ -0,0 +1,120 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store; + +// base +import io.kumare.lib.app.api.Context; +import io.kumare.lib.v.ExceptionPrototype; +// app +import io.kumare.iqr.app.module.AppModules; +import io.kumare.iqr.mod.biz.BizErrors; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; +import java.util.List; + +/** + * + * @author administrador + */ +public enum BizTaxonomies { + + businessActivity("business-activity", BizErrors.businessprofile_activity_notfound), + businessState("business-state", BizErrors.business_state_notfound), + businessPromoState("business-promo-state", BizErrors.businesspromo_state_notfound), + businessImageType("business-image-type", BizErrors.businessimage_type_notfound), + businessDefaultTag("business-default-tag", BizErrors.businesstag_notfound), + businessWorkerState("business-worker-state", BizErrors.businessworker_state_notfound), + businessWorkerRole("business-worker-role", BizErrors.businessworker_role_notfound); + + // ::: + // + private final String taxaKey; + private final ExceptionPrototype proto; + + // ::: constructor + // + BizTaxonomies(String taxaKey, ExceptionPrototype proto) { + this.taxaKey = taxaKey; + this.proto = proto; + } + + public String getKey() { + return taxaKey; + } + + // ::: ensure + // + public TaxonEntity ensure(Context context, TaxonEntity taxon) { + return AppModules.taxonomy.getController().getTaxonStore() + .ensure(context, taxaKey, taxon, proto); + } + + public TaxonEntity ensureById(Context context, String taxonId) { + return AppModules.taxonomy.getController().getTaxonStore() + .ensureById(context, taxaKey, taxonId, proto); + } + + public TaxonEntity ensureByKey(Context context, String key) { + return AppModules.taxonomy.getController().getTaxonStore() + .ensureByKey(context, taxaKey, key, proto); + } + + public TaxonEntity ensureByValue(Context context, String value) { + return AppModules.taxonomy.getController().getTaxonStore() + .ensureByValue(context, taxaKey, value, proto); + } + + // ::: find + // + public TaxonEntity findById(Context context, String taxonId) { + return AppModules.taxonomy.getController() + .getTaxonStore() + .findById(context, taxaKey, taxonId); + } + + public TaxonEntity findByKey(Context context, String key) { + return AppModules.taxonomy.getController() + .getTaxonStore() + .findByKey(context, taxaKey, key); + } + + public TaxonEntity findByValue(Context context, String value) { + return AppModules.taxonomy.getController() + .getTaxonStore() + .findByValue(context, taxaKey, value); + } + + // ::: list + // + public List list(Context context) { + return AppModules.taxonomy.getController() + .getTaxonStore() + .listByTaxaKey(context, taxaKey); + } + + // ::: default + // + public TaxonEntity ensureDefault(Context context) { + return AppModules.taxonomy.getController() + .getTaxonStore() + .ensureDefault(context, taxaKey, proto); + } + + public TaxonEntity findDefault(Context context) { + return AppModules.taxonomy.getController() + .getTaxonStore() + .findDefault(context, taxaKey); + } + + // ::: statics + // + public static boolean hasTaxaKey(String taxaKey) { + for (var i : values()) { + if (i.getKey().equals(taxaKey)) { + return true; + } + } + + return false; + } +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/BizWorkerRoles.java b/src/main/java/io/kumare/iqr/mod/biz/store/BizWorkerRoles.java new file mode 100644 index 0000000..36b09a6 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/BizWorkerRoles.java @@ -0,0 +1,29 @@ +/* + */ +package io.kumare.iqr.mod.biz.store; + +/** + * + * @author administrador + */ +public enum BizWorkerRoles { + + manager("manager-role"), + worker("worker-role"); + + // ::: implementation + // + private final String key; + + // ::: constructor + // + BizWorkerRoles(String key) { + this.key = key; + } + + // ::: api + // + public String getKey() { + return key; + } +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/business/BusinessData.java b/src/main/java/io/kumare/iqr/mod/biz/store/business/BusinessData.java new file mode 100644 index 0000000..e9ed562 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/business/BusinessData.java @@ -0,0 +1,25 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.business; + +// base +import io.kumare.iqr.app.store.AppExtendedEntityData; +// imports + + +public class BusinessData extends AppExtendedEntityData { + + // ::: vars + // + + + // ::: fields + // + + + // ::: fluent + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/business/BusinessEntity.java b/src/main/java/io/kumare/iqr/mod/biz/store/business/BusinessEntity.java new file mode 100644 index 0000000..419e6e2 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/business/BusinessEntity.java @@ -0,0 +1,137 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.business; + +// jakarta +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.Index; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +// base +import io.kumare.lib.app.api.store.*; +import io.kumare.iqr.app.store.*; +// imports + +// relations +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; + +// annotations +@Entity +@Table( + name = "business", + indexes = { + @Index(name = "idx_business_entity_key", columnList = "entityKey"), + @Index(name = "idx_business_alias", columnList = "alias"), + @Index(name = "idx_business_state_value", columnList = "stateValue"), + @Index(name = "idx_business_name", columnList = "name"), + @Index(name = "idx_business_description", columnList = "description") + } +) +public class BusinessEntity extends AppEntity implements SupportedEntityKey { + + // ::: vars + // + private String entityKey; + private String alias; + private String stateValue; + private String name; + private String description; + @ManyToOne(fetch = FetchType.LAZY) + private TaxonEntity state; + + // ::: constructors + // + public BusinessEntity() { + } + + public BusinessEntity(String id) { + super(id); + } + + // ::: fields + // + @Override + public String getEntityKey() { + return entityKey; + } + + @Override + public void setEntityKey(String entityKey) { + this.entityKey = entityKey; + } + + public String getAlias() { + return alias; + } + + public void setAlias(String alias) { + this.alias = alias; + } + + public String getStateValue() { + return stateValue; + } + + public void setStateValue(String stateValue) { + this.stateValue = stateValue; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public TaxonEntity getState() { + return state; + } + + public void setState(TaxonEntity state) { + this.state = state; + } + + // ::: fluent + // + public BusinessEntity entityKey(String entityKey) { + setEntityKey(entityKey); + return this; + } + + public BusinessEntity alias(String alias) { + setAlias(alias); + return this; + } + + public BusinessEntity stateValue(String stateValue) { + setStateValue(stateValue); + return this; + } + + public BusinessEntity name(String name) { + setName(name); + return this; + } + + public BusinessEntity description(String description) { + setDescription(description); + return this; + } + + public BusinessEntity state(TaxonEntity state) { + setState(state); + return this; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/business/BusinessFields.java b/src/main/java/io/kumare/iqr/mod/biz/store/business/BusinessFields.java new file mode 100644 index 0000000..63fd55d --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/business/BusinessFields.java @@ -0,0 +1,151 @@ +/* + */ +package io.kumare.iqr.mod.biz.store.business; + +// java +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +// base +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app +import io.kumare.iqr.mod.taxonomy.store.TaxonomyEntities; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonFields; + +/** + * + * @author afatecha + */ +public enum BusinessFields implements EntityFieldDescriptor { + + id(MAIN, FIND, LIST), + entityKey(MAIN, FIND, LIST), + alias(MAIN, FIND, LIST), + stateValue(MAIN, FIND, LIST), + name(MAIN, FIND, LIST), + description(MAIN, FIND, LIST), + active(MAIN, FIND, LIST), + inserted(AUDIT, FIND, LIST), + inserter(AUDIT, FIND, LIST), + modified(AUDIT, FIND), + modifier(AUDIT, FIND), + deleted(AUDIT), + removed(AUDIT), + remover(AUDIT), + state(TaxonomyEntities.taxon, TaxonFields.class, FIND, LIST); + + // ::: vars + // + private final boolean relation; + private final EntityDescriptor entityDescriptor; + private final Class enumClass; + private final List groups; + + // ::: constructors + // + BusinessFields(String... groups) { + this(false, null, null, groups); + } + + BusinessFields(EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this(true, entityDescriptor, enumClass, groups); + } + + BusinessFields(boolean relation, EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this.relation = relation; + this.entityDescriptor = entityDescriptor; + this.enumClass = enumClass; + this.groups = groups == null ? Collections.EMPTY_LIST : Arrays.asList(groups); + } + + // ::: api + // + @Override + public String getName() { + return name(); + } + + @Override + public boolean isRelation() { + return relation; + } + + @Override + public Class getRelationEnumClass() { + return enumClass; + } + + @Override + public List getGroups() { + return groups; + } + + @Override + public EntityDescriptor getEntityDescriptor() { + return entityDescriptor; + } + + @Override + public Object fetchValue(BusinessEntity entity) { + if (entity == null) { + return null; + } + + switch (this) { + case null -> { + return null; + } + case id -> { + return entity.getId(); + } + case entityKey ->{ + return entity.getEntityKey(); + } + case alias ->{ + return entity.getAlias(); + } + case stateValue ->{ + return entity.getStateValue(); + } + case name ->{ + return entity.getName(); + } + case description ->{ + return entity.getDescription(); + } + case active -> { + return entity.isActive(); + } + case inserted -> { + return entity.getInserted(); + } + case inserter -> { + return entity.getInserter(); + } + case modified -> { + return entity.getModified(); + } + case modifier -> { + return entity.getModifier(); + } + case deleted -> { + return entity.isDeleted(); + } + case removed -> { + return entity.getRemoved(); + } + case remover -> { + return entity.getRemover(); + } + case state ->{ + return entity.getState(); + } + default -> { + return null; + } + } + + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/business/BusinessMapBuilder.java b/src/main/java/io/kumare/iqr/mod/biz/store/business/BusinessMapBuilder.java new file mode 100644 index 0000000..6b8271e --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/business/BusinessMapBuilder.java @@ -0,0 +1,139 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.business; + +// java +import java.util.List; +import java.util.Map; +// base +import io.kumare.lib.app.api.Context; +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.BaseEntityMapBuilder; +// app +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonMapBuilder; + +/** + * + * @author afatecha + */ +public class BusinessMapBuilder extends BaseEntityMapBuilder { + + // ::: vars + // + private TaxonMapBuilder stateBuilder; + + + // ::: fields + // + @Override + public BusinessMapBuilder addGroup(String name, boolean cascade) { + includes.addAll(EntityFieldDescriptor.group(BusinessFields.values(), name)); + + if(cascade) { + if (includes.contains(BusinessFields.state)) { + getStateBuilder().addGroup(name); + } + } + return this; + } + + @Override + public BusinessMapBuilder add(String fieldName) { + includes.add(BusinessFields.valueOf(fieldName)); + return this; + } + + @Override + public BusinessMapBuilder addAll(String... names) { + for (var i : names) { + includes.add(BusinessFields.valueOf(i)); + } + return this; + } + + @Override + public BusinessMapBuilder remove(String fieldName) { + excludes.add(BusinessFields.valueOf(fieldName)); + return this; + } + + @Override + public BusinessMapBuilder removeAll(String... names) { + for (var i : names) { + excludes.add(BusinessFields.valueOf(i)); + } + return this; + } + + // ::: relations + // + @Override + public BusinessMapBuilder addPlains(boolean cascade) { + includes.addAll(EntityFieldDescriptor.plains(BusinessFields.values())); + + if(cascade) { + if (includes.contains(BusinessFields.state)) { + getStateBuilder().addPlains(); + } + } + return this; + } + + @Override + public BusinessMapBuilder addRelations(boolean cascade) { + includes.addAll(EntityFieldDescriptor.relations(BusinessFields.values())); + + if(cascade) { + if (includes.contains(BusinessFields.state)) { + getStateBuilder().addRelations(); + } + } + return this; + } + + // ::: state + // + public BusinessMapBuilder addState() { + return addState(null); + } + + public BusinessMapBuilder addState(String group) { + return addState(group, false); + } + + public BusinessMapBuilder addState(String group, boolean cascade) { + includes.add(BusinessFields.state); + + if (group != null) { + getStateBuilder().addGroup(group); + } + + return this; + } + + public TaxonMapBuilder getStateBuilder() { + if(stateBuilder == null) { + stateBuilder = new TaxonMapBuilder(); + } + return stateBuilder; + } + + // ::: internals + // + @Override + protected void internalAttachRelations(Context context, + BusinessEntity entity, + List fields, + Map resultMap) { + + if (fields.contains(BusinessFields.state)) { + attachRelation(context, + entity, + BusinessFields.state, + getStateBuilder(), + resultMap); + } + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/business/BusinessRepository.java b/src/main/java/io/kumare/iqr/mod/biz/store/business/BusinessRepository.java new file mode 100644 index 0000000..fbeac5a --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/business/BusinessRepository.java @@ -0,0 +1,18 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.business; + +// spring +import org.springframework.stereotype.Repository; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Repository +public interface BusinessRepository extends AppKeyEntityRepository{ + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/business/BusinessStore.java b/src/main/java/io/kumare/iqr/mod/biz/store/business/BusinessStore.java new file mode 100644 index 0000000..b3e28a4 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/business/BusinessStore.java @@ -0,0 +1,35 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.business; + +// spring +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Service +public class BusinessStore extends AppKeyEntityStore { + + // ::: vars + // + @Autowired + private BusinessRepository repository; + + // ::: override + // + @Override + public BusinessRepository getRepository() { + return repository; + } + + // ::: api + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businessimage/BusinessImageData.java b/src/main/java/io/kumare/iqr/mod/biz/store/businessimage/BusinessImageData.java new file mode 100644 index 0000000..8d02a28 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businessimage/BusinessImageData.java @@ -0,0 +1,25 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businessimage; + +// base +import io.kumare.iqr.app.store.AppExtendedEntityData; +// imports + + +public class BusinessImageData extends AppExtendedEntityData { + + // ::: vars + // + + + // ::: fields + // + + + // ::: fluent + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businessimage/BusinessImageEntity.java b/src/main/java/io/kumare/iqr/mod/biz/store/businessimage/BusinessImageEntity.java new file mode 100644 index 0000000..2c2bc31 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businessimage/BusinessImageEntity.java @@ -0,0 +1,109 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businessimage; + +// jakarta +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.Index; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +// base +import io.kumare.lib.app.api.store.*; +import io.kumare.iqr.app.store.*; +// imports + +// relations +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; + +// annotations +@Entity +@Table( + name = "business_image", + indexes = { + @Index(name = "idx_business_image_type_value", columnList = "typeValue"), + @Index(name = "idx_business_image_bytes", columnList = "bytes") + } +) +public class BusinessImageEntity extends AppEntity { + + // ::: vars + // + private String typeValue; + private byte[] bytes; + // relations + @ManyToOne(fetch = FetchType.LAZY) + private BusinessEntity business; + @ManyToOne(fetch = FetchType.LAZY) + private TaxonEntity type; + + // ::: constructors + // + public BusinessImageEntity() { + } + + public BusinessImageEntity(String id) { + super(id); + } + + // ::: fields + // + public String getTypeValue() { + return typeValue; + } + + public void setTypeValue(String typeValue) { + this.typeValue = typeValue; + } + + public byte[] getBytes() { + return bytes; + } + + public void setBytes(byte[] bytes) { + this.bytes = bytes; + } + + // relations + public BusinessEntity getBusiness() { + return business; + } + + public void setBusiness(BusinessEntity business) { + this.business = business; + } + + public TaxonEntity getType() { + return type; + } + + public void setType(TaxonEntity type) { + this.type = type; + } + + // ::: fluent + // + public BusinessImageEntity typeValue(String typeValue) { + setTypeValue(typeValue); + return this; + } + + public BusinessImageEntity bytes(byte[] bytes) { + setBytes(bytes); + return this; + } + + // relations + public BusinessImageEntity business(BusinessEntity business) { + setBusiness(business); + return this; + } + + public BusinessImageEntity type(TaxonEntity type) { + setType(type); + return this; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businessimage/BusinessImageFields.java b/src/main/java/io/kumare/iqr/mod/biz/store/businessimage/BusinessImageFields.java new file mode 100644 index 0000000..5c2838f --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businessimage/BusinessImageFields.java @@ -0,0 +1,145 @@ +/* + */ +package io.kumare.iqr.mod.biz.store.businessimage; + +// java +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +// base +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app +import io.kumare.iqr.mod.biz.store.BizEntities; +import io.kumare.iqr.mod.biz.store.business.BusinessFields; +import io.kumare.iqr.mod.taxonomy.store.TaxonomyEntities; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonFields; + +/** + * + * @author afatecha + */ +public enum BusinessImageFields implements EntityFieldDescriptor { + + id(MAIN, FIND, LIST), + typeValue(MAIN, FIND, LIST), + bytes(MAIN, FIND, LIST), + active(MAIN, FIND, LIST), + inserted(AUDIT, FIND, LIST), + inserter(AUDIT, FIND, LIST), + modified(AUDIT, FIND), + modifier(AUDIT, FIND), + deleted(AUDIT), + removed(AUDIT), + remover(AUDIT), + business(BizEntities.business, BusinessFields.class, FIND, LIST), + type(TaxonomyEntities.taxon, TaxonFields.class, FIND, LIST); + + // ::: vars + // + private final boolean relation; + private final EntityDescriptor entityDescriptor; + private final Class enumClass; + private final List groups; + + // ::: constructors + // + BusinessImageFields(String... groups) { + this(false, null, null, groups); + } + + BusinessImageFields(EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this(true, entityDescriptor, enumClass, groups); + } + + BusinessImageFields(boolean relation, EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this.relation = relation; + this.entityDescriptor = entityDescriptor; + this.enumClass = enumClass; + this.groups = groups == null ? Collections.EMPTY_LIST : Arrays.asList(groups); + } + + // ::: api + // + @Override + public String getName() { + return name(); + } + + @Override + public boolean isRelation() { + return relation; + } + + @Override + public Class getRelationEnumClass() { + return enumClass; + } + + @Override + public List getGroups() { + return groups; + } + + @Override + public EntityDescriptor getEntityDescriptor() { + return entityDescriptor; + } + + @Override + public Object fetchValue(BusinessImageEntity entity) { + if (entity == null) { + return null; + } + + switch (this) { + case null -> { + return null; + } + case id -> { + return entity.getId(); + } + case typeValue ->{ + return entity.getTypeValue(); + } + case bytes ->{ + return entity.getBytes(); + } + case active -> { + return entity.isActive(); + } + case inserted -> { + return entity.getInserted(); + } + case inserter -> { + return entity.getInserter(); + } + case modified -> { + return entity.getModified(); + } + case modifier -> { + return entity.getModifier(); + } + case deleted -> { + return entity.isDeleted(); + } + case removed -> { + return entity.getRemoved(); + } + case remover -> { + return entity.getRemover(); + } + case business ->{ + return entity.getBusiness(); + } + case type ->{ + return entity.getType(); + } + default -> { + return null; + } + } + + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businessimage/BusinessImageMapBuilder.java b/src/main/java/io/kumare/iqr/mod/biz/store/businessimage/BusinessImageMapBuilder.java new file mode 100644 index 0000000..8f80fcd --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businessimage/BusinessImageMapBuilder.java @@ -0,0 +1,185 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businessimage; + +// java +import java.util.List; +import java.util.Map; +// base +import io.kumare.lib.app.api.Context; +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.BaseEntityMapBuilder; +// app +import io.kumare.iqr.mod.biz.store.business.BusinessMapBuilder; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonMapBuilder; + +/** + * + * @author afatecha + */ +public class BusinessImageMapBuilder extends BaseEntityMapBuilder { + + // ::: vars + // + private BusinessMapBuilder businessBuilder; + private TaxonMapBuilder typeBuilder; + + + // ::: fields + // + @Override + public BusinessImageMapBuilder addGroup(String name, boolean cascade) { + includes.addAll(EntityFieldDescriptor.group(BusinessImageFields.values(), name)); + + if(cascade) { + if (includes.contains(BusinessImageFields.business)) { + getBusinessBuilder().addGroup(name); + } + if (includes.contains(BusinessImageFields.type)) { + getTypeBuilder().addGroup(name); + } + } + return this; + } + + @Override + public BusinessImageMapBuilder add(String fieldName) { + includes.add(BusinessImageFields.valueOf(fieldName)); + return this; + } + + @Override + public BusinessImageMapBuilder addAll(String... names) { + for (var i : names) { + includes.add(BusinessImageFields.valueOf(i)); + } + return this; + } + + @Override + public BusinessImageMapBuilder remove(String fieldName) { + excludes.add(BusinessImageFields.valueOf(fieldName)); + return this; + } + + @Override + public BusinessImageMapBuilder removeAll(String... names) { + for (var i : names) { + excludes.add(BusinessImageFields.valueOf(i)); + } + return this; + } + + // ::: relations + // + @Override + public BusinessImageMapBuilder addPlains(boolean cascade) { + includes.addAll(EntityFieldDescriptor.plains(BusinessImageFields.values())); + + if(cascade) { + if (includes.contains(BusinessImageFields.business)) { + getBusinessBuilder().addPlains(); + } + if (includes.contains(BusinessImageFields.type)) { + getTypeBuilder().addPlains(); + } + } + return this; + } + + @Override + public BusinessImageMapBuilder addRelations(boolean cascade) { + includes.addAll(EntityFieldDescriptor.relations(BusinessImageFields.values())); + + if(cascade) { + if (includes.contains(BusinessImageFields.business)) { + getBusinessBuilder().addRelations(); + } + if (includes.contains(BusinessImageFields.type)) { + getTypeBuilder().addRelations(); + } + } + return this; + } + + // ::: business + // + public BusinessImageMapBuilder addBusiness() { + return addBusiness(null); + } + + public BusinessImageMapBuilder addBusiness(String group) { + return addBusiness(group, false); + } + + public BusinessImageMapBuilder addBusiness(String group, boolean cascade) { + includes.add(BusinessImageFields.business); + + if (group != null) { + getBusinessBuilder().addGroup(group); + } + + return this; + } + + public BusinessMapBuilder getBusinessBuilder() { + if(businessBuilder == null) { + businessBuilder = new BusinessMapBuilder(); + } + return businessBuilder; + } + + + // ::: type + // + public BusinessImageMapBuilder addType() { + return addType(null); + } + + public BusinessImageMapBuilder addType(String group) { + return addType(group, false); + } + + public BusinessImageMapBuilder addType(String group, boolean cascade) { + includes.add(BusinessImageFields.type); + + if (group != null) { + getTypeBuilder().addGroup(group); + } + + return this; + } + + public TaxonMapBuilder getTypeBuilder() { + if(typeBuilder == null) { + typeBuilder = new TaxonMapBuilder(); + } + return typeBuilder; + } + + // ::: internals + // + @Override + protected void internalAttachRelations(Context context, + BusinessImageEntity entity, + List fields, + Map resultMap) { + + if (fields.contains(BusinessImageFields.business)) { + attachRelation(context, + entity, + BusinessImageFields.business, + getBusinessBuilder(), + resultMap); + } + if (fields.contains(BusinessImageFields.type)) { + attachRelation(context, + entity, + BusinessImageFields.type, + getTypeBuilder(), + resultMap); + } + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businessimage/BusinessImageRepository.java b/src/main/java/io/kumare/iqr/mod/biz/store/businessimage/BusinessImageRepository.java new file mode 100644 index 0000000..50659ec --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businessimage/BusinessImageRepository.java @@ -0,0 +1,18 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businessimage; + +// spring +import org.springframework.stereotype.Repository; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Repository +public interface BusinessImageRepository extends AppEntityRepository{ + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businessimage/BusinessImageStore.java b/src/main/java/io/kumare/iqr/mod/biz/store/businessimage/BusinessImageStore.java new file mode 100644 index 0000000..7ae4773 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businessimage/BusinessImageStore.java @@ -0,0 +1,35 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businessimage; + +// spring +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Service +public class BusinessImageStore extends AppEntityStore { + + // ::: vars + // + @Autowired + private BusinessImageRepository repository; + + // ::: override + // + @Override + public BusinessImageRepository getRepository() { + return repository; + } + + // ::: api + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businessprofile/BusinessProfileData.java b/src/main/java/io/kumare/iqr/mod/biz/store/businessprofile/BusinessProfileData.java new file mode 100644 index 0000000..b685ba3 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businessprofile/BusinessProfileData.java @@ -0,0 +1,25 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businessprofile; + +// base +import io.kumare.iqr.app.store.AppExtendedEntityData; +// imports + + +public class BusinessProfileData extends AppExtendedEntityData { + + // ::: vars + // + + + // ::: fields + // + + + // ::: fluent + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businessprofile/BusinessProfileEntity.java b/src/main/java/io/kumare/iqr/mod/biz/store/businessprofile/BusinessProfileEntity.java new file mode 100644 index 0000000..fe05d17 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businessprofile/BusinessProfileEntity.java @@ -0,0 +1,200 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businessprofile; + +// jakarta +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.Index; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +// base +import io.kumare.lib.app.api.store.*; +import io.kumare.iqr.app.store.*; +// imports + +// relations +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; +import io.kumare.iqr.mod.biz.store.businessimage.BusinessImageEntity; + +// annotations +@Entity +@Table( + name = "business_profile", + indexes = { + @Index(name = "idx_business_profile_activity_value", columnList = "activityValue"), + @Index(name = "idx_business_profile_gps_latitude", columnList = "gpsLatitude"), + @Index(name = "idx_business_profile_gps_longitude", columnList = "gpsLongitude"), + @Index(name = "idx_business_profile_website", columnList = "website"), + @Index(name = "idx_business_profile_phone", columnList = "phone"), + @Index(name = "idx_business_profile_address", columnList = "address"), + @Index(name = "idx_business_profile_extra_info", columnList = "extraInfo"), + @Index(name = "idx_business_profile_description", columnList = "description") + } +) +public class BusinessProfileEntity extends AppEntity { + + // ::: vars + // + private String activityValue; + private String gpsLatitude; + private String gpsLongitude; + private String website; + private String phone; + private String address; + private String extraInfo; + private String description; + // relations + @ManyToOne(fetch = FetchType.LAZY) + private BusinessEntity business; + @ManyToOne(fetch = FetchType.LAZY) + private TaxonEntity activity; + + // ::: constructors + // + public BusinessProfileEntity() { + } + + public BusinessProfileEntity(String id) { + super(id); + } + + // ::: fields + // + public String getActivityValue() { + return activityValue; + } + + public void setActivityValue(String activityValue) { + this.activityValue = activityValue; + } + + public String getGpsLatitude() { + return gpsLatitude; + } + + public void setGpsLatitude(String gpsLatitude) { + this.gpsLatitude = gpsLatitude; + } + + public String getGpsLongitude() { + return gpsLongitude; + } + + public void setGpsLongitude(String gpsLongitude) { + this.gpsLongitude = gpsLongitude; + } + + public String getWebsite() { + return website; + } + + public void setWebsite(String website) { + this.website = website; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getExtraInfo() { + return extraInfo; + } + + public void setExtraInfo(String extraInfo) { + this.extraInfo = extraInfo; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + // relations + public BusinessEntity getBusiness() { + return business; + } + + public void setBusiness(BusinessEntity business) { + this.business = business; + } + + public TaxonEntity getActivity() { + return activity; + } + + public void setActivity(TaxonEntity activity) { + this.activity = activity; + } + + // ::: fluent + // + public BusinessProfileEntity activityValue(String activityValue) { + setActivityValue(activityValue); + return this; + } + + public BusinessProfileEntity gpsLatitude(String gpsLatitude) { + setGpsLatitude(gpsLatitude); + return this; + } + + public BusinessProfileEntity gpsLongitude(String gpsLongitude) { + setGpsLongitude(gpsLongitude); + return this; + } + + public BusinessProfileEntity website(String website) { + setWebsite(website); + return this; + } + + public BusinessProfileEntity phone(String phone) { + setPhone(phone); + return this; + } + + public BusinessProfileEntity address(String address) { + setAddress(address); + return this; + } + + public BusinessProfileEntity extraInfo(String extraInfo) { + setExtraInfo(extraInfo); + return this; + } + + public BusinessProfileEntity description(String description) { + setDescription(description); + return this; + } + + // relations + public BusinessProfileEntity business(BusinessEntity business) { + setBusiness(business); + return this; + } + + public BusinessProfileEntity activity(TaxonEntity activity) { + setActivity(activity); + return this; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businessprofile/BusinessProfileFields.java b/src/main/java/io/kumare/iqr/mod/biz/store/businessprofile/BusinessProfileFields.java new file mode 100644 index 0000000..b4decac --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businessprofile/BusinessProfileFields.java @@ -0,0 +1,171 @@ +/* + */ +package io.kumare.iqr.mod.biz.store.businessprofile; + +// java +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +// base +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app +import io.kumare.iqr.mod.biz.store.BizEntities; +import io.kumare.iqr.mod.biz.store.business.BusinessFields; +import io.kumare.iqr.mod.biz.store.BizEntities; +import io.kumare.iqr.mod.biz.store.businessimage.BusinessImageFields; +import io.kumare.iqr.mod.taxonomy.store.TaxonomyEntities; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonFields; + +/** + * + * @author afatecha + */ +public enum BusinessProfileFields implements EntityFieldDescriptor { + + id(MAIN, FIND, LIST), + activityValue(MAIN, FIND, LIST), + gpsLatitude(MAIN, FIND, LIST), + gpsLongitude(MAIN, FIND, LIST), + website(MAIN, FIND, LIST), + phone(MAIN, FIND, LIST), + address(MAIN, FIND, LIST), + extraInfo(MAIN, FIND, LIST), + description(MAIN, FIND, LIST), + active(MAIN, FIND, LIST), + inserted(AUDIT, FIND, LIST), + inserter(AUDIT, FIND, LIST), + modified(AUDIT, FIND), + modifier(AUDIT, FIND), + deleted(AUDIT), + removed(AUDIT), + remover(AUDIT), + business(BizEntities.business, BusinessFields.class, FIND, LIST), + activity(TaxonomyEntities.taxon, TaxonFields.class, FIND, LIST); + + // ::: vars + // + private final boolean relation; + private final EntityDescriptor entityDescriptor; + private final Class enumClass; + private final List groups; + + // ::: constructors + // + BusinessProfileFields(String... groups) { + this(false, null, null, groups); + } + + BusinessProfileFields(EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this(true, entityDescriptor, enumClass, groups); + } + + BusinessProfileFields(boolean relation, EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this.relation = relation; + this.entityDescriptor = entityDescriptor; + this.enumClass = enumClass; + this.groups = groups == null ? Collections.EMPTY_LIST : Arrays.asList(groups); + } + + // ::: api + // + @Override + public String getName() { + return name(); + } + + @Override + public boolean isRelation() { + return relation; + } + + @Override + public Class getRelationEnumClass() { + return enumClass; + } + + @Override + public List getGroups() { + return groups; + } + + @Override + public EntityDescriptor getEntityDescriptor() { + return entityDescriptor; + } + + @Override + public Object fetchValue(BusinessProfileEntity entity) { + if (entity == null) { + return null; + } + + switch (this) { + case null -> { + return null; + } + case id -> { + return entity.getId(); + } + case activityValue ->{ + return entity.getActivityValue(); + } + case gpsLatitude ->{ + return entity.getGpsLatitude(); + } + case gpsLongitude ->{ + return entity.getGpsLongitude(); + } + case website ->{ + return entity.getWebsite(); + } + case phone ->{ + return entity.getPhone(); + } + case address ->{ + return entity.getAddress(); + } + case extraInfo ->{ + return entity.getExtraInfo(); + } + case description ->{ + return entity.getDescription(); + } + case active -> { + return entity.isActive(); + } + case inserted -> { + return entity.getInserted(); + } + case inserter -> { + return entity.getInserter(); + } + case modified -> { + return entity.getModified(); + } + case modifier -> { + return entity.getModifier(); + } + case deleted -> { + return entity.isDeleted(); + } + case removed -> { + return entity.getRemoved(); + } + case remover -> { + return entity.getRemover(); + } + case business ->{ + return entity.getBusiness(); + } + case activity ->{ + return entity.getActivity(); + } + default -> { + return null; + } + } + + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businessprofile/BusinessProfileMapBuilder.java b/src/main/java/io/kumare/iqr/mod/biz/store/businessprofile/BusinessProfileMapBuilder.java new file mode 100644 index 0000000..146f429 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businessprofile/BusinessProfileMapBuilder.java @@ -0,0 +1,185 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businessprofile; + +// java +import java.util.List; +import java.util.Map; +// base +import io.kumare.lib.app.api.Context; +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.BaseEntityMapBuilder; +// app +import io.kumare.iqr.mod.biz.store.business.BusinessMapBuilder; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonMapBuilder; + +/** + * + * @author afatecha + */ +public class BusinessProfileMapBuilder extends BaseEntityMapBuilder { + + // ::: vars + // + private BusinessMapBuilder businessBuilder; + private TaxonMapBuilder activityBuilder; + + + // ::: fields + // + @Override + public BusinessProfileMapBuilder addGroup(String name, boolean cascade) { + includes.addAll(EntityFieldDescriptor.group(BusinessProfileFields.values(), name)); + + if(cascade) { + if (includes.contains(BusinessProfileFields.business)) { + getBusinessBuilder().addGroup(name); + } + if (includes.contains(BusinessProfileFields.activity)) { + getActivityBuilder().addGroup(name); + } + } + return this; + } + + @Override + public BusinessProfileMapBuilder add(String fieldName) { + includes.add(BusinessProfileFields.valueOf(fieldName)); + return this; + } + + @Override + public BusinessProfileMapBuilder addAll(String... names) { + for (var i : names) { + includes.add(BusinessProfileFields.valueOf(i)); + } + return this; + } + + @Override + public BusinessProfileMapBuilder remove(String fieldName) { + excludes.add(BusinessProfileFields.valueOf(fieldName)); + return this; + } + + @Override + public BusinessProfileMapBuilder removeAll(String... names) { + for (var i : names) { + excludes.add(BusinessProfileFields.valueOf(i)); + } + return this; + } + + // ::: relations + // + @Override + public BusinessProfileMapBuilder addPlains(boolean cascade) { + includes.addAll(EntityFieldDescriptor.plains(BusinessProfileFields.values())); + + if(cascade) { + if (includes.contains(BusinessProfileFields.business)) { + getBusinessBuilder().addPlains(); + } + if (includes.contains(BusinessProfileFields.activity)) { + getActivityBuilder().addPlains(); + } + } + return this; + } + + @Override + public BusinessProfileMapBuilder addRelations(boolean cascade) { + includes.addAll(EntityFieldDescriptor.relations(BusinessProfileFields.values())); + + if(cascade) { + if (includes.contains(BusinessProfileFields.business)) { + getBusinessBuilder().addRelations(); + } + if (includes.contains(BusinessProfileFields.activity)) { + getActivityBuilder().addRelations(); + } + } + return this; + } + + // ::: business + // + public BusinessProfileMapBuilder addBusiness() { + return addBusiness(null); + } + + public BusinessProfileMapBuilder addBusiness(String group) { + return addBusiness(group, false); + } + + public BusinessProfileMapBuilder addBusiness(String group, boolean cascade) { + includes.add(BusinessProfileFields.business); + + if (group != null) { + getBusinessBuilder().addGroup(group); + } + + return this; + } + + public BusinessMapBuilder getBusinessBuilder() { + if(businessBuilder == null) { + businessBuilder = new BusinessMapBuilder(); + } + return businessBuilder; + } + + + // ::: activity + // + public BusinessProfileMapBuilder addActivity() { + return addActivity(null); + } + + public BusinessProfileMapBuilder addActivity(String group) { + return addActivity(group, false); + } + + public BusinessProfileMapBuilder addActivity(String group, boolean cascade) { + includes.add(BusinessProfileFields.activity); + + if (group != null) { + getActivityBuilder().addGroup(group); + } + + return this; + } + + public TaxonMapBuilder getActivityBuilder() { + if(activityBuilder == null) { + activityBuilder = new TaxonMapBuilder(); + } + return activityBuilder; + } + + // ::: internals + // + @Override + protected void internalAttachRelations(Context context, + BusinessProfileEntity entity, + List fields, + Map resultMap) { + + if (fields.contains(BusinessProfileFields.business)) { + attachRelation(context, + entity, + BusinessProfileFields.business, + getBusinessBuilder(), + resultMap); + } + if (fields.contains(BusinessProfileFields.activity)) { + attachRelation(context, + entity, + BusinessProfileFields.activity, + getActivityBuilder(), + resultMap); + } + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businessprofile/BusinessProfileRepository.java b/src/main/java/io/kumare/iqr/mod/biz/store/businessprofile/BusinessProfileRepository.java new file mode 100644 index 0000000..f6f0c41 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businessprofile/BusinessProfileRepository.java @@ -0,0 +1,18 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businessprofile; + +// spring +import org.springframework.stereotype.Repository; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Repository +public interface BusinessProfileRepository extends AppEntityRepository{ + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businessprofile/BusinessProfileStore.java b/src/main/java/io/kumare/iqr/mod/biz/store/businessprofile/BusinessProfileStore.java new file mode 100644 index 0000000..f6ed880 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businessprofile/BusinessProfileStore.java @@ -0,0 +1,35 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businessprofile; + +// spring +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Service +public class BusinessProfileStore extends AppEntityStore { + + // ::: vars + // + @Autowired + private BusinessProfileRepository repository; + + // ::: override + // + @Override + public BusinessProfileRepository getRepository() { + return repository; + } + + // ::: api + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businesspromo/BusinessPromoData.java b/src/main/java/io/kumare/iqr/mod/biz/store/businesspromo/BusinessPromoData.java new file mode 100644 index 0000000..a0722d0 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businesspromo/BusinessPromoData.java @@ -0,0 +1,25 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businesspromo; + +// base +import io.kumare.iqr.app.store.AppExtendedEntityData; +// imports + + +public class BusinessPromoData extends AppExtendedEntityData { + + // ::: vars + // + + + // ::: fields + // + + + // ::: fluent + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businesspromo/BusinessPromoEntity.java b/src/main/java/io/kumare/iqr/mod/biz/store/businesspromo/BusinessPromoEntity.java new file mode 100644 index 0000000..b19b2ac --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businesspromo/BusinessPromoEntity.java @@ -0,0 +1,215 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businesspromo; + +// jakarta +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.Index; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +// base +import io.kumare.lib.app.api.store.*; +import io.kumare.iqr.app.store.*; +// imports +import java.util.Date; +// relations +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; +import io.kumare.iqr.mod.biz.store.businessimage.BusinessImageEntity; + +// annotations +@Entity +@Table( + name = "business_promo", + indexes = { + @Index(name = "idx_business_promo_state_value", columnList = "stateValue"), + @Index(name = "idx_business_promo_started", columnList = "started"), + @Index(name = "idx_business_promo_ended", columnList = "ended"), + @Index(name = "idx_business_promo_schedule_start", columnList = "scheduleStart"), + @Index(name = "idx_business_promo_schedule_end", columnList = "scheduleEnd"), + @Index(name = "idx_business_promo_title", columnList = "title"), + @Index(name = "idx_business_promo_body_info", columnList = "bodyInfo"), + @Index(name = "idx_business_promo_footer_info", columnList = "footerInfo") + } +) +public class BusinessPromoEntity extends AppEntity { + + // ::: vars + // + private String stateValue; + private Date started; + private Date ended; + private Date scheduleStart; + private Date scheduleEnd; + private String title; + private String bodyInfo; + private String footerInfo; + // relations + @ManyToOne(fetch = FetchType.LAZY) + private BusinessEntity business; + @ManyToOne(fetch = FetchType.LAZY) + private BusinessImageEntity image; + @ManyToOne(fetch = FetchType.LAZY) + private TaxonEntity state; + + // ::: constructors + // + public BusinessPromoEntity() { + } + + public BusinessPromoEntity(String id) { + super(id); + } + + // ::: fields + // + public String getStateValue() { + return stateValue; + } + + public void setStateValue(String stateValue) { + this.stateValue = stateValue; + } + + public Date getStarted() { + return started; + } + + public void setStarted(Date started) { + this.started = started; + } + + public Date getEnded() { + return ended; + } + + public void setEnded(Date ended) { + this.ended = ended; + } + + public Date getScheduleStart() { + return scheduleStart; + } + + public void setScheduleStart(Date scheduleStart) { + this.scheduleStart = scheduleStart; + } + + public Date getScheduleEnd() { + return scheduleEnd; + } + + public void setScheduleEnd(Date scheduleEnd) { + this.scheduleEnd = scheduleEnd; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getBodyInfo() { + return bodyInfo; + } + + public void setBodyInfo(String bodyInfo) { + this.bodyInfo = bodyInfo; + } + + public String getFooterInfo() { + return footerInfo; + } + + public void setFooterInfo(String footerInfo) { + this.footerInfo = footerInfo; + } + + // relations + public BusinessEntity getBusiness() { + return business; + } + + public void setBusiness(BusinessEntity business) { + this.business = business; + } + + public BusinessImageEntity getImage() { + return image; + } + + public void setImage(BusinessImageEntity image) { + this.image = image; + } + + public TaxonEntity getState() { + return state; + } + + public void setState(TaxonEntity state) { + this.state = state; + } + + // ::: fluent + // + public BusinessPromoEntity stateValue(String stateValue) { + setStateValue(stateValue); + return this; + } + + public BusinessPromoEntity started(Date started) { + setStarted(started); + return this; + } + + public BusinessPromoEntity ended(Date ended) { + setEnded(ended); + return this; + } + + public BusinessPromoEntity scheduleStart(Date scheduleStart) { + setScheduleStart(scheduleStart); + return this; + } + + public BusinessPromoEntity scheduleEnd(Date scheduleEnd) { + setScheduleEnd(scheduleEnd); + return this; + } + + public BusinessPromoEntity title(String title) { + setTitle(title); + return this; + } + + public BusinessPromoEntity bodyInfo(String bodyInfo) { + setBodyInfo(bodyInfo); + return this; + } + + public BusinessPromoEntity footerInfo(String footerInfo) { + setFooterInfo(footerInfo); + return this; + } + + // relations + public BusinessPromoEntity business(BusinessEntity business) { + setBusiness(business); + return this; + } + + public BusinessPromoEntity image(BusinessImageEntity image) { + setImage(image); + return this; + } + + public BusinessPromoEntity state(TaxonEntity state) { + setState(state); + return this; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businesspromo/BusinessPromoFields.java b/src/main/java/io/kumare/iqr/mod/biz/store/businesspromo/BusinessPromoFields.java new file mode 100644 index 0000000..2bf6dbc --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businesspromo/BusinessPromoFields.java @@ -0,0 +1,175 @@ +/* + */ +package io.kumare.iqr.mod.biz.store.businesspromo; + +// java +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +// base +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app +import io.kumare.iqr.mod.biz.store.BizEntities; +import io.kumare.iqr.mod.biz.store.business.BusinessFields; +import io.kumare.iqr.mod.biz.store.BizEntities; +import io.kumare.iqr.mod.biz.store.businessimage.BusinessImageFields; +import io.kumare.iqr.mod.taxonomy.store.TaxonomyEntities; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonFields; + +/** + * + * @author afatecha + */ +public enum BusinessPromoFields implements EntityFieldDescriptor { + + id(MAIN, FIND, LIST), + stateValue(MAIN, FIND, LIST), + started(MAIN, FIND, LIST), + ended(MAIN, FIND, LIST), + scheduleStart(MAIN, FIND, LIST), + scheduleEnd(MAIN, FIND, LIST), + title(MAIN, FIND, LIST), + bodyInfo(MAIN, FIND, LIST), + footerInfo(MAIN, FIND, LIST), + active(MAIN, FIND, LIST), + inserted(AUDIT, FIND, LIST), + inserter(AUDIT, FIND, LIST), + modified(AUDIT, FIND), + modifier(AUDIT, FIND), + deleted(AUDIT), + removed(AUDIT), + remover(AUDIT), + business(BizEntities.business, BusinessFields.class, FIND, LIST), + image(BizEntities.businessImage, BusinessImageFields.class, FIND, LIST), + state(TaxonomyEntities.taxon, TaxonFields.class, FIND, LIST); + + // ::: vars + // + private final boolean relation; + private final EntityDescriptor entityDescriptor; + private final Class enumClass; + private final List groups; + + // ::: constructors + // + BusinessPromoFields(String... groups) { + this(false, null, null, groups); + } + + BusinessPromoFields(EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this(true, entityDescriptor, enumClass, groups); + } + + BusinessPromoFields(boolean relation, EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this.relation = relation; + this.entityDescriptor = entityDescriptor; + this.enumClass = enumClass; + this.groups = groups == null ? Collections.EMPTY_LIST : Arrays.asList(groups); + } + + // ::: api + // + @Override + public String getName() { + return name(); + } + + @Override + public boolean isRelation() { + return relation; + } + + @Override + public Class getRelationEnumClass() { + return enumClass; + } + + @Override + public List getGroups() { + return groups; + } + + @Override + public EntityDescriptor getEntityDescriptor() { + return entityDescriptor; + } + + @Override + public Object fetchValue(BusinessPromoEntity entity) { + if (entity == null) { + return null; + } + + switch (this) { + case null -> { + return null; + } + case id -> { + return entity.getId(); + } + case stateValue ->{ + return entity.getStateValue(); + } + case started ->{ + return entity.getStarted(); + } + case ended ->{ + return entity.getEnded(); + } + case scheduleStart ->{ + return entity.getScheduleStart(); + } + case scheduleEnd ->{ + return entity.getScheduleEnd(); + } + case title ->{ + return entity.getTitle(); + } + case bodyInfo ->{ + return entity.getBodyInfo(); + } + case footerInfo ->{ + return entity.getFooterInfo(); + } + case active -> { + return entity.isActive(); + } + case inserted -> { + return entity.getInserted(); + } + case inserter -> { + return entity.getInserter(); + } + case modified -> { + return entity.getModified(); + } + case modifier -> { + return entity.getModifier(); + } + case deleted -> { + return entity.isDeleted(); + } + case removed -> { + return entity.getRemoved(); + } + case remover -> { + return entity.getRemover(); + } + case business ->{ + return entity.getBusiness(); + } + case image ->{ + return entity.getImage(); + } + case state ->{ + return entity.getState(); + } + default -> { + return null; + } + } + + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businesspromo/BusinessPromoMapBuilder.java b/src/main/java/io/kumare/iqr/mod/biz/store/businesspromo/BusinessPromoMapBuilder.java new file mode 100644 index 0000000..a810d6e --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businesspromo/BusinessPromoMapBuilder.java @@ -0,0 +1,231 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businesspromo; + +// java +import java.util.List; +import java.util.Map; +// base +import io.kumare.lib.app.api.Context; +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.BaseEntityMapBuilder; +// app +import io.kumare.iqr.mod.biz.store.business.BusinessMapBuilder; +import io.kumare.iqr.mod.biz.store.businessimage.BusinessImageMapBuilder; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonMapBuilder; + +/** + * + * @author afatecha + */ +public class BusinessPromoMapBuilder extends BaseEntityMapBuilder { + + // ::: vars + // + private BusinessMapBuilder businessBuilder; + private BusinessImageMapBuilder imageBuilder; + private TaxonMapBuilder stateBuilder; + + + // ::: fields + // + @Override + public BusinessPromoMapBuilder addGroup(String name, boolean cascade) { + includes.addAll(EntityFieldDescriptor.group(BusinessPromoFields.values(), name)); + + if(cascade) { + if (includes.contains(BusinessPromoFields.business)) { + getBusinessBuilder().addGroup(name); + } + if (includes.contains(BusinessPromoFields.image)) { + getImageBuilder().addGroup(name); + } + if (includes.contains(BusinessPromoFields.state)) { + getStateBuilder().addGroup(name); + } + } + return this; + } + + @Override + public BusinessPromoMapBuilder add(String fieldName) { + includes.add(BusinessPromoFields.valueOf(fieldName)); + return this; + } + + @Override + public BusinessPromoMapBuilder addAll(String... names) { + for (var i : names) { + includes.add(BusinessPromoFields.valueOf(i)); + } + return this; + } + + @Override + public BusinessPromoMapBuilder remove(String fieldName) { + excludes.add(BusinessPromoFields.valueOf(fieldName)); + return this; + } + + @Override + public BusinessPromoMapBuilder removeAll(String... names) { + for (var i : names) { + excludes.add(BusinessPromoFields.valueOf(i)); + } + return this; + } + + // ::: relations + // + @Override + public BusinessPromoMapBuilder addPlains(boolean cascade) { + includes.addAll(EntityFieldDescriptor.plains(BusinessPromoFields.values())); + + if(cascade) { + if (includes.contains(BusinessPromoFields.business)) { + getBusinessBuilder().addPlains(); + } + if (includes.contains(BusinessPromoFields.image)) { + getImageBuilder().addPlains(); + } + if (includes.contains(BusinessPromoFields.state)) { + getStateBuilder().addPlains(); + } + } + return this; + } + + @Override + public BusinessPromoMapBuilder addRelations(boolean cascade) { + includes.addAll(EntityFieldDescriptor.relations(BusinessPromoFields.values())); + + if(cascade) { + if (includes.contains(BusinessPromoFields.business)) { + getBusinessBuilder().addRelations(); + } + if (includes.contains(BusinessPromoFields.image)) { + getImageBuilder().addRelations(); + } + if (includes.contains(BusinessPromoFields.state)) { + getStateBuilder().addRelations(); + } + } + return this; + } + + // ::: business + // + public BusinessPromoMapBuilder addBusiness() { + return addBusiness(null); + } + + public BusinessPromoMapBuilder addBusiness(String group) { + return addBusiness(group, false); + } + + public BusinessPromoMapBuilder addBusiness(String group, boolean cascade) { + includes.add(BusinessPromoFields.business); + + if (group != null) { + getBusinessBuilder().addGroup(group); + } + + return this; + } + + public BusinessMapBuilder getBusinessBuilder() { + if(businessBuilder == null) { + businessBuilder = new BusinessMapBuilder(); + } + return businessBuilder; + } + + + // ::: image + // + public BusinessPromoMapBuilder addImage() { + return addImage(null); + } + + public BusinessPromoMapBuilder addImage(String group) { + return addImage(group, false); + } + + public BusinessPromoMapBuilder addImage(String group, boolean cascade) { + includes.add(BusinessPromoFields.image); + + if (group != null) { + getImageBuilder().addGroup(group); + } + + return this; + } + + public BusinessImageMapBuilder getImageBuilder() { + if(imageBuilder == null) { + imageBuilder = new BusinessImageMapBuilder(); + } + return imageBuilder; + } + + + // ::: state + // + public BusinessPromoMapBuilder addState() { + return addState(null); + } + + public BusinessPromoMapBuilder addState(String group) { + return addState(group, false); + } + + public BusinessPromoMapBuilder addState(String group, boolean cascade) { + includes.add(BusinessPromoFields.state); + + if (group != null) { + getStateBuilder().addGroup(group); + } + + return this; + } + + public TaxonMapBuilder getStateBuilder() { + if(stateBuilder == null) { + stateBuilder = new TaxonMapBuilder(); + } + return stateBuilder; + } + + // ::: internals + // + @Override + protected void internalAttachRelations(Context context, + BusinessPromoEntity entity, + List fields, + Map resultMap) { + + if (fields.contains(BusinessPromoFields.business)) { + attachRelation(context, + entity, + BusinessPromoFields.business, + getBusinessBuilder(), + resultMap); + } + if (fields.contains(BusinessPromoFields.image)) { + attachRelation(context, + entity, + BusinessPromoFields.image, + getImageBuilder(), + resultMap); + } + if (fields.contains(BusinessPromoFields.state)) { + attachRelation(context, + entity, + BusinessPromoFields.state, + getStateBuilder(), + resultMap); + } + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businesspromo/BusinessPromoRepository.java b/src/main/java/io/kumare/iqr/mod/biz/store/businesspromo/BusinessPromoRepository.java new file mode 100644 index 0000000..8bb1c3e --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businesspromo/BusinessPromoRepository.java @@ -0,0 +1,18 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businesspromo; + +// spring +import org.springframework.stereotype.Repository; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Repository +public interface BusinessPromoRepository extends AppEntityRepository{ + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businesspromo/BusinessPromoStore.java b/src/main/java/io/kumare/iqr/mod/biz/store/businesspromo/BusinessPromoStore.java new file mode 100644 index 0000000..e1a9f59 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businesspromo/BusinessPromoStore.java @@ -0,0 +1,35 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businesspromo; + +// spring +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Service +public class BusinessPromoStore extends AppEntityStore { + + // ::: vars + // + @Autowired + private BusinessPromoRepository repository; + + // ::: override + // + @Override + public BusinessPromoRepository getRepository() { + return repository; + } + + // ::: api + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businesspromoitem/BusinessPromoItemData.java b/src/main/java/io/kumare/iqr/mod/biz/store/businesspromoitem/BusinessPromoItemData.java new file mode 100644 index 0000000..eb04b4d --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businesspromoitem/BusinessPromoItemData.java @@ -0,0 +1,25 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businesspromoitem; + +// base +import io.kumare.iqr.app.store.AppExtendedEntityData; +// imports + + +public class BusinessPromoItemData extends AppExtendedEntityData { + + // ::: vars + // + + + // ::: fields + // + + + // ::: fluent + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businesspromoitem/BusinessPromoItemEntity.java b/src/main/java/io/kumare/iqr/mod/biz/store/businesspromoitem/BusinessPromoItemEntity.java new file mode 100644 index 0000000..2e68118 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businesspromoitem/BusinessPromoItemEntity.java @@ -0,0 +1,155 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businesspromoitem; + +// jakarta +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.Index; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +// base +import io.kumare.lib.app.api.store.*; +import io.kumare.iqr.app.store.*; +// imports + +// relations +import io.kumare.iqr.mod.biz.store.businesspromo.BusinessPromoEntity; +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; +import io.kumare.iqr.mod.biz.store.businessimage.BusinessImageEntity; + +// annotations +@Entity +@Table( + name = "business_promo_item", + indexes = { + @Index(name = "idx_business_promo_item_title", columnList = "title"), + @Index(name = "idx_business_promo_item_description", columnList = "description"), + @Index(name = "idx_business_promo_item_points", columnList = "points"), + @Index(name = "idx_business_promo_item_condition", columnList = "condition") + } +) +public class BusinessPromoItemEntity extends AppEntity { + + // ::: vars + // + private String title; + private String description; + private int points; + private String condition; + // relations + @ManyToOne(fetch = FetchType.LAZY) + private BusinessEntity business; + @ManyToOne(fetch = FetchType.LAZY) + private BusinessPromoEntity promo; + @ManyToOne(fetch = FetchType.LAZY) + private BusinessImageEntity image; + + // ::: constructors + // + public BusinessPromoItemEntity() { + } + + public BusinessPromoItemEntity(String id) { + super(id); + } + + // ::: fields + // + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public int getPoints() { + return points; + } + + public void setPoints(int points) { + this.points = points; + } + + public String getCondition() { + return condition; + } + + public void setCondition(String condition) { + this.condition = condition; + } + + // relations + public BusinessEntity getBusiness() { + return business; + } + + public void setBusiness(BusinessEntity business) { + this.business = business; + } + + public BusinessPromoEntity getPromo() { + return promo; + } + + public void setPromo(BusinessPromoEntity promo) { + this.promo = promo; + } + + public BusinessImageEntity getImage() { + return image; + } + + public void setImage(BusinessImageEntity image) { + this.image = image; + } + + // ::: fluent + // + public BusinessPromoItemEntity title(String title) { + setTitle(title); + return this; + } + + public BusinessPromoItemEntity description(String description) { + setDescription(description); + return this; + } + + public BusinessPromoItemEntity points(int points) { + setPoints(points); + return this; + } + + public BusinessPromoItemEntity condition(String condition) { + setCondition(condition); + return this; + } + + // relations + public BusinessPromoItemEntity business(BusinessEntity business) { + setBusiness(business); + return this; + } + + public BusinessPromoItemEntity promo(BusinessPromoEntity promo) { + setPromo(promo); + return this; + } + + public BusinessPromoItemEntity image(BusinessImageEntity image) { + setImage(image); + return this; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businesspromoitem/BusinessPromoItemFields.java b/src/main/java/io/kumare/iqr/mod/biz/store/businesspromoitem/BusinessPromoItemFields.java new file mode 100644 index 0000000..50c7205 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businesspromoitem/BusinessPromoItemFields.java @@ -0,0 +1,159 @@ +/* + */ +package io.kumare.iqr.mod.biz.store.businesspromoitem; + +// java +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +// base +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app +import io.kumare.iqr.mod.biz.store.BizEntities; +import io.kumare.iqr.mod.biz.store.business.BusinessFields; +import io.kumare.iqr.mod.biz.store.BizEntities; +import io.kumare.iqr.mod.biz.store.businesspromo.BusinessPromoFields; +import io.kumare.iqr.mod.biz.store.BizEntities; +import io.kumare.iqr.mod.biz.store.businessimage.BusinessImageFields; + +/** + * + * @author afatecha + */ +public enum BusinessPromoItemFields implements EntityFieldDescriptor { + + id(MAIN, FIND, LIST), + title(MAIN, FIND, LIST), + description(MAIN, FIND, LIST), + points(MAIN, FIND, LIST), + condition(MAIN, FIND, LIST), + active(MAIN, FIND, LIST), + inserted(AUDIT, FIND, LIST), + inserter(AUDIT, FIND, LIST), + modified(AUDIT, FIND), + modifier(AUDIT, FIND), + deleted(AUDIT), + removed(AUDIT), + remover(AUDIT), + business(BizEntities.business, BusinessFields.class, FIND, LIST), + promo(BizEntities.businessPromo, BusinessPromoFields.class, FIND, LIST), + image(BizEntities.businessImage, BusinessImageFields.class, FIND, LIST); + + // ::: vars + // + private final boolean relation; + private final EntityDescriptor entityDescriptor; + private final Class enumClass; + private final List groups; + + // ::: constructors + // + BusinessPromoItemFields(String... groups) { + this(false, null, null, groups); + } + + BusinessPromoItemFields(EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this(true, entityDescriptor, enumClass, groups); + } + + BusinessPromoItemFields(boolean relation, EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this.relation = relation; + this.entityDescriptor = entityDescriptor; + this.enumClass = enumClass; + this.groups = groups == null ? Collections.EMPTY_LIST : Arrays.asList(groups); + } + + // ::: api + // + @Override + public String getName() { + return name(); + } + + @Override + public boolean isRelation() { + return relation; + } + + @Override + public Class getRelationEnumClass() { + return enumClass; + } + + @Override + public List getGroups() { + return groups; + } + + @Override + public EntityDescriptor getEntityDescriptor() { + return entityDescriptor; + } + + @Override + public Object fetchValue(BusinessPromoItemEntity entity) { + if (entity == null) { + return null; + } + + switch (this) { + case null -> { + return null; + } + case id -> { + return entity.getId(); + } + case title ->{ + return entity.getTitle(); + } + case description ->{ + return entity.getDescription(); + } + case points ->{ + return entity.getPoints(); + } + case condition ->{ + return entity.getCondition(); + } + case active -> { + return entity.isActive(); + } + case inserted -> { + return entity.getInserted(); + } + case inserter -> { + return entity.getInserter(); + } + case modified -> { + return entity.getModified(); + } + case modifier -> { + return entity.getModifier(); + } + case deleted -> { + return entity.isDeleted(); + } + case removed -> { + return entity.getRemoved(); + } + case remover -> { + return entity.getRemover(); + } + case business ->{ + return entity.getBusiness(); + } + case promo ->{ + return entity.getPromo(); + } + case image ->{ + return entity.getImage(); + } + default -> { + return null; + } + } + + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businesspromoitem/BusinessPromoItemMapBuilder.java b/src/main/java/io/kumare/iqr/mod/biz/store/businesspromoitem/BusinessPromoItemMapBuilder.java new file mode 100644 index 0000000..35adcf7 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businesspromoitem/BusinessPromoItemMapBuilder.java @@ -0,0 +1,231 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businesspromoitem; + +// java +import java.util.List; +import java.util.Map; +// base +import io.kumare.lib.app.api.Context; +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.BaseEntityMapBuilder; +// app +import io.kumare.iqr.mod.biz.store.businesspromo.BusinessPromoMapBuilder; +import io.kumare.iqr.mod.biz.store.business.BusinessMapBuilder; +import io.kumare.iqr.mod.biz.store.businessimage.BusinessImageMapBuilder; + +/** + * + * @author afatecha + */ +public class BusinessPromoItemMapBuilder extends BaseEntityMapBuilder { + + // ::: vars + // + private BusinessMapBuilder businessBuilder; + private BusinessPromoMapBuilder promoBuilder; + private BusinessImageMapBuilder imageBuilder; + + + // ::: fields + // + @Override + public BusinessPromoItemMapBuilder addGroup(String name, boolean cascade) { + includes.addAll(EntityFieldDescriptor.group(BusinessPromoItemFields.values(), name)); + + if(cascade) { + if (includes.contains(BusinessPromoItemFields.business)) { + getBusinessBuilder().addGroup(name); + } + if (includes.contains(BusinessPromoItemFields.promo)) { + getPromoBuilder().addGroup(name); + } + if (includes.contains(BusinessPromoItemFields.image)) { + getImageBuilder().addGroup(name); + } + } + return this; + } + + @Override + public BusinessPromoItemMapBuilder add(String fieldName) { + includes.add(BusinessPromoItemFields.valueOf(fieldName)); + return this; + } + + @Override + public BusinessPromoItemMapBuilder addAll(String... names) { + for (var i : names) { + includes.add(BusinessPromoItemFields.valueOf(i)); + } + return this; + } + + @Override + public BusinessPromoItemMapBuilder remove(String fieldName) { + excludes.add(BusinessPromoItemFields.valueOf(fieldName)); + return this; + } + + @Override + public BusinessPromoItemMapBuilder removeAll(String... names) { + for (var i : names) { + excludes.add(BusinessPromoItemFields.valueOf(i)); + } + return this; + } + + // ::: relations + // + @Override + public BusinessPromoItemMapBuilder addPlains(boolean cascade) { + includes.addAll(EntityFieldDescriptor.plains(BusinessPromoItemFields.values())); + + if(cascade) { + if (includes.contains(BusinessPromoItemFields.business)) { + getBusinessBuilder().addPlains(); + } + if (includes.contains(BusinessPromoItemFields.promo)) { + getPromoBuilder().addPlains(); + } + if (includes.contains(BusinessPromoItemFields.image)) { + getImageBuilder().addPlains(); + } + } + return this; + } + + @Override + public BusinessPromoItemMapBuilder addRelations(boolean cascade) { + includes.addAll(EntityFieldDescriptor.relations(BusinessPromoItemFields.values())); + + if(cascade) { + if (includes.contains(BusinessPromoItemFields.business)) { + getBusinessBuilder().addRelations(); + } + if (includes.contains(BusinessPromoItemFields.promo)) { + getPromoBuilder().addRelations(); + } + if (includes.contains(BusinessPromoItemFields.image)) { + getImageBuilder().addRelations(); + } + } + return this; + } + + // ::: business + // + public BusinessPromoItemMapBuilder addBusiness() { + return addBusiness(null); + } + + public BusinessPromoItemMapBuilder addBusiness(String group) { + return addBusiness(group, false); + } + + public BusinessPromoItemMapBuilder addBusiness(String group, boolean cascade) { + includes.add(BusinessPromoItemFields.business); + + if (group != null) { + getBusinessBuilder().addGroup(group); + } + + return this; + } + + public BusinessMapBuilder getBusinessBuilder() { + if(businessBuilder == null) { + businessBuilder = new BusinessMapBuilder(); + } + return businessBuilder; + } + + + // ::: promo + // + public BusinessPromoItemMapBuilder addPromo() { + return addPromo(null); + } + + public BusinessPromoItemMapBuilder addPromo(String group) { + return addPromo(group, false); + } + + public BusinessPromoItemMapBuilder addPromo(String group, boolean cascade) { + includes.add(BusinessPromoItemFields.promo); + + if (group != null) { + getPromoBuilder().addGroup(group); + } + + return this; + } + + public BusinessPromoMapBuilder getPromoBuilder() { + if(promoBuilder == null) { + promoBuilder = new BusinessPromoMapBuilder(); + } + return promoBuilder; + } + + + // ::: image + // + public BusinessPromoItemMapBuilder addImage() { + return addImage(null); + } + + public BusinessPromoItemMapBuilder addImage(String group) { + return addImage(group, false); + } + + public BusinessPromoItemMapBuilder addImage(String group, boolean cascade) { + includes.add(BusinessPromoItemFields.image); + + if (group != null) { + getImageBuilder().addGroup(group); + } + + return this; + } + + public BusinessImageMapBuilder getImageBuilder() { + if(imageBuilder == null) { + imageBuilder = new BusinessImageMapBuilder(); + } + return imageBuilder; + } + + // ::: internals + // + @Override + protected void internalAttachRelations(Context context, + BusinessPromoItemEntity entity, + List fields, + Map resultMap) { + + if (fields.contains(BusinessPromoItemFields.business)) { + attachRelation(context, + entity, + BusinessPromoItemFields.business, + getBusinessBuilder(), + resultMap); + } + if (fields.contains(BusinessPromoItemFields.promo)) { + attachRelation(context, + entity, + BusinessPromoItemFields.promo, + getPromoBuilder(), + resultMap); + } + if (fields.contains(BusinessPromoItemFields.image)) { + attachRelation(context, + entity, + BusinessPromoItemFields.image, + getImageBuilder(), + resultMap); + } + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businesspromoitem/BusinessPromoItemRepository.java b/src/main/java/io/kumare/iqr/mod/biz/store/businesspromoitem/BusinessPromoItemRepository.java new file mode 100644 index 0000000..4a5158c --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businesspromoitem/BusinessPromoItemRepository.java @@ -0,0 +1,18 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businesspromoitem; + +// spring +import org.springframework.stereotype.Repository; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Repository +public interface BusinessPromoItemRepository extends AppEntityRepository{ + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businesspromoitem/BusinessPromoItemStore.java b/src/main/java/io/kumare/iqr/mod/biz/store/businesspromoitem/BusinessPromoItemStore.java new file mode 100644 index 0000000..610ab86 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businesspromoitem/BusinessPromoItemStore.java @@ -0,0 +1,35 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businesspromoitem; + +// spring +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Service +public class BusinessPromoItemStore extends AppEntityStore { + + // ::: vars + // + @Autowired + private BusinessPromoItemRepository repository; + + // ::: override + // + @Override + public BusinessPromoItemRepository getRepository() { + return repository; + } + + // ::: api + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businesssetting/BusinessSettingData.java b/src/main/java/io/kumare/iqr/mod/biz/store/businesssetting/BusinessSettingData.java new file mode 100644 index 0000000..85c60ee --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businesssetting/BusinessSettingData.java @@ -0,0 +1,25 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businesssetting; + +// base +import io.kumare.iqr.app.store.AppExtendedEntityData; +// imports + + +public class BusinessSettingData extends AppExtendedEntityData { + + // ::: vars + // + + + // ::: fields + // + + + // ::: fluent + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businesssetting/BusinessSettingEntity.java b/src/main/java/io/kumare/iqr/mod/biz/store/businesssetting/BusinessSettingEntity.java new file mode 100644 index 0000000..11cdfd8 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businesssetting/BusinessSettingEntity.java @@ -0,0 +1,108 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businesssetting; + +// jakarta +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.Index; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +// base +import io.kumare.lib.app.api.store.*; +import io.kumare.iqr.app.store.*; +// imports + +// relations +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; + +// annotations +@Entity +@Table( + name = "business_setting", + indexes = { + @Index(name = "idx_business_setting_point_exchange", columnList = "pointExchange"), + @Index(name = "idx_business_setting_lead_capture_reward", columnList = "leadCaptureReward"), + @Index(name = "idx_business_setting_customer_capture_reward", columnList = "customerCaptureReward") + } +) +public class BusinessSettingEntity extends AppEntity { + + // ::: vars + // + private int pointExchange; + private int leadCaptureReward; + private int customerCaptureReward; + // relations + @ManyToOne(fetch = FetchType.LAZY) + private BusinessEntity business; + + // ::: constructors + // + public BusinessSettingEntity() { + } + + public BusinessSettingEntity(String id) { + super(id); + } + + // ::: fields + // + public int getPointExchange() { + return pointExchange; + } + + public void setPointExchange(int pointExchange) { + this.pointExchange = pointExchange; + } + + public int getLeadCaptureReward() { + return leadCaptureReward; + } + + public void setLeadCaptureReward(int leadCaptureReward) { + this.leadCaptureReward = leadCaptureReward; + } + + public int getCustomerCaptureReward() { + return customerCaptureReward; + } + + public void setCustomerCaptureReward(int customerCaptureReward) { + this.customerCaptureReward = customerCaptureReward; + } + + // relations + public BusinessEntity getBusiness() { + return business; + } + + public void setBusiness(BusinessEntity business) { + this.business = business; + } + + // ::: fluent + // + public BusinessSettingEntity pointExchange(int pointExchange) { + setPointExchange(pointExchange); + return this; + } + + public BusinessSettingEntity leadCaptureReward(int leadCaptureReward) { + setLeadCaptureReward(leadCaptureReward); + return this; + } + + public BusinessSettingEntity customerCaptureReward(int customerCaptureReward) { + setCustomerCaptureReward(customerCaptureReward); + return this; + } + + // relations + public BusinessSettingEntity business(BusinessEntity business) { + setBusiness(business); + return this; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businesssetting/BusinessSettingFields.java b/src/main/java/io/kumare/iqr/mod/biz/store/businesssetting/BusinessSettingFields.java new file mode 100644 index 0000000..dc7fbc8 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businesssetting/BusinessSettingFields.java @@ -0,0 +1,143 @@ +/* + */ +package io.kumare.iqr.mod.biz.store.businesssetting; + +// java +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +// base +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app +import io.kumare.iqr.mod.biz.store.BizEntities; +import io.kumare.iqr.mod.biz.store.business.BusinessFields; + +/** + * + * @author afatecha + */ +public enum BusinessSettingFields implements EntityFieldDescriptor { + + id(MAIN, FIND, LIST), + pointExchange(MAIN, FIND, LIST), + leadCaptureReward(MAIN, FIND, LIST), + customerCaptureReward(MAIN, FIND, LIST), + active(MAIN, FIND, LIST), + inserted(AUDIT, FIND, LIST), + inserter(AUDIT, FIND, LIST), + modified(AUDIT, FIND), + modifier(AUDIT, FIND), + deleted(AUDIT), + removed(AUDIT), + remover(AUDIT), + business(BizEntities.business, BusinessFields.class, FIND, LIST); + + // ::: vars + // + private final boolean relation; + private final EntityDescriptor entityDescriptor; + private final Class enumClass; + private final List groups; + + // ::: constructors + // + BusinessSettingFields(String... groups) { + this(false, null, null, groups); + } + + BusinessSettingFields(EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this(true, entityDescriptor, enumClass, groups); + } + + BusinessSettingFields(boolean relation, EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this.relation = relation; + this.entityDescriptor = entityDescriptor; + this.enumClass = enumClass; + this.groups = groups == null ? Collections.EMPTY_LIST : Arrays.asList(groups); + } + + // ::: api + // + @Override + public String getName() { + return name(); + } + + @Override + public boolean isRelation() { + return relation; + } + + @Override + public Class getRelationEnumClass() { + return enumClass; + } + + @Override + public List getGroups() { + return groups; + } + + @Override + public EntityDescriptor getEntityDescriptor() { + return entityDescriptor; + } + + @Override + public Object fetchValue(BusinessSettingEntity entity) { + if (entity == null) { + return null; + } + + switch (this) { + case null -> { + return null; + } + case id -> { + return entity.getId(); + } + case pointExchange ->{ + return entity.getPointExchange(); + } + case leadCaptureReward ->{ + return entity.getLeadCaptureReward(); + } + case customerCaptureReward ->{ + return entity.getCustomerCaptureReward(); + } + case active -> { + return entity.isActive(); + } + case inserted -> { + return entity.getInserted(); + } + case inserter -> { + return entity.getInserter(); + } + case modified -> { + return entity.getModified(); + } + case modifier -> { + return entity.getModifier(); + } + case deleted -> { + return entity.isDeleted(); + } + case removed -> { + return entity.getRemoved(); + } + case remover -> { + return entity.getRemover(); + } + case business ->{ + return entity.getBusiness(); + } + default -> { + return null; + } + } + + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businesssetting/BusinessSettingMapBuilder.java b/src/main/java/io/kumare/iqr/mod/biz/store/businesssetting/BusinessSettingMapBuilder.java new file mode 100644 index 0000000..0e35e31 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businesssetting/BusinessSettingMapBuilder.java @@ -0,0 +1,139 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businesssetting; + +// java +import java.util.List; +import java.util.Map; +// base +import io.kumare.lib.app.api.Context; +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.BaseEntityMapBuilder; +// app +import io.kumare.iqr.mod.biz.store.business.BusinessMapBuilder; + +/** + * + * @author afatecha + */ +public class BusinessSettingMapBuilder extends BaseEntityMapBuilder { + + // ::: vars + // + private BusinessMapBuilder businessBuilder; + + + // ::: fields + // + @Override + public BusinessSettingMapBuilder addGroup(String name, boolean cascade) { + includes.addAll(EntityFieldDescriptor.group(BusinessSettingFields.values(), name)); + + if(cascade) { + if (includes.contains(BusinessSettingFields.business)) { + getBusinessBuilder().addGroup(name); + } + } + return this; + } + + @Override + public BusinessSettingMapBuilder add(String fieldName) { + includes.add(BusinessSettingFields.valueOf(fieldName)); + return this; + } + + @Override + public BusinessSettingMapBuilder addAll(String... names) { + for (var i : names) { + includes.add(BusinessSettingFields.valueOf(i)); + } + return this; + } + + @Override + public BusinessSettingMapBuilder remove(String fieldName) { + excludes.add(BusinessSettingFields.valueOf(fieldName)); + return this; + } + + @Override + public BusinessSettingMapBuilder removeAll(String... names) { + for (var i : names) { + excludes.add(BusinessSettingFields.valueOf(i)); + } + return this; + } + + // ::: relations + // + @Override + public BusinessSettingMapBuilder addPlains(boolean cascade) { + includes.addAll(EntityFieldDescriptor.plains(BusinessSettingFields.values())); + + if(cascade) { + if (includes.contains(BusinessSettingFields.business)) { + getBusinessBuilder().addPlains(); + } + } + return this; + } + + @Override + public BusinessSettingMapBuilder addRelations(boolean cascade) { + includes.addAll(EntityFieldDescriptor.relations(BusinessSettingFields.values())); + + if(cascade) { + if (includes.contains(BusinessSettingFields.business)) { + getBusinessBuilder().addRelations(); + } + } + return this; + } + + // ::: business + // + public BusinessSettingMapBuilder addBusiness() { + return addBusiness(null); + } + + public BusinessSettingMapBuilder addBusiness(String group) { + return addBusiness(group, false); + } + + public BusinessSettingMapBuilder addBusiness(String group, boolean cascade) { + includes.add(BusinessSettingFields.business); + + if (group != null) { + getBusinessBuilder().addGroup(group); + } + + return this; + } + + public BusinessMapBuilder getBusinessBuilder() { + if(businessBuilder == null) { + businessBuilder = new BusinessMapBuilder(); + } + return businessBuilder; + } + + // ::: internals + // + @Override + protected void internalAttachRelations(Context context, + BusinessSettingEntity entity, + List fields, + Map resultMap) { + + if (fields.contains(BusinessSettingFields.business)) { + attachRelation(context, + entity, + BusinessSettingFields.business, + getBusinessBuilder(), + resultMap); + } + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businesssetting/BusinessSettingRepository.java b/src/main/java/io/kumare/iqr/mod/biz/store/businesssetting/BusinessSettingRepository.java new file mode 100644 index 0000000..54164c5 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businesssetting/BusinessSettingRepository.java @@ -0,0 +1,18 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businesssetting; + +// spring +import org.springframework.stereotype.Repository; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Repository +public interface BusinessSettingRepository extends AppEntityRepository{ + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businesssetting/BusinessSettingStore.java b/src/main/java/io/kumare/iqr/mod/biz/store/businesssetting/BusinessSettingStore.java new file mode 100644 index 0000000..789d7d9 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businesssetting/BusinessSettingStore.java @@ -0,0 +1,35 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businesssetting; + +// spring +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Service +public class BusinessSettingStore extends AppEntityStore { + + // ::: vars + // + @Autowired + private BusinessSettingRepository repository; + + // ::: override + // + @Override + public BusinessSettingRepository getRepository() { + return repository; + } + + // ::: api + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businesstag/BusinessTagData.java b/src/main/java/io/kumare/iqr/mod/biz/store/businesstag/BusinessTagData.java new file mode 100644 index 0000000..e71b32a --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businesstag/BusinessTagData.java @@ -0,0 +1,25 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businesstag; + +// base +import io.kumare.iqr.app.store.AppExtendedEntityData; +// imports + + +public class BusinessTagData extends AppExtendedEntityData { + + // ::: vars + // + + + // ::: fields + // + + + // ::: fluent + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businesstag/BusinessTagEntity.java b/src/main/java/io/kumare/iqr/mod/biz/store/businesstag/BusinessTagEntity.java new file mode 100644 index 0000000..9fe6f51 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businesstag/BusinessTagEntity.java @@ -0,0 +1,83 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businesstag; + +// jakarta +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.Index; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +// base +import io.kumare.lib.app.api.store.*; +import io.kumare.iqr.app.store.*; +// imports + +// relations + + +// annotations +@Entity +@Table( + name = "business_tag", + indexes = { + @Index(name = "idx_business_tag_entity_key", columnList = "entityKey"), + @Index(name = "idx_business_tag_name", columnList = "name") + } +) +public class BusinessTagEntity extends AppEntity implements SupportedEntityKey { + + // ::: vars + // + private String entityKey; + private String name; + // relations + + + // ::: constructors + // + public BusinessTagEntity() { + } + + public BusinessTagEntity(String id) { + super(id); + } + + // ::: fields + // + public String getEntityKey() { + return entityKey; + } + + public void setEntityKey(String entityKey) { + this.entityKey = entityKey; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + // relations + + + // ::: fluent + // + public BusinessTagEntity entityKey(String entityKey) { + setEntityKey(entityKey); + return this; + } + + public BusinessTagEntity name(String name) { + setName(name); + return this; + } + + // relations + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businesstag/BusinessTagFields.java b/src/main/java/io/kumare/iqr/mod/biz/store/businesstag/BusinessTagFields.java new file mode 100644 index 0000000..d4b21d0 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businesstag/BusinessTagFields.java @@ -0,0 +1,135 @@ +/* + */ +package io.kumare.iqr.mod.biz.store.businesstag; + +// java +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +// base +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app + + +/** + * + * @author afatecha + */ +public enum BusinessTagFields implements EntityFieldDescriptor { + + id(MAIN, FIND, LIST), + entityKey(MAIN, FIND, LIST), + name(MAIN, FIND, LIST), + active(MAIN, FIND, LIST), + inserted(AUDIT, FIND, LIST), + inserter(AUDIT, FIND, LIST), + modified(AUDIT, FIND), + modifier(AUDIT, FIND), + deleted(AUDIT), + removed(AUDIT), + remover(AUDIT); + + // ::: vars + // + private final boolean relation; + private final EntityDescriptor entityDescriptor; + private final Class enumClass; + private final List groups; + + // ::: constructors + // + BusinessTagFields(String... groups) { + this(false, null, null, groups); + } + + BusinessTagFields(EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this(true, entityDescriptor, enumClass, groups); + } + + BusinessTagFields(boolean relation, EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this.relation = relation; + this.entityDescriptor = entityDescriptor; + this.enumClass = enumClass; + this.groups = groups == null ? Collections.EMPTY_LIST : Arrays.asList(groups); + } + + // ::: api + // + @Override + public String getName() { + return name(); + } + + @Override + public boolean isRelation() { + return relation; + } + + @Override + public Class getRelationEnumClass() { + return enumClass; + } + + @Override + public List getGroups() { + return groups; + } + + @Override + public EntityDescriptor getEntityDescriptor() { + return entityDescriptor; + } + + @Override + public Object fetchValue(BusinessTagEntity entity) { + if (entity == null) { + return null; + } + + switch (this) { + case null -> { + return null; + } + case id -> { + return entity.getId(); + } + case entityKey ->{ + return entity.getEntityKey(); + } + case name ->{ + return entity.getName(); + } + case active -> { + return entity.isActive(); + } + case inserted -> { + return entity.getInserted(); + } + case inserter -> { + return entity.getInserter(); + } + case modified -> { + return entity.getModified(); + } + case modifier -> { + return entity.getModifier(); + } + case deleted -> { + return entity.isDeleted(); + } + case removed -> { + return entity.getRemoved(); + } + case remover -> { + return entity.getRemover(); + } + + default -> { + return null; + } + } + + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businesstag/BusinessTagMapBuilder.java b/src/main/java/io/kumare/iqr/mod/biz/store/businesstag/BusinessTagMapBuilder.java new file mode 100644 index 0000000..6a29eb7 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businesstag/BusinessTagMapBuilder.java @@ -0,0 +1,93 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businesstag; + +// java +import java.util.List; +import java.util.Map; +// base +import io.kumare.lib.app.api.Context; +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.BaseEntityMapBuilder; +// app + + +/** + * + * @author afatecha + */ +public class BusinessTagMapBuilder extends BaseEntityMapBuilder { + + // ::: vars + // + + + + // ::: fields + // + @Override + public BusinessTagMapBuilder addGroup(String name, boolean cascade) { + includes.addAll(EntityFieldDescriptor.group(BusinessTagFields.values(), name)); + + return this; + } + + @Override + public BusinessTagMapBuilder add(String fieldName) { + includes.add(BusinessTagFields.valueOf(fieldName)); + return this; + } + + @Override + public BusinessTagMapBuilder addAll(String... names) { + for (var i : names) { + includes.add(BusinessTagFields.valueOf(i)); + } + return this; + } + + @Override + public BusinessTagMapBuilder remove(String fieldName) { + excludes.add(BusinessTagFields.valueOf(fieldName)); + return this; + } + + @Override + public BusinessTagMapBuilder removeAll(String... names) { + for (var i : names) { + excludes.add(BusinessTagFields.valueOf(i)); + } + return this; + } + + // ::: relations + // + @Override + public BusinessTagMapBuilder addPlains(boolean cascade) { + includes.addAll(EntityFieldDescriptor.plains(BusinessTagFields.values())); + + return this; + } + + @Override + public BusinessTagMapBuilder addRelations(boolean cascade) { + includes.addAll(EntityFieldDescriptor.relations(BusinessTagFields.values())); + + return this; + } + + + + // ::: internals + // + @Override + protected void internalAttachRelations(Context context, + BusinessTagEntity entity, + List fields, + Map resultMap) { + + + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businesstag/BusinessTagRepository.java b/src/main/java/io/kumare/iqr/mod/biz/store/businesstag/BusinessTagRepository.java new file mode 100644 index 0000000..b242ef1 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businesstag/BusinessTagRepository.java @@ -0,0 +1,18 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businesstag; + +// spring +import org.springframework.stereotype.Repository; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Repository +public interface BusinessTagRepository extends AppKeyEntityRepository{ + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businesstag/BusinessTagStore.java b/src/main/java/io/kumare/iqr/mod/biz/store/businesstag/BusinessTagStore.java new file mode 100644 index 0000000..a8d272e --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businesstag/BusinessTagStore.java @@ -0,0 +1,35 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businesstag; + +// spring +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Service +public class BusinessTagStore extends AppKeyEntityStore { + + // ::: vars + // + @Autowired + private BusinessTagRepository repository; + + // ::: override + // + @Override + public BusinessTagRepository getRepository() { + return repository; + } + + // ::: api + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businessworker/BusinessWorkerData.java b/src/main/java/io/kumare/iqr/mod/biz/store/businessworker/BusinessWorkerData.java new file mode 100644 index 0000000..be5e7f4 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businessworker/BusinessWorkerData.java @@ -0,0 +1,25 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businessworker; + +// base +import io.kumare.iqr.app.store.AppExtendedEntityData; +// imports + + +public class BusinessWorkerData extends AppExtendedEntityData { + + // ::: vars + // + + + // ::: fields + // + + + // ::: fluent + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businessworker/BusinessWorkerEntity.java b/src/main/java/io/kumare/iqr/mod/biz/store/businessworker/BusinessWorkerEntity.java new file mode 100644 index 0000000..39d84c6 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businessworker/BusinessWorkerEntity.java @@ -0,0 +1,201 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businessworker; + +// jakarta +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.Index; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +// base +import io.kumare.lib.app.api.store.*; +import io.kumare.iqr.app.store.*; +// imports + +// relations +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; + +// annotations +@Entity +@Table( + name = "business_worker", + indexes = { + @Index(name = "idx_business_worker_entity_key", columnList = "entityKey"), + @Index(name = "idx_business_worker_role_value", columnList = "roleValue"), + @Index(name = "idx_business_worker_state_value", columnList = "stateValue"), + @Index(name = "idx_business_worker_email", columnList = "email"), + @Index(name = "idx_business_worker_phone", columnList = "phone"), + @Index(name = "idx_business_worker_name", columnList = "name"), + @Index(name = "idx_business_worker_description", columnList = "description") + } +) +public class BusinessWorkerEntity extends AppEntity implements SupportedEntityKey { + + // ::: vars + // + private String entityKey; + private String roleValue; + private String stateValue; + private String email; + private String phone; + private String name; + private String description; + // relations + @ManyToOne(fetch = FetchType.LAZY) + private BusinessEntity business; + @ManyToOne(fetch = FetchType.LAZY) + private TaxonEntity role; + @ManyToOne(fetch = FetchType.LAZY) + private TaxonEntity state; + + // ::: constructors + // + public BusinessWorkerEntity() { + } + + public BusinessWorkerEntity(String id) { + super(id); + } + + // ::: fields + // + @Override + public String getEntityKey() { + return entityKey; + } + + @Override + public void setEntityKey(String entityKey) { + this.entityKey = entityKey; + } + + public String getRoleValue() { + return roleValue; + } + + public void setRoleValue(String roleValue) { + this.roleValue = roleValue; + } + + public String getStateValue() { + return stateValue; + } + + public void setStateValue(String stateValue) { + this.stateValue = stateValue; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + // relations + public BusinessEntity getBusiness() { + return business; + } + + public void setBusiness(BusinessEntity business) { + this.business = business; + } + + public TaxonEntity getRole() { + return role; + } + + public void setRole(TaxonEntity role) { + this.role = role; + } + + public TaxonEntity getState() { + return state; + } + + public void setState(TaxonEntity state) { + this.state = state; + } + + // ::: fluent + // + public BusinessWorkerEntity entityKey(String entityKey) { + setEntityKey(entityKey); + return this; + } + + public BusinessWorkerEntity roleValue(String roleValue) { + setRoleValue(roleValue); + return this; + } + + public BusinessWorkerEntity stateValue(String stateValue) { + setStateValue(stateValue); + return this; + } + + public BusinessWorkerEntity email(String email) { + setEmail(email); + return this; + } + + public BusinessWorkerEntity phone(String phone) { + setPhone(phone); + return this; + } + + public BusinessWorkerEntity name(String name) { + setName(name); + return this; + } + + public BusinessWorkerEntity description(String description) { + setDescription(description); + return this; + } + + // relations + public BusinessWorkerEntity business(BusinessEntity business) { + setBusiness(business); + return this; + } + + public BusinessWorkerEntity role(TaxonEntity role) { + setRole(role); + return this; + } + + public BusinessWorkerEntity state(TaxonEntity state) { + setState(state); + return this; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businessworker/BusinessWorkerFields.java b/src/main/java/io/kumare/iqr/mod/biz/store/businessworker/BusinessWorkerFields.java new file mode 100644 index 0000000..e901749 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businessworker/BusinessWorkerFields.java @@ -0,0 +1,169 @@ +/* + */ +package io.kumare.iqr.mod.biz.store.businessworker; + +// java +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +// base +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app +import io.kumare.iqr.mod.biz.store.BizEntities; +import io.kumare.iqr.mod.biz.store.business.BusinessFields; +import io.kumare.iqr.mod.taxonomy.store.TaxonomyEntities; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonFields; + +/** + * + * @author afatecha + */ +public enum BusinessWorkerFields implements EntityFieldDescriptor { + + id(MAIN, FIND, LIST), + entityKey(MAIN, FIND, LIST), + roleValue(MAIN, FIND, LIST), + stateValue(MAIN, FIND, LIST), + email(MAIN, FIND, LIST), + phone(MAIN, FIND, LIST), + name(MAIN, FIND, LIST), + description(MAIN, FIND, LIST), + active(MAIN, FIND, LIST), + inserted(AUDIT, FIND, LIST), + inserter(AUDIT, FIND, LIST), + modified(AUDIT, FIND), + modifier(AUDIT, FIND), + deleted(AUDIT), + removed(AUDIT), + remover(AUDIT), + business(BizEntities.business, BusinessFields.class, FIND, LIST), + role(TaxonomyEntities.taxon, TaxonFields.class, FIND, LIST), + state(TaxonomyEntities.taxon, TaxonFields.class, FIND, LIST); + + // ::: vars + // + private final boolean relation; + private final EntityDescriptor entityDescriptor; + private final Class enumClass; + private final List groups; + + // ::: constructors + // + BusinessWorkerFields(String... groups) { + this(false, null, null, groups); + } + + BusinessWorkerFields(EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this(true, entityDescriptor, enumClass, groups); + } + + BusinessWorkerFields(boolean relation, EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this.relation = relation; + this.entityDescriptor = entityDescriptor; + this.enumClass = enumClass; + this.groups = groups == null ? Collections.EMPTY_LIST : Arrays.asList(groups); + } + + // ::: api + // + @Override + public String getName() { + return name(); + } + + @Override + public boolean isRelation() { + return relation; + } + + @Override + public Class getRelationEnumClass() { + return enumClass; + } + + @Override + public List getGroups() { + return groups; + } + + @Override + public EntityDescriptor getEntityDescriptor() { + return entityDescriptor; + } + + @Override + public Object fetchValue(BusinessWorkerEntity entity) { + if (entity == null) { + return null; + } + + switch (this) { + case null -> { + return null; + } + case id -> { + return entity.getId(); + } + case entityKey ->{ + return entity.getEntityKey(); + } + case roleValue ->{ + return entity.getRoleValue(); + } + case stateValue ->{ + return entity.getStateValue(); + } + case email ->{ + return entity.getEmail(); + } + case phone ->{ + return entity.getPhone(); + } + case name ->{ + return entity.getName(); + } + case description ->{ + return entity.getDescription(); + } + case active -> { + return entity.isActive(); + } + case inserted -> { + return entity.getInserted(); + } + case inserter -> { + return entity.getInserter(); + } + case modified -> { + return entity.getModified(); + } + case modifier -> { + return entity.getModifier(); + } + case deleted -> { + return entity.isDeleted(); + } + case removed -> { + return entity.getRemoved(); + } + case remover -> { + return entity.getRemover(); + } + case business ->{ + return entity.getBusiness(); + } + case role ->{ + return entity.getRole(); + } + case state ->{ + return entity.getState(); + } + default -> { + return null; + } + } + + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businessworker/BusinessWorkerMapBuilder.java b/src/main/java/io/kumare/iqr/mod/biz/store/businessworker/BusinessWorkerMapBuilder.java new file mode 100644 index 0000000..5aec430 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businessworker/BusinessWorkerMapBuilder.java @@ -0,0 +1,230 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businessworker; + +// java +import java.util.List; +import java.util.Map; +// base +import io.kumare.lib.app.api.Context; +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.BaseEntityMapBuilder; +// app +import io.kumare.iqr.mod.biz.store.business.BusinessMapBuilder; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonMapBuilder; + +/** + * + * @author afatecha + */ +public class BusinessWorkerMapBuilder extends BaseEntityMapBuilder { + + // ::: vars + // + private BusinessMapBuilder businessBuilder; + private TaxonMapBuilder roleBuilder; + private TaxonMapBuilder stateBuilder; + + + // ::: fields + // + @Override + public BusinessWorkerMapBuilder addGroup(String name, boolean cascade) { + includes.addAll(EntityFieldDescriptor.group(BusinessWorkerFields.values(), name)); + + if(cascade) { + if (includes.contains(BusinessWorkerFields.business)) { + getBusinessBuilder().addGroup(name); + } + if (includes.contains(BusinessWorkerFields.role)) { + getRoleBuilder().addGroup(name); + } + if (includes.contains(BusinessWorkerFields.state)) { + getStateBuilder().addGroup(name); + } + } + return this; + } + + @Override + public BusinessWorkerMapBuilder add(String fieldName) { + includes.add(BusinessWorkerFields.valueOf(fieldName)); + return this; + } + + @Override + public BusinessWorkerMapBuilder addAll(String... names) { + for (var i : names) { + includes.add(BusinessWorkerFields.valueOf(i)); + } + return this; + } + + @Override + public BusinessWorkerMapBuilder remove(String fieldName) { + excludes.add(BusinessWorkerFields.valueOf(fieldName)); + return this; + } + + @Override + public BusinessWorkerMapBuilder removeAll(String... names) { + for (var i : names) { + excludes.add(BusinessWorkerFields.valueOf(i)); + } + return this; + } + + // ::: relations + // + @Override + public BusinessWorkerMapBuilder addPlains(boolean cascade) { + includes.addAll(EntityFieldDescriptor.plains(BusinessWorkerFields.values())); + + if(cascade) { + if (includes.contains(BusinessWorkerFields.business)) { + getBusinessBuilder().addPlains(); + } + if (includes.contains(BusinessWorkerFields.role)) { + getRoleBuilder().addPlains(); + } + if (includes.contains(BusinessWorkerFields.state)) { + getStateBuilder().addPlains(); + } + } + return this; + } + + @Override + public BusinessWorkerMapBuilder addRelations(boolean cascade) { + includes.addAll(EntityFieldDescriptor.relations(BusinessWorkerFields.values())); + + if(cascade) { + if (includes.contains(BusinessWorkerFields.business)) { + getBusinessBuilder().addRelations(); + } + if (includes.contains(BusinessWorkerFields.role)) { + getRoleBuilder().addRelations(); + } + if (includes.contains(BusinessWorkerFields.state)) { + getStateBuilder().addRelations(); + } + } + return this; + } + + // ::: business + // + public BusinessWorkerMapBuilder addBusiness() { + return addBusiness(null); + } + + public BusinessWorkerMapBuilder addBusiness(String group) { + return addBusiness(group, false); + } + + public BusinessWorkerMapBuilder addBusiness(String group, boolean cascade) { + includes.add(BusinessWorkerFields.business); + + if (group != null) { + getBusinessBuilder().addGroup(group); + } + + return this; + } + + public BusinessMapBuilder getBusinessBuilder() { + if(businessBuilder == null) { + businessBuilder = new BusinessMapBuilder(); + } + return businessBuilder; + } + + + // ::: role + // + public BusinessWorkerMapBuilder addRole() { + return addRole(null); + } + + public BusinessWorkerMapBuilder addRole(String group) { + return addRole(group, false); + } + + public BusinessWorkerMapBuilder addRole(String group, boolean cascade) { + includes.add(BusinessWorkerFields.role); + + if (group != null) { + getRoleBuilder().addGroup(group); + } + + return this; + } + + public TaxonMapBuilder getRoleBuilder() { + if(roleBuilder == null) { + roleBuilder = new TaxonMapBuilder(); + } + return roleBuilder; + } + + + // ::: state + // + public BusinessWorkerMapBuilder addState() { + return addState(null); + } + + public BusinessWorkerMapBuilder addState(String group) { + return addState(group, false); + } + + public BusinessWorkerMapBuilder addState(String group, boolean cascade) { + includes.add(BusinessWorkerFields.state); + + if (group != null) { + getStateBuilder().addGroup(group); + } + + return this; + } + + public TaxonMapBuilder getStateBuilder() { + if(stateBuilder == null) { + stateBuilder = new TaxonMapBuilder(); + } + return stateBuilder; + } + + // ::: internals + // + @Override + protected void internalAttachRelations(Context context, + BusinessWorkerEntity entity, + List fields, + Map resultMap) { + + if (fields.contains(BusinessWorkerFields.business)) { + attachRelation(context, + entity, + BusinessWorkerFields.business, + getBusinessBuilder(), + resultMap); + } + if (fields.contains(BusinessWorkerFields.role)) { + attachRelation(context, + entity, + BusinessWorkerFields.role, + getRoleBuilder(), + resultMap); + } + if (fields.contains(BusinessWorkerFields.state)) { + attachRelation(context, + entity, + BusinessWorkerFields.state, + getStateBuilder(), + resultMap); + } + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businessworker/BusinessWorkerRepository.java b/src/main/java/io/kumare/iqr/mod/biz/store/businessworker/BusinessWorkerRepository.java new file mode 100644 index 0000000..8f0be63 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businessworker/BusinessWorkerRepository.java @@ -0,0 +1,18 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businessworker; + +// spring +import org.springframework.stereotype.Repository; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Repository +public interface BusinessWorkerRepository extends AppKeyEntityRepository{ + +} diff --git a/src/main/java/io/kumare/iqr/mod/biz/store/businessworker/BusinessWorkerStore.java b/src/main/java/io/kumare/iqr/mod/biz/store/businessworker/BusinessWorkerStore.java new file mode 100644 index 0000000..7be4db3 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/biz/store/businessworker/BusinessWorkerStore.java @@ -0,0 +1,35 @@ +/* + * + */ +package io.kumare.iqr.mod.biz.store.businessworker; + +// spring +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Service +public class BusinessWorkerStore extends AppKeyEntityStore { + + // ::: vars + // + @Autowired + private BusinessWorkerRepository repository; + + // ::: override + // + @Override + public BusinessWorkerRepository getRepository() { + return repository; + } + + // ::: api + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/ClienteleConstants.java b/src/main/java/io/kumare/iqr/mod/clientele/ClienteleConstants.java new file mode 100644 index 0000000..ccdff2e --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/ClienteleConstants.java @@ -0,0 +1,20 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele; + +// base +import io.kumare.iqr.app.AppConstants; + +/** + * + * @author afatecha + */ +public class ClienteleConstants { + + // ::: codes + // + public static final int CODE = AppConstants.CLIENTELE_CODE; + public static final String NAME = "clientele"; + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/ClienteleController.java b/src/main/java/io/kumare/iqr/mod/clientele/ClienteleController.java new file mode 100644 index 0000000..8730578 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/ClienteleController.java @@ -0,0 +1,57 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele; + +// java +import io.kumare.iqr.mod.clientele.store.ClienteleEntities; +import java.util.Arrays; +import java.util.List; +// base +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app +import io.kumare.iqr.app.module.AppModuleController; +// module +import io.kumare.iqr.mod.clientele.store.client.ClientStore; +import io.kumare.iqr.mod.clientele.store.clientrelation.ClientRelationStore; + +/** + * + * @author afatecha + */ +public class ClienteleController extends AppModuleController { + + // ::: api + // + @Override + public boolean hasStore(String name) { + return ClienteleEntities.hasDescriptor(name); + } + + @Override + public EntityDescriptor getEntityDescriptor(Class entityClass) { + return ClienteleEntities.descriptorOf(entityClass); + } + + @Override + public EntityDescriptor getEntityDescriptor(String name) { + return ClienteleEntities.descriptorOf(name); + } + + @Override + public List getEntityDescriptors() { + return Arrays.asList(ClienteleEntities.values()); + } + + // ::: stores + // + public ClientStore getClientStore() { + return getService(ClientStore.class); + } + + public ClientRelationStore getClientRelationStore() { + return getService(ClientRelationStore.class); + } + + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/ClienteleErrors.java b/src/main/java/io/kumare/iqr/mod/clientele/ClienteleErrors.java new file mode 100644 index 0000000..c1fe36b --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/ClienteleErrors.java @@ -0,0 +1,95 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele; + +// java +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.transport.TransportCode; +import static io.kumare.lib.transport.Transports.code; +import io.kumare.lib.v.ExceptionPrototype; +// app +import io.kumare.iqr.app.AppException; +import io.kumare.iqr.app.endpoint.AppTransports; + + +/** + * + * @author afatecha + */ +public enum ClienteleErrors implements ExceptionPrototype { + + + // client + client_notfound(1, code(AppTransports.http, 400)), + client_data_notfound(1, code(AppTransports.http, 400)), + client_preload_empty(1, code(AppTransports.http, 400)), + client_externalid_empty(1, code(AppTransports.http, 400)), + client_entitykey_empty(1, code(AppTransports.http, 400)), + client_alias_empty(1, code(AppTransports.http, 400)), + client_statevalue_empty(1, code(AppTransports.http, 400)), + client_email_empty(1, code(AppTransports.http, 400)), + client_phone_empty(1, code(AppTransports.http, 400)), + client_name_empty(1, code(AppTransports.http, 400)), + client_description_empty(1, code(AppTransports.http, 400)), + client_authuser_notfound(1, code(AppTransports.http, 400)), + client_state_notfound(1, code(AppTransports.http, 400)), + + // client relation + clientrelation_notfound(1, code(AppTransports.http, 400)), + clientrelation_data_notfound(1, code(AppTransports.http, 400)), + clientrelation_preload_empty(1, code(AppTransports.http, 400)), + clientrelation_typevalue_empty(1, code(AppTransports.http, 400)), + clientrelation_statevalue_empty(1, code(AppTransports.http, 400)), + clientrelation_resourcetype_empty(1, code(AppTransports.http, 400)), + clientrelation_resourcekey_empty(1, code(AppTransports.http, 400)), + clientrelation_resourceid_empty(1, code(AppTransports.http, 400)), + clientrelation_type_notfound(1, code(AppTransports.http, 400)), + clientrelation_state_notfound(1, code(AppTransports.http, 400)); + + // ::: vars + // + private final Map transportCodes = new HashMap(); + private final int code; + + // ::: constructors + // + private ClienteleErrors(int code, TransportCode... codes) { + this.code = code; + if (codes != null) { + for (var i : codes) { + if (i != null) { + transportCodes.put(i.getId(), i.getCode()); + } + } + } + } + + // ::: prototype api + // + @Override + public int getCode() { + return code; + } + + @Override + public String getName() { + return name(); + } + + @Override + public Map getTransportCodes() { + return transportCodes; + } + + @Override + public RuntimeException newInstance(String msg, Throwable cause, Map extra) { + var ex = new AppException(this, msg, cause); + ex.setExtra(extra); + return ex; + } + + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/ClienteleModule.java b/src/main/java/io/kumare/iqr/mod/clientele/ClienteleModule.java new file mode 100644 index 0000000..d5da95e --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/ClienteleModule.java @@ -0,0 +1,37 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele; + +// java +import io.kumare.lib.base.server.spring.module.BaseModule; + + +/** + * + * @author afatecha + */ +public class ClienteleModule extends BaseModule { + + // ::: + // + public static final ClienteleController controller = new ClienteleController(); + + // ::: api + // + @Override + public int getId() { + return ClienteleConstants.CODE; + } + + @Override + public String getName() { + return ClienteleConstants.NAME; + } + + @Override + public ClienteleController getController() { + return controller; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/ClientelePermissions.java b/src/main/java/io/kumare/iqr/mod/clientele/ClientelePermissions.java new file mode 100644 index 0000000..d3ced0e --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/ClientelePermissions.java @@ -0,0 +1,84 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele; + +// base +import io.kumare.iqr.mod.clientele.store.ClienteleEntities; +import io.kumare.lib.app.api.security.PermissionReference; +// app +import io.kumare.iqr.app.AppErrors; + +/** + * + * @author afatecha + */ +public enum ClientelePermissions { + + // client + //client_add(ClienteleEntities.client), + //client_edit(ClienteleEntities.client), + //client_find(ClienteleEntities.client), + //client_enable(ClienteleEntities.client), + //client_disable(ClienteleEntities.client), + //client_list(ClienteleEntities.client), + //client_delete(ClienteleEntities.client), + //client_preload(ClienteleEntities.client), + // + client_viewer(ClienteleEntities.client), + //client_guest(ClienteleEntities.client), + //client_collab(ClienteleEntities.client), + client_worker(ClienteleEntities.client), + //client_control(ClienteleEntities.client), + client_manager(ClienteleEntities.client), + client_admin(null), + client_system(null), + + // client relation + //client_relation_add(ClienteleEntities.clientRelation), + //client_relation_edit(ClienteleEntities.clientRelation), + //client_relation_find(ClienteleEntities.clientRelation), + //client_relation_enable(ClienteleEntities.clientRelation), + //client_relation_disable(ClienteleEntities.clientRelation), + //client_relation_list(ClienteleEntities.clientRelation), + //client_relation_delete(ClienteleEntities.clientRelation), + //client_relation_preload(ClienteleEntities.clientRelation), + // + client_relation_viewer(ClienteleEntities.clientRelation), + //client_relation_guest(ClienteleEntities.clientRelation), + //client_relation_collab(ClienteleEntities.clientRelation), + client_relation_worker(ClienteleEntities.clientRelation), + //client_relation_control(ClienteleEntities.clientRelation), + client_relation_manager(ClienteleEntities.clientRelation), + client_relation_admin(null), + client_relation_system(null); + + + // ::: + // + private final ClienteleEntities resourceType; + + ClientelePermissions(ClienteleEntities entityRef) { + this.resourceType = entityRef; + } + + // + public PermissionReference toReference() { + return toReference(null); + } + + public PermissionReference toReference(String resourceKey) { + var ref = new PermissionReference() + .module(ClienteleConstants.NAME) + .permission(name()) + .error(AppErrors.action_unauthorized); + + if (resourceType != null && resourceKey != null) { + ref.resourceType(resourceType.name()) + .resourceKey(resourceKey); + } + + return ref; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientActionArgument.java b/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientActionArgument.java new file mode 100644 index 0000000..ef9dc8f --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientActionArgument.java @@ -0,0 +1,29 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.client; + +// base +import io.kumare.iqr.app.action.AppEntityActionArgument; +// entity +import io.kumare.iqr.mod.clientele.store.client.ClientEntity; + +/** + * + * @author afatecha + */ +public class ClientActionArgument extends AppEntityActionArgument { + + // ::: constructors + // + public ClientActionArgument() { + } + + public ClientActionArgument(ClientEntity entity) { + super(entity); + } + + // ::: api + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientAddAction.java b/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientAddAction.java new file mode 100644 index 0000000..11a929f --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientAddAction.java @@ -0,0 +1,136 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.client; + +// lib +import io.kumare.lib.base.server.spring.action.Actions; +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +import io.kumare.iqr.mod.authentication.action.authuser.AuthUserAddAction; +import io.kumare.iqr.mod.authentication.action.authuser.AuthUserAddArgument; +// module +import io.kumare.iqr.mod.clientele.ClienteleErrors; +// entity +import io.kumare.iqr.mod.clientele.store.client.ClientEntity; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; +import io.kumare.iqr.mod.authentication.store.authuser.AuthUserEntity; + +/** + * + * @author afatecha + */ +public class ClientAddAction extends AppAction> { + + // ::: vars + // + private ClientEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, ClienteleErrors.client_notfound); + + // relations + V.ifNull(model.getAuthUser(), ClienteleErrors.client_authuser_notfound); + V.ifNull(model.getState(), ClienteleErrors.client_state_notfound); + + // fields + //V.ifEmpty(model.getExternalId(), ClienteleErrors.client_externalid_empty); + //V.ifEmpty(model.getEntityKey(), ClienteleErrors.client_entitykey_empty); + V.ifEmpty(model.getAlias(), ClienteleErrors.client_alias_empty); + // V.ifEmpty(model.getStateValue(), ClienteleErrors.client_statevalue_empty); + V.ifEmpty(model.getEmail(), ClienteleErrors.client_email_empty); + //V.ifEmpty(model.getPhone(), ClienteleErrors.client_phone_empty); + V.ifEmpty(model.getName(), ClienteleErrors.client_name_empty); + //V.ifEmpty(model.getDescription(), ClienteleErrors.client_description_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + var taxonomy = AppModules.taxonomy.getController(); + var authentication = AppModules.authentication.getController(); + + //var authUserStore = authentication.getAuthUserStore(); + var taxonStore = taxonomy.getTaxonStore(); + + //var authUser = authUserStore.ensure(getContext(), argModel.getAuthUser(), ClienteleErrors.client_authuser_notfound); + var authUser = createAuthUser(); + var state = taxonStore.ensure(getContext(), argModel.getState(), ClienteleErrors.client_state_notfound); + + // model + var model = makeModel(authUser, state); + + // add + entity = saveEntity(model); + + // add others + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private ClientEntity makeModel(AuthUserEntity authUser, TaxonEntity state) { + + var argModel = getArgument().getEntity(); + var model = new ClientEntity(); + + // relations + model.setAuthUser(authUser); + model.setState(state); + + // fields + model.setExternalId(argModel.getExternalId()); + model.setEntityKey(argModel.getEntityKey()); + model.setAlias(argModel.getAlias()); + model.setStateValue(argModel.getStateValue()); + model.setEmail(argModel.getEmail()); + model.setPhone(argModel.getPhone()); + model.setName(argModel.getName()); + model.setDescription(argModel.getDescription()); + model.setActive(true); + + return model; + } + + // ::: save + // + private ClientEntity saveEntity(ClientEntity model) { + + var store = AppModules.clientele.getController().getClientStore(); + + var saved = store.add(getContext(), model); + getContext().attach(saved.getId(), saved); + return saved; + } + + private AuthUserEntity createAuthUser() { + var arg = new AuthUserAddArgument(); + var ent = new AuthUserEntity(); + arg.setEntity(ent); + arg.setPassword(getArgument().getPassword()); + var action = Actions.perform(getContext(), AuthUserAddAction.class, arg); + return action.getResult().getEntity(); + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientAddArgument.java b/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientAddArgument.java new file mode 100644 index 0000000..ce8c536 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientAddArgument.java @@ -0,0 +1,38 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.client; + +// app +import io.kumare.iqr.mod.clientele.store.client.ClientEntity; + +/** + * + * @author afatecha + */ +public class ClientAddArgument extends ClientActionArgument { + + // ::: vars + // + private String password; + + // ::: constructors + // + public ClientAddArgument() { + } + + public ClientAddArgument(ClientEntity entity) { + super(entity); + } + + // ::: fields + // + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientDeleteAction.java b/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientDeleteAction.java new file mode 100644 index 0000000..12221a4 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientDeleteAction.java @@ -0,0 +1,59 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.client; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.clientele.ClienteleErrors; +// entity +import io.kumare.iqr.mod.clientele.store.client.ClientEntity; + +/** + * + * @author afatecha + */ +public class ClientDeleteAction extends AppAction> { + + // ::: vars + // + private ClientEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), ClienteleErrors.client_notfound); + V.ifNull(getArgument().getEntity().getId(), ClienteleErrors.client_notfound); + } + + @Override + protected void doAction() { + + var argModel = getArgument().getEntity(); + + deleteEntity(argModel); + } + + @Override + protected void setResultOnly() { + } + + // ::: delete + // + private void deleteEntity(ClientEntity model) { + + var store = AppModules.clientele.getController().getClientStore(); + + store.deleteById(getContext(), model.getId()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientEditAction.java b/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientEditAction.java new file mode 100644 index 0000000..489c19f --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientEditAction.java @@ -0,0 +1,107 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.client; + +// lib +import io.kumare.lib.v.V; +// app +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.clientele.ClienteleErrors; +// entity +import io.kumare.iqr.mod.clientele.store.client.ClientEntity; + +/** + * + * @author afatecha + */ +public class ClientEditAction extends AppAction> { + + // ::: vars + // + private ClientEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, ClienteleErrors.client_notfound); + + // fields + V.ifEmpty(model.getExternalId(), ClienteleErrors.client_externalid_empty); + V.ifEmpty(model.getEntityKey(), ClienteleErrors.client_entitykey_empty); + V.ifEmpty(model.getAlias(), ClienteleErrors.client_alias_empty); + V.ifEmpty(model.getStateValue(), ClienteleErrors.client_statevalue_empty); + V.ifEmpty(model.getEmail(), ClienteleErrors.client_email_empty); + V.ifEmpty(model.getPhone(), ClienteleErrors.client_phone_empty); + V.ifEmpty(model.getName(), ClienteleErrors.client_name_empty); + V.ifEmpty(model.getDescription(), ClienteleErrors.client_description_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + + var clientele = AppModules.clientele.getController(); + var clientStore = clientele.getClientStore(); + + // edit + entity = clientStore.ensure(getContext(), argModel, ClienteleErrors.client_notfound); + + editEntity(); + + entity = saveEntity(); + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private void editEntity() { + + var model = getArgument().getEntity(); + + // fields + entity.setExternalId(V.firstNotEmpty(model.getExternalId(), entity.getExternalId())); + entity.setEntityKey(V.firstNotEmpty(model.getEntityKey(), entity.getEntityKey())); + entity.setAlias(V.firstNotEmpty(model.getAlias(), entity.getAlias())); + entity.setStateValue(V.firstNotEmpty(model.getStateValue(), entity.getStateValue())); + entity.setEmail(V.firstNotEmpty(model.getEmail(), entity.getEmail())); + entity.setPhone(V.firstNotEmpty(model.getPhone(), entity.getPhone())); + entity.setName(V.firstNotEmpty(model.getName(), entity.getName())); + entity.setDescription(V.firstNotEmpty(model.getDescription(), entity.getDescription())); + + + } + + // ::: save + // + private ClientEntity saveEntity() { + + var store = AppModules.clientele.getController().getClientStore(); + + var saved = store.edit(getContext(), entity); + getContext().attach(saved.getId(), saved); + return saved; + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientEditArgument.java b/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientEditArgument.java new file mode 100644 index 0000000..62ae824 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientEditArgument.java @@ -0,0 +1,32 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.client; + +// app +import io.kumare.iqr.mod.clientele.store.client.ClientEntity; + +/** + * + * @author afatecha + */ +public class ClientEditArgument extends ClientActionArgument { + + // ::: vars + // + + + // ::: constructors + // + public ClientEditArgument() { + } + + public ClientEditArgument(ClientEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientEnableAction.java b/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientEnableAction.java new file mode 100644 index 0000000..9422631 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientEnableAction.java @@ -0,0 +1,60 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.client; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.clientele.ClienteleErrors; +// entity +import io.kumare.iqr.mod.clientele.store.client.ClientEntity; + + +/** + * + * @author afatecha + */ +public class ClientEnableAction extends AppAction { + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), ClienteleErrors.client_notfound); + V.ifNull(getArgument().getEntity().getId(), ClienteleErrors.client_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + + enableEntity(model); + } + + @Override + protected void setResultOnly() { + } + + // ::: enable + // + private void enableEntity(ClientEntity model) { + + var store = AppModules.clientele.getController().getClientStore(); + + if (getArgument().getEntity().isActive()) { + store.enableById(getContext(), model.getId()); + } else { + store.disableById(getContext(), model.getId()); + } + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientFindAction.java b/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientFindAction.java new file mode 100644 index 0000000..497e973 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientFindAction.java @@ -0,0 +1,64 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.client; + +// java +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.clientele.ClienteleErrors; +// entity +import io.kumare.iqr.mod.clientele.store.client.ClientEntity; + + +/** + * + * @author afatecha + */ +public class ClientFindAction extends AppAction { + + // ::: vars + // + private ClientEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), ClienteleErrors.client_notfound); + V.ifNull(getArgument().getEntity().getId(), ClienteleErrors.client_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + entity = findEntity(model); + } + + @Override + protected void setResultOnly() { + var result = new HashMap(); + result.put("entity", entity); + setResult(result); + } + + // ::: find + // + private ClientEntity findEntity(ClientEntity model) { + + var store = AppModules.clientele.getController().getClientStore(); + return store.findById(getContext(), model.getId()); + } + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientListAction.java b/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientListAction.java new file mode 100644 index 0000000..532df4b --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientListAction.java @@ -0,0 +1,145 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.client; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.LinkedList; +import java.util.Map; +// spring +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// entity +import io.kumare.iqr.mod.clientele.store.client.ClientEntity; +import io.kumare.iqr.mod.clientele.store.client.ClientMapBuilder; + +/** + * + * @author afatecha + */ +public class ClientListAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private final List entities = new LinkedList<>(); + + // ::: public api + // + public List getEntities() { + return entities; + } + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + } + + @Override + protected void doAction() { + + result.put("pageable", getArgument().isPageable()); + result.put("wrapped", getArgument().isWrapped()); + + if (getArgument().isPageable()) { + + var page = makePage(); + entities.addAll(page.toList()); + + if (getArgument().isWrapped()) { + result.put("page", makeWrappedPage(page)); + } else { + result.put("page", page); + } + + } else { + + var list = makeList(); + entities.addAll(list); + + if (getArgument().isWrapped()) { + result.put("list", makeWrappedList()); + } else { + result.put("list", list); + } + } + + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: page + // + private Page makePage() { + + var page = getArgument().getPageNumber(); + var size = getArgument().getPageSize(); + //var sort = getArgument().getSort(); + + var pageable = PageRequest.of(page, size); + + var store = AppModules.clientele.getController().getClientStore(); + return store.getRepository().findAll(pageable); + } + + // ::: wrapped page + // + private Map makeWrappedPage(Page found) { + + var page = new HashMap(); + var content = new LinkedList(); + + wrapList(entities, content); + + page.put("size", found.getSize()); + page.put("number", found.getNumber()); + page.put("totalElements", found.getTotalElements()); + page.put("totalPages", found.getTotalPages()); + page.put("content", content); + + return page; + } + + // ::: list + // + private List makeList() { + + var store = AppModules.clientele.getController().getClientStore(); + + return store.listAll(getContext()); + } + + // ::: wrapped list + private List makeWrappedList() { + var list = new LinkedList(); + + wrapList(entities, list); + + return list; + } + + // ::: wrapper + // + private void wrapList(List found, List output) { + + var builder = new ClientMapBuilder().addListGroup(); + builder.getAuthUserBuilder().addMainGroup(); + builder.getStateBuilder().addMainGroup(); + + output.addAll(builder.build(getContext(), found)); + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientListArgument.java b/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientListArgument.java new file mode 100644 index 0000000..0896d74 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientListArgument.java @@ -0,0 +1,50 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.client; + +// app +import io.kumare.iqr.app.action.AppListActionArgument; +// store +import io.kumare.iqr.mod.clientele.store.client.ClientEntity; +import java.time.LocalDate; + +/** + * + * @author afatecha + */ +public class ClientListArgument extends AppListActionArgument { + + // ::: vars + // + private LocalDate start; + private LocalDate end; + + // ::: constructors + // + public ClientListArgument() { + } + + public ClientListArgument(ClientEntity entity) { + super(entity); + } + + // ::: fields + // + public LocalDate getStart() { + return start; + } + + public void setStart(LocalDate start) { + this.start = start; + } + + public LocalDate getEnd() { + return end; + } + + public void setEnd(LocalDate end) { + this.end = end; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientPreloadAction.java b/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientPreloadAction.java new file mode 100644 index 0000000..c89a6ee --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientPreloadAction.java @@ -0,0 +1,114 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.client; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.clientele.ClienteleErrors; +// entity +import io.kumare.iqr.mod.clientele.store.client.ClientEntity; +// relations +import io.kumare.iqr.mod.authentication.store.authuser.AuthUserEntity; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; + +/** + * + * @author afatecha + */ +public class ClientPreloadAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private Map params = new HashMap<>(); + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifEmpty(getArgument().getAction(), ClienteleErrors.client_preload_empty); + } + + @Override + protected void doAction() { + if(getArgument().getParams() != null) { + params = getArgument().getParams(); + } + + switch (getArgument().getAction()) { + case "find" -> + prepareFind(); + case "list" -> + prepareList(); + case "add" -> + prepareAdd(); + case "edit" -> + prepareEdit(); + } + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: preload + // + private void prepareAdd() { + result.put("taxons", listTaxons()); + result.put("authUsers", listAuthUsers()); + } + + private void prepareEdit() { + var entity = findEntity(); + result.put("entity", entity); + result.put("authUser", entity.getAuthUser()); + result.put("state", entity.getState()); + } + + private void prepareList() { + } + + private void prepareFind() { + var entity = findEntity(); + result.put("entity", entity); + result.put("authUser", entity.getAuthUser()); + result.put("state", entity.getState()); + } + + // ::: queries + // + private ClientEntity findEntity() { + var store = AppModules.clientele.getController().getClientStore(); + + var id = (String) params.get("id"); + if(id == null && getArgument().getEntity() != null) { + id = getArgument().getEntity().getId(); + } + return store.findById(getContext(), id); + } + + public List listTaxons() { + var store = AppModules.taxonomy.getController().getTaxonStore(); + + return store.listAll(getContext()); + } + public List listAuthUsers() { + var store = AppModules.authentication.getController().getAuthUserStore(); + + return store.listAll(getContext()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientPreloadArgument.java b/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientPreloadArgument.java new file mode 100644 index 0000000..4fb3a3d --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/client/ClientPreloadArgument.java @@ -0,0 +1,26 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.client; + +/** + * + * @author afatecha + */ +public class ClientPreloadArgument extends ClientActionArgument { + + // ::: vars + // + private String action; + + // ::: fields + // + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/client/GvTime.java b/src/main/java/io/kumare/iqr/mod/clientele/action/client/GvTime.java new file mode 100644 index 0000000..b0670fe --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/client/GvTime.java @@ -0,0 +1,35 @@ +package io.kumare.iqr.mod.clientele.action.client; +import java.time.*; +import java.time.format.DateTimeFormatter; + +public final class GvTime { + private GvTime() {} + + // Formato: 20251004163000 (yyyyMMddHHmmss) + public static final DateTimeFormatter GV_TS = DateTimeFormatter.ofPattern("uuuuMMddHHmmss"); + + // LocalDateTime -> String + public static String format(LocalDateTime dt) { + return dt.format(GV_TS); + } + + // LocalDate -> String (inicio de día) + public static String formatStartOfDay(LocalDate d) { + return d.atStartOfDay().format(GV_TS); // HHmmss = 000000 + } + + // LocalDate -> String (fin de día) + public static String formatEndOfDay(LocalDate d) { + return d.atTime(23, 59, 59).format(GV_TS); // HHmmss = 235959 + } + + // Instant -> String (con zona, ej. Asunción) + public static String format(Instant instant, ZoneId zone) { + return instant.atZone(zone).format(GV_TS); + } + + // String -> LocalDateTime (parsea "20251004163000") + public static LocalDateTime parse(String s) { + return LocalDateTime.parse(s, GV_TS); + } +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/client/PunchType.java b/src/main/java/io/kumare/iqr/mod/clientele/action/client/PunchType.java new file mode 100644 index 0000000..1f4377d --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/client/PunchType.java @@ -0,0 +1,41 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Enum.java to edit this template + */ +package io.kumare.iqr.mod.clientele.action.client; + +/** + * + * @author Albino + */ +public enum PunchType { + ENTER("Ingreso"), + EXIT("Salida"); + + private final String display; + + PunchType(String display) { + this.display = display; + } + + public String getDisplay() { + return display; + } + + public boolean isEnter() { + return this == ENTER; + } + + public boolean isExit() { + return this == EXIT; + } + + public static java.util.Optional fromDisplay(String s) { + if (s == null) { + return java.util.Optional.empty(); + } + return java.util.Arrays.stream(values()) + .filter(p -> p.display.equalsIgnoreCase(s)) + .findFirst(); + } +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/client/VismaAddPunchAction.java b/src/main/java/io/kumare/iqr/mod/clientele/action/client/VismaAddPunchAction.java new file mode 100644 index 0000000..41a9126 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/client/VismaAddPunchAction.java @@ -0,0 +1,56 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.client; + +// java +import io.kumare.adapter.spring.vismatime.message.punch.model.AddArtificialRequest; +import io.kumare.adapter.spring.vismatime.message.punch.model.AddArtificialResponse; +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +// entity + +/** + * + * @author afatecha + */ +public class VismaAddPunchAction extends AppAction { + + // ::: vars + // + private AddArtificialResponse response; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + } + + @Override + protected void doAction() { + var vismaAdapter = getContext().getAdapters().getVisma(); + var arg = getArgument(); + var punch = new AddArtificialRequest(); + punch.setUserIdentifier(arg.getUserId()); + punch.setType(arg.getType().getDisplay()); + punch.setDate(GvTime.format(arg.getDate())); + + response = vismaAdapter.punch().addArtificial(punch); + } + + @Override + protected void setResultOnly() { + var result = new HashMap(); + result.put("punch", response); + setResult(result); + } + + // ::: find + // +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/client/VismaAddPunchArgument.java b/src/main/java/io/kumare/iqr/mod/clientele/action/client/VismaAddPunchArgument.java new file mode 100644 index 0000000..74da780 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/client/VismaAddPunchArgument.java @@ -0,0 +1,49 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.client; + +// app +import java.time.LocalDateTime; + +/** + * + * @author afatecha + */ +public class VismaAddPunchArgument { + + // ::: vars + // + private LocalDateTime date; + private String userId; + private PunchType type; + + // ::: constructors + // + // ::: fields + // + public LocalDateTime getDate() { + return date; + } + + public void setDate(LocalDateTime date) { + this.date = date; + } + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public PunchType getType() { + return type; + } + + public void setType(PunchType type) { + this.type = type; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/client/VismaAddPunchMultipleAction.java b/src/main/java/io/kumare/iqr/mod/clientele/action/client/VismaAddPunchMultipleAction.java new file mode 100644 index 0000000..e5c9af7 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/client/VismaAddPunchMultipleAction.java @@ -0,0 +1,63 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.client; + +// java +import io.kumare.adapter.spring.vismatime.message.punch.model.AddMultipleItemRequest; +import io.kumare.adapter.spring.vismatime.message.punch.model.AddMultipleRequest; +import io.kumare.adapter.spring.vismatime.message.punch.model.AddMultipleResponse; +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import java.util.UUID; + +// entity + +/** + * + * @author afatecha + */ +public class VismaAddPunchMultipleAction extends AppAction { + + // ::: vars + // + private AddMultipleResponse response; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + } + + @Override + protected void doAction() { + var vismaAdapter = getContext().getAdapters().getVisma(); + var arg = getArgument(); + var punch = new AddMultipleRequest(); + for (var p : arg) { + var a = new AddMultipleItemRequest(); + a.setReferenceIdentifier(UUID.randomUUID().toString()); + a.setType(p.getType()); + a.setUserIdentifier(p.getUserIdentifier()); + a.setDate(p.getDate()); + } + + response = vismaAdapter.punch().addMultiple(punch); + } + + @Override + protected void setResultOnly() { + var result = new HashMap(); + result.put("punchs", response); + setResult(result); + } + + // ::: find + // +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/client/VismaAddPunchMultipleArgument.java b/src/main/java/io/kumare/iqr/mod/clientele/action/client/VismaAddPunchMultipleArgument.java new file mode 100644 index 0000000..4a1997f --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/client/VismaAddPunchMultipleArgument.java @@ -0,0 +1,21 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.client; + +// app +import io.kumare.adapter.spring.vismatime.message.punch.model.AddMultipleRequest; + +/** + * + * @author afatecha + */ +public class VismaAddPunchMultipleArgument extends AddMultipleRequest { + + // ::: vars + // + // ::: constructors + // + // ::: fields + // +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/client/VismaDeletePunchAction.java b/src/main/java/io/kumare/iqr/mod/clientele/action/client/VismaDeletePunchAction.java new file mode 100644 index 0000000..8a064af --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/client/VismaDeletePunchAction.java @@ -0,0 +1,55 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.client; + +// java +import io.kumare.adapter.spring.vismatime.message.punch.model.AddArtificialRequest; +import io.kumare.adapter.spring.vismatime.message.punch.model.AddArtificialResponse; +import io.kumare.adapter.spring.vismatime.message.punch.model.DeleteArtificialRequest; +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +// entity + +/** + * + * @author afatecha + */ +public class VismaDeletePunchAction extends AppAction { + + // ::: vars + // + private boolean response; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + } + + @Override + protected void doAction() { + var vismaAdapter = getContext().getAdapters().getVisma(); + var arg = getArgument(); + var punch = new DeleteArtificialRequest(); + punch.setKey(arg.getKey()); + + response = vismaAdapter.punch().deleteArtificial(punch); + } + + @Override + protected void setResultOnly() { + var result = new HashMap(); + result.put("punchDelete", response); + setResult(result); + } + + // ::: find + // +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/client/VismaDeletePunchArgument.java b/src/main/java/io/kumare/iqr/mod/clientele/action/client/VismaDeletePunchArgument.java new file mode 100644 index 0000000..0f06679 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/client/VismaDeletePunchArgument.java @@ -0,0 +1,29 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.client; + +// app +/** + * + * @author afatecha + */ +public class VismaDeletePunchArgument { + + // ::: vars + // + private String key; + + // ::: constructors + // + // ::: fields + // + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/client/VismaEmployeeListAction.java b/src/main/java/io/kumare/iqr/mod/clientele/action/client/VismaEmployeeListAction.java new file mode 100644 index 0000000..0cda07d --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/client/VismaEmployeeListAction.java @@ -0,0 +1,49 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.client; + +// java +import io.kumare.adapter.spring.vismatime.message.user.model.UserItemResponse; +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +// entity + +/** + * + * @author afatecha + */ +public class VismaEmployeeListAction extends AppAction { + + // ::: vars + // + private UserItemResponse response; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + } + + @Override + protected void doAction() { + var vismaAdapter = getContext().getAdapters().getVisma(); + response = vismaAdapter.user().list(); + } + + @Override + protected void setResultOnly() { + var result = new HashMap(); + result.put("list", response.getItems()); + setResult(result); + } + + // ::: find + // +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/client/VismaPunchListAction.java b/src/main/java/io/kumare/iqr/mod/clientele/action/client/VismaPunchListAction.java new file mode 100644 index 0000000..6a33e15 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/client/VismaPunchListAction.java @@ -0,0 +1,57 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.client; + +// java +import io.kumare.adapter.spring.vismatime.message.punch.model.PaginatedListByDateRequest; +import io.kumare.adapter.spring.vismatime.message.punch.model.PunchList; +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import java.time.format.DateTimeFormatter; +// entity + +/** + * + * @author afatecha + */ +public class VismaPunchListAction extends AppAction { + + // ::: vars + // + private PunchList response; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + } + + @Override + protected void doAction() { + var vismaAdapter = getContext().getAdapters().getVisma(); + var arg = getArgument(); + var req = new PaginatedListByDateRequest(); + req.setPage(String.valueOf(arg.getPageNumber() + 1)); + req.setStartDate(arg.getStart().format(DateTimeFormatter.BASIC_ISO_DATE)); + req.setEndDate(arg.getEnd().format(DateTimeFormatter.BASIC_ISO_DATE)); + + response = vismaAdapter.punch().paginatedListByDate(req); + } + + @Override + protected void setResultOnly() { + var result = new HashMap(); + result.put("lis", response); + setResult(result); + } + + // ::: find + // +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/client/VismaPunchListArgument.java b/src/main/java/io/kumare/iqr/mod/clientele/action/client/VismaPunchListArgument.java new file mode 100644 index 0000000..3eed5db --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/client/VismaPunchListArgument.java @@ -0,0 +1,52 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.client; + +// app +import io.kumare.iqr.app.action.AppListActionArgument; +// store +import io.kumare.iqr.mod.clientele.store.client.ClientEntity; +import java.time.LocalDate; + +/** + * + * @author afatecha + */ +public class VismaPunchListArgument { + + // ::: vars + // + private LocalDate start; + private LocalDate end; + private Integer pageNumber = 0; + + // ::: constructors + // + // ::: fields + // + public LocalDate getStart() { + return start; + } + + public void setStart(LocalDate start) { + this.start = start; + } + + public LocalDate getEnd() { + return end; + } + + public void setEnd(LocalDate end) { + this.end = end; + } + + public Integer getPageNumber() { + return pageNumber; + } + + public void setPageNumber(Integer pageNumber) { + this.pageNumber = pageNumber; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/client/VismaPunchListPageAction.java b/src/main/java/io/kumare/iqr/mod/clientele/action/client/VismaPunchListPageAction.java new file mode 100644 index 0000000..a2f633f --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/client/VismaPunchListPageAction.java @@ -0,0 +1,59 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.client; + +// java +import io.kumare.adapter.spring.vismatime.message.punch.model.PaginatedListByDateRequest; +import io.kumare.adapter.spring.vismatime.message.punch.model.PunchItem; +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import java.time.format.DateTimeFormatter; +import org.springframework.data.domain.Page; +// entity + +/** + * + * @author afatecha + */ +public class VismaPunchListPageAction extends AppAction { + + // ::: vars + // + private Page response = Page.empty(); + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + } + + @Override + protected void doAction() { + var vismaAdapter = getContext().getAdapters().getVisma(); + var arg = getArgument(); + var req = new PaginatedListByDateRequest(); + req.setPage(String.valueOf(arg.getPageNumber() + 1)); + req.setStartDate(arg.getStart().format(DateTimeFormatter.BASIC_ISO_DATE)); // yyyyMMdd + req.setEndDate(arg.getEnd().format(DateTimeFormatter.BASIC_ISO_DATE)); + + + response = vismaAdapter.punch().paginatedListByDateAsPage(req, null); + } + + @Override + protected void setResultOnly() { + var result = new HashMap(); + result.put("page", response); + setResult(result); + } + + // ::: find + // +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationActionArgument.java b/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationActionArgument.java new file mode 100644 index 0000000..aaedf8b --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationActionArgument.java @@ -0,0 +1,29 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.clientrelation; + +// base +import io.kumare.iqr.app.action.AppEntityActionArgument; +// entity +import io.kumare.iqr.mod.clientele.store.clientrelation.ClientRelationEntity; + +/** + * + * @author afatecha + */ +public class ClientRelationActionArgument extends AppEntityActionArgument { + + // ::: constructors + // + public ClientRelationActionArgument() { + } + + public ClientRelationActionArgument(ClientRelationEntity entity) { + super(entity); + } + + // ::: api + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationAddAction.java b/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationAddAction.java new file mode 100644 index 0000000..6e3073f --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationAddAction.java @@ -0,0 +1,124 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.clientrelation; + + +// lib +import io.kumare.lib.base.server.spring.action.Actions; +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.clientele.ClienteleErrors; +// entity +import io.kumare.iqr.mod.clientele.store.clientrelation.ClientRelationEntity; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; + + +/** + * + * @author afatecha + */ +public class ClientRelationAddAction extends AppAction> { + + // ::: vars + // + private ClientRelationEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, ClienteleErrors.clientrelation_notfound); + + // relations + V.ifNull(model.getType(), ClienteleErrors.clientrelation_type_notfound); + V.ifNull(model.getState(), ClienteleErrors.clientrelation_state_notfound); + + // fields + V.ifEmpty(model.getTypeValue(), ClienteleErrors.clientrelation_typevalue_empty); + V.ifEmpty(model.getStateValue(), ClienteleErrors.clientrelation_statevalue_empty); + V.ifEmpty(model.getResourceType(), ClienteleErrors.clientrelation_resourcetype_empty); + V.ifEmpty(model.getResourceKey(), ClienteleErrors.clientrelation_resourcekey_empty); + V.ifEmpty(model.getResourceId(), ClienteleErrors.clientrelation_resourceid_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + var taxonomy = AppModules.taxonomy.getController(); + + var taxonStore = taxonomy.getTaxonStore(); + + var type = taxonStore.ensure(getContext(), argModel.getType(), ClienteleErrors.clientrelation_type_notfound); + var state = taxonStore.ensure(getContext(), argModel.getState(), ClienteleErrors.clientrelation_state_notfound); + + // model + var model = makeModel(type, state); + + // add + entity = saveEntity(model); + + // add others + + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private ClientRelationEntity makeModel(TaxonEntity type, TaxonEntity state) { + + var argModel = getArgument().getEntity(); + var model = new ClientRelationEntity(); + + // relations + model.setType(type); + model.setState(state); + + // fields + model.setTypeValue(argModel.getTypeValue()); + model.setStateValue(argModel.getStateValue()); + model.setResourceType(argModel.getResourceType()); + model.setResourceKey(argModel.getResourceKey()); + model.setResourceId(argModel.getResourceId()); + model.setActive(true); + + + + return model; + } + + // ::: save + // + private ClientRelationEntity saveEntity(ClientRelationEntity model) { + + var store = AppModules.clientele.getController().getClientRelationStore(); + + var saved = store.add(getContext(), model); + getContext().attach(saved.getId(), saved); + return saved; + } + + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationAddArgument.java b/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationAddArgument.java new file mode 100644 index 0000000..137132c --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationAddArgument.java @@ -0,0 +1,34 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.clientrelation; + + +// app +import io.kumare.iqr.mod.clientele.store.clientrelation.ClientRelationEntity; + + +/** + * + * @author afatecha + */ +public class ClientRelationAddArgument extends ClientRelationActionArgument { + + // ::: vars + // + + + // ::: constructors + // + public ClientRelationAddArgument() { + } + + public ClientRelationAddArgument(ClientRelationEntity entity) { + super(entity); + } + + // ::: fields + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationDeleteAction.java b/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationDeleteAction.java new file mode 100644 index 0000000..350c8b0 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationDeleteAction.java @@ -0,0 +1,59 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.clientrelation; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.clientele.ClienteleErrors; +// entity +import io.kumare.iqr.mod.clientele.store.clientrelation.ClientRelationEntity; + +/** + * + * @author afatecha + */ +public class ClientRelationDeleteAction extends AppAction> { + + // ::: vars + // + private ClientRelationEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), ClienteleErrors.clientrelation_notfound); + V.ifNull(getArgument().getEntity().getId(), ClienteleErrors.clientrelation_notfound); + } + + @Override + protected void doAction() { + + var argModel = getArgument().getEntity(); + + deleteEntity(argModel); + } + + @Override + protected void setResultOnly() { + } + + // ::: delete + // + private void deleteEntity(ClientRelationEntity model) { + + var store = AppModules.clientele.getController().getClientRelationStore(); + + store.deleteById(getContext(), model.getId()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationEditAction.java b/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationEditAction.java new file mode 100644 index 0000000..6e4ada1 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationEditAction.java @@ -0,0 +1,101 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.clientrelation; + +// lib +import io.kumare.lib.v.V; +// app +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.clientele.ClienteleErrors; +// entity +import io.kumare.iqr.mod.clientele.store.clientrelation.ClientRelationEntity; + +/** + * + * @author afatecha + */ +public class ClientRelationEditAction extends AppAction> { + + // ::: vars + // + private ClientRelationEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, ClienteleErrors.clientrelation_notfound); + + // fields + V.ifEmpty(model.getTypeValue(), ClienteleErrors.clientrelation_typevalue_empty); + V.ifEmpty(model.getStateValue(), ClienteleErrors.clientrelation_statevalue_empty); + V.ifEmpty(model.getResourceType(), ClienteleErrors.clientrelation_resourcetype_empty); + V.ifEmpty(model.getResourceKey(), ClienteleErrors.clientrelation_resourcekey_empty); + V.ifEmpty(model.getResourceId(), ClienteleErrors.clientrelation_resourceid_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + + var clientele = AppModules.clientele.getController(); + var clientRelationStore = clientele.getClientRelationStore(); + + // edit + entity = clientRelationStore.ensure(getContext(), argModel, ClienteleErrors.clientrelation_notfound); + + editEntity(); + + entity = saveEntity(); + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private void editEntity() { + + var model = getArgument().getEntity(); + + // fields + entity.setTypeValue(V.firstNotEmpty(model.getTypeValue(), entity.getTypeValue())); + entity.setStateValue(V.firstNotEmpty(model.getStateValue(), entity.getStateValue())); + entity.setResourceType(V.firstNotEmpty(model.getResourceType(), entity.getResourceType())); + entity.setResourceKey(V.firstNotEmpty(model.getResourceKey(), entity.getResourceKey())); + entity.setResourceId(V.firstNotEmpty(model.getResourceId(), entity.getResourceId())); + + + } + + // ::: save + // + private ClientRelationEntity saveEntity() { + + var store = AppModules.clientele.getController().getClientRelationStore(); + + var saved = store.edit(getContext(), entity); + getContext().attach(saved.getId(), saved); + return saved; + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationEditArgument.java b/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationEditArgument.java new file mode 100644 index 0000000..20ae3c4 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationEditArgument.java @@ -0,0 +1,32 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.clientrelation; + +// app +import io.kumare.iqr.mod.clientele.store.clientrelation.ClientRelationEntity; + +/** + * + * @author afatecha + */ +public class ClientRelationEditArgument extends ClientRelationActionArgument { + + // ::: vars + // + + + // ::: constructors + // + public ClientRelationEditArgument() { + } + + public ClientRelationEditArgument(ClientRelationEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationEnableAction.java b/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationEnableAction.java new file mode 100644 index 0000000..14d1cef --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationEnableAction.java @@ -0,0 +1,60 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.clientrelation; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.clientele.ClienteleErrors; +// entity +import io.kumare.iqr.mod.clientele.store.clientrelation.ClientRelationEntity; + + +/** + * + * @author afatecha + */ +public class ClientRelationEnableAction extends AppAction { + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), ClienteleErrors.clientrelation_notfound); + V.ifNull(getArgument().getEntity().getId(), ClienteleErrors.clientrelation_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + + enableEntity(model); + } + + @Override + protected void setResultOnly() { + } + + // ::: enable + // + private void enableEntity(ClientRelationEntity model) { + + var store = AppModules.clientele.getController().getClientRelationStore(); + + if (getArgument().getEntity().isActive()) { + store.enableById(getContext(), model.getId()); + } else { + store.disableById(getContext(), model.getId()); + } + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationFindAction.java b/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationFindAction.java new file mode 100644 index 0000000..358d1a1 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationFindAction.java @@ -0,0 +1,64 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.clientrelation; + +// java +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.clientele.ClienteleErrors; +// entity +import io.kumare.iqr.mod.clientele.store.clientrelation.ClientRelationEntity; + + +/** + * + * @author afatecha + */ +public class ClientRelationFindAction extends AppAction { + + // ::: vars + // + private ClientRelationEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), ClienteleErrors.clientrelation_notfound); + V.ifNull(getArgument().getEntity().getId(), ClienteleErrors.clientrelation_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + entity = findEntity(model); + } + + @Override + protected void setResultOnly() { + var result = new HashMap(); + result.put("entity", entity); + setResult(result); + } + + // ::: find + // + private ClientRelationEntity findEntity(ClientRelationEntity model) { + + var store = AppModules.clientele.getController().getClientRelationStore(); + return store.findById(getContext(), model.getId()); + } + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationListAction.java b/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationListAction.java new file mode 100644 index 0000000..3d2991c --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationListAction.java @@ -0,0 +1,149 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.clientrelation; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.LinkedList; +import java.util.Map; +// spring +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// entity +import io.kumare.iqr.mod.clientele.store.clientrelation.ClientRelationEntity; +import io.kumare.iqr.mod.clientele.store.clientrelation.ClientRelationMapBuilder; + + +/** + * + * @author afatecha + */ +public class ClientRelationListAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private final List entities = new LinkedList<>(); + + // ::: public api + // + public List getEntities() { + return entities; + } + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + } + + @Override + protected void doAction() { + + result.put("pageable", getArgument().isPageable()); + result.put("wrapped", getArgument().isWrapped()); + + if (getArgument().isPageable()) { + + var page = makePage(); + entities.addAll(page.toList()); + + if (getArgument().isWrapped()) { + result.put("page", makeWrappedPage(page)); + } else { + result.put("page", page); + } + + } else { + + var list = makeList(); + entities.addAll(list); + + if (getArgument().isWrapped()) { + result.put("list", makeWrappedList()); + } else { + result.put("list", list); + } + } + + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: page + // + private Page makePage() { + + var page = getArgument().getPageNumber(); + var size = getArgument().getPageSize(); + //var sort = getArgument().getSort(); + + var pageable = PageRequest.of(page, size); + + var store = AppModules.clientele.getController().getClientRelationStore(); + return store.getRepository().findAll(pageable); + } + + // ::: wrapped page + // + private Map makeWrappedPage(Page found) { + + var page = new HashMap(); + var content = new LinkedList(); + + wrapList(entities, content); + + page.put("size", found.getSize()); + page.put("number", found.getNumber()); + page.put("totalElements", found.getTotalElements()); + page.put("totalPages", found.getTotalPages()); + page.put("content", content); + + return page; + } + + + // ::: list + // + + private List makeList() { + + var store = AppModules.clientele.getController().getClientRelationStore(); + + return store.listAll(getContext()); + } + + // ::: wrapped list + private List makeWrappedList() { + var list = new LinkedList(); + + wrapList(entities, list); + + return list; + } + + // ::: wrapper + // + private void wrapList(List found, List output) { + + var builder = new ClientRelationMapBuilder().addListGroup(); + builder.getTypeBuilder().addMainGroup(); + builder.getStateBuilder().addMainGroup(); + + output.addAll(builder.build(getContext(), found)); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationListArgument.java b/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationListArgument.java new file mode 100644 index 0000000..b67dacd --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationListArgument.java @@ -0,0 +1,33 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.clientrelation; + +// app +import io.kumare.iqr.app.action.AppListActionArgument; +// store +import io.kumare.iqr.mod.clientele.store.clientrelation.ClientRelationEntity; + +/** + * + * @author afatecha + */ +public class ClientRelationListArgument extends AppListActionArgument { + + // ::: vars + // + + // ::: constructors + // + public ClientRelationListArgument() { + } + + public ClientRelationListArgument(ClientRelationEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationPreloadAction.java b/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationPreloadAction.java new file mode 100644 index 0000000..1a87b82 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationPreloadAction.java @@ -0,0 +1,107 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.clientrelation; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.clientele.ClienteleErrors; +// entity +import io.kumare.iqr.mod.clientele.store.clientrelation.ClientRelationEntity; +// relations +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; + +/** + * + * @author afatecha + */ +public class ClientRelationPreloadAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private Map params = new HashMap<>(); + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifEmpty(getArgument().getAction(), ClienteleErrors.clientrelation_preload_empty); + } + + @Override + protected void doAction() { + if(getArgument().getParams() != null) { + params = getArgument().getParams(); + } + + switch (getArgument().getAction()) { + case "find" -> + prepareFind(); + case "list" -> + prepareList(); + case "add" -> + prepareAdd(); + case "edit" -> + prepareEdit(); + } + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: preload + // + private void prepareAdd() { + result.put("taxons", listTaxons()); + } + + private void prepareEdit() { + var entity = findEntity(); + result.put("entity", entity); + result.put("type", entity.getType()); + result.put("state", entity.getState()); + } + + private void prepareList() { + } + + private void prepareFind() { + var entity = findEntity(); + result.put("entity", entity); + result.put("type", entity.getType()); + result.put("state", entity.getState()); + } + + // ::: queries + // + private ClientRelationEntity findEntity() { + var store = AppModules.clientele.getController().getClientRelationStore(); + + var id = (String) params.get("id"); + if(id == null && getArgument().getEntity() != null) { + id = getArgument().getEntity().getId(); + } + return store.findById(getContext(), id); + } + + public List listTaxons() { + var store = AppModules.taxonomy.getController().getTaxonStore(); + + return store.listAll(getContext()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationPreloadArgument.java b/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationPreloadArgument.java new file mode 100644 index 0000000..9d20916 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/action/clientrelation/ClientRelationPreloadArgument.java @@ -0,0 +1,26 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.action.clientrelation; + +/** + * + * @author afatecha + */ +public class ClientRelationPreloadArgument extends ClientRelationActionArgument { + + // ::: vars + // + private String action; + + // ::: fields + // + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/endpoint/rest/AbstractClientRelationRest.java b/src/main/java/io/kumare/iqr/mod/clientele/endpoint/rest/AbstractClientRelationRest.java new file mode 100644 index 0000000..30c1172 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/endpoint/rest/AbstractClientRelationRest.java @@ -0,0 +1,214 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.endpoint.rest; + +// java +import java.util.Map; +// openapi +import io.swagger.v3.oas.annotations.*; +import io.swagger.v3.oas.annotations.media.*; +import io.swagger.v3.oas.annotations.responses.*; +// spring +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +// base +import io.kumare.lib.app.api.operation.TransactionType; +import io.kumare.lib.app.api.security.PermissionReference; +// app +import io.kumare.iqr.app.endpoint.rest.AppEndpointRest; +import io.kumare.iqr.app.action.*; +// module +import io.kumare.iqr.mod.clientele.ClientelePermissions; +import io.kumare.iqr.mod.clientele.store.clientrelation.ClientRelationEntity; +import io.kumare.iqr.mod.clientele.action.clientrelation.*; + +/** +* +* @author afatecha +*/ +public abstract class AbstractClientRelationRest extends AppEndpointRest { + + // ::: DEFAULT PERMISSIONS + // + protected PermissionReference getPermission(String action, String ref, Object extra) { + switch (action) { + case null -> { + return null; + } + case "add" -> { + return ClientelePermissions.client_relation_worker.toReference(ref); + } + case "edit" -> { + return ClientelePermissions.client_relation_worker.toReference(ref); + } + case "enable" -> { + return ClientelePermissions.client_relation_manager.toReference(ref); + } + case "disable" -> { + return ClientelePermissions.client_relation_manager.toReference(ref); + } + case "delete" -> { + return ClientelePermissions.client_relation_manager.toReference(ref); + } + case "find" -> { + return ClientelePermissions.client_relation_viewer.toReference(ref); + } + case "list" -> { + return ClientelePermissions.client_relation_viewer.toReference(ref); + } + default -> { + return null; + } + } + } + + + // ::: ADD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "client relation add operation", description = "") + // + @PostMapping + public ResponseEntity add(@RequestBody ClientRelationAddArgument arg) { + + var permission = getPermission("add", null, arg); + return handle(new ClientRelationAddAction(), arg, permission, TransactionType.service); + } + + // ::: EDIT + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "client relation edit operation", description = "") + // + @PutMapping("/{id}") + public ResponseEntity edit(@PathVariable("id") String id, + @RequestBody ClientRelationEditArgument arg) { + + arg.getEntity().id(id); + + var permission = getPermission("edit", id, arg); + return handle(new ClientRelationEditAction(), arg, permission, TransactionType.service); + } + + // ::: FIND + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "client relation find operation", description = "") + // + @GetMapping("/{id}") + public ResponseEntity find(@PathVariable("id") String id, + @ModelAttribute ClientRelationActionArgument arg) { + + + arg = arg == null ? new ClientRelationActionArgument() : arg; + + arg.entity(new ClientRelationEntity(id)); + + var permission = getPermission("find", id, arg); + return handle(new ClientRelationFindAction(), arg, permission); + } + + // ::: ENABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "client relation enable operation", description = "") + // + @PutMapping("/{id}/enable") + public ResponseEntity enable(@PathVariable("id") String id) { + + var arg = new ClientRelationActionArgument(); + arg.setEntity(new ClientRelationEntity(id)); + arg.getEntity().setActive(true); + + var permission = getPermission("disable", id, arg); + return handle(new ClientRelationEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: DISABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "client relation disable operation", description = "") + // + @PutMapping("/{id}/disable") + public ResponseEntity disable(@PathVariable("id") String id) { + + var arg = new ClientRelationActionArgument(); + arg.setEntity(new ClientRelationEntity(id)); + arg.getEntity().setActive(false); + + var permission = getPermission("disable", id, arg); + return handle(new ClientRelationEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: LIST + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "client relation list operation", description = "") + // + @GetMapping + public ResponseEntity list(@ModelAttribute ClientRelationListArgument arg) { + + arg = arg == null ? new ClientRelationListArgument() : arg; + + var permission = getPermission("list", null, arg); + return handle(new ClientRelationListAction(), arg, permission); + } + + // ::: DELETE + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "client relation delete operation", description = "") + // + @DeleteMapping("/{id}") + public ResponseEntity delete(@PathVariable("id") String id) { + + var arg = new ClientRelationActionArgument(); + + arg.setEntity(new ClientRelationEntity(id)); + + var permission = getPermission("delete", id, arg); + return handle(new ClientRelationDeleteAction(), arg, permission, TransactionType.service); + } + + // ::: PRELOAD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "client relation preload operation", description = "") + // + @PostMapping("/preload") + public ResponseEntity preload(@RequestBody ClientRelationPreloadArgument arg) { + + var permission = getPermission(arg.getAction(), null, arg); + return handle(new ClientRelationPreloadAction(), arg, permission); + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/endpoint/rest/AbstractClientRest.java b/src/main/java/io/kumare/iqr/mod/clientele/endpoint/rest/AbstractClientRest.java new file mode 100644 index 0000000..45f1420 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/endpoint/rest/AbstractClientRest.java @@ -0,0 +1,315 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.endpoint.rest; + +// java +import java.util.Map; +// openapi +import io.swagger.v3.oas.annotations.*; +import io.swagger.v3.oas.annotations.media.*; +import io.swagger.v3.oas.annotations.responses.*; +// spring +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +// base +import io.kumare.lib.app.api.operation.TransactionType; +import io.kumare.lib.app.api.security.PermissionReference; +// app +import io.kumare.iqr.app.endpoint.rest.AppEndpointRest; +import io.kumare.iqr.app.action.*; +// module +import io.kumare.iqr.mod.clientele.ClientelePermissions; +import io.kumare.iqr.mod.clientele.store.client.ClientEntity; +import io.kumare.iqr.mod.clientele.action.client.*; + +/** + * + * @author afatecha + */ +public abstract class AbstractClientRest extends AppEndpointRest { + + // ::: DEFAULT PERMISSIONS + // + protected PermissionReference getPermission(String action, String ref, Object extra) { + switch (action) { + case null -> { + return null; + } + case "add" -> { + return ClientelePermissions.client_worker.toReference(ref); + } + case "edit" -> { + return ClientelePermissions.client_worker.toReference(ref); + } + case "enable" -> { + return ClientelePermissions.client_manager.toReference(ref); + } + case "disable" -> { + return ClientelePermissions.client_manager.toReference(ref); + } + case "delete" -> { + return ClientelePermissions.client_manager.toReference(ref); + } + case "find" -> { + return ClientelePermissions.client_viewer.toReference(ref); + } + case "list" -> { + return ClientelePermissions.client_viewer.toReference(ref); + } + default -> { + return null; + } + } + } + + // ::: ADD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "client add operation", description = "") + // + @PostMapping + public ResponseEntity add(@RequestBody ClientAddArgument arg) { + + var permission = getPermission("add", null, arg); + return handle(new ClientAddAction(), arg, permission, TransactionType.service); + } + + // ::: EDIT + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "client edit operation", description = "") + // + @PutMapping("/{id}") + public ResponseEntity edit(@PathVariable("id") String id, + @RequestBody ClientEditArgument arg) { + + arg.getEntity().id(id); + + var permission = getPermission("edit", id, arg); + return handle(new ClientEditAction(), arg, permission, TransactionType.service); + } + + // ::: FIND + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "client find operation", description = "") + // + @GetMapping("/{id}") + public ResponseEntity find(@PathVariable("id") String id, @ModelAttribute ClientActionArgument arg) { + + arg = arg == null ? new ClientActionArgument() : arg; + + arg.entity(new ClientEntity(id)); + + var permission = getPermission("find", id, arg); + return handle(new ClientFindAction(), arg, permission); + } + + // ::: ENABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "client enable operation", description = "") + // + @PutMapping("/{id}/enable") + public ResponseEntity enable(@PathVariable("id") String id) { + + var arg = new ClientActionArgument(); + arg.setEntity(new ClientEntity(id)); + arg.getEntity().setActive(true); + + var permission = getPermission("disable", id, arg); + return handle(new ClientEnableAction(), arg, permission, TransactionType.service); + } + */ + // ::: DISABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "client disable operation", description = "") + // + @PutMapping("/{id}/disable") + public ResponseEntity disable(@PathVariable("id") String id) { + + var arg = new ClientActionArgument(); + arg.setEntity(new ClientEntity(id)); + arg.getEntity().setActive(false); + + var permission = getPermission("disable", id, arg); + return handle(new ClientEnableAction(), arg, permission, TransactionType.service); + } + */ + // ::: LIST + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "client list operation", description = "") + // + @GetMapping + public ResponseEntity list(@ModelAttribute ClientListArgument arg) { + + arg = arg == null ? new ClientListArgument() : arg; + + var permission = getPermission("list", null, arg); + return handle(new ClientListAction(), arg, permission); + } + + // ::: DELETE + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "client delete operation", description = "") + // + @DeleteMapping("/{id}") + public ResponseEntity delete(@PathVariable("id") String id) { + + var arg = new ClientActionArgument(); + + arg.setEntity(new ClientEntity(id)); + + var permission = getPermission("delete", id, arg); + return handle(new ClientDeleteAction(), arg, permission, TransactionType.service); + } + + // ::: PRELOAD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "client preload operation", description = "") + // + @PostMapping("/preload") + public ResponseEntity preload(@RequestBody ClientPreloadArgument arg) { + + var permission = getPermission(arg.getAction(), null, arg); + return handle(new ClientPreloadAction(), arg, permission); + } + + // ::: FIND EMPLOYEE + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "employee list operation", description = "") + // + @GetMapping("/employee") + public ResponseEntity employee(@ModelAttribute ClientActionArgument arg) { + + arg = arg == null ? new ClientActionArgument() : arg; + + arg.entity(new ClientEntity()); + + var permission = getPermission("list", null, arg); + return handle(new VismaEmployeeListAction(), arg, permission); + } + + // ::: LIST PAGED + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "punch list paged", description = "") + // + @PostMapping("/punch/page") + public ResponseEntity punchPage(@RequestBody ClientListArgument arg) { + + arg = arg == null ? new ClientListArgument() : arg; + + arg.entity(new ClientEntity()); + + var permission = getPermission("", null, arg); + return handle(new VismaPunchListPageAction(), arg, permission); + } + + // ::: LIST + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "punch list", description = "") + // + @PostMapping("/punch/list") + public ResponseEntity punchList(@RequestBody VismaPunchListArgument arg) { + + arg = arg == null ? new VismaPunchListArgument() : arg; + + var permission = getPermission("", null, arg); + return handle(new VismaPunchListAction(), arg, permission); + } + + // ::: ADD PUNCH + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "punch add", description = "") + // + @PostMapping("/punch/add") + public ResponseEntity punchAdd(@RequestBody VismaAddPunchArgument arg) { + + arg = arg == null ? new VismaAddPunchArgument() : arg; + + var permission = getPermission("", null, arg); + return handle(new VismaAddPunchAction(), arg, permission); + } + + // ::: DELETE PUNCH + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "punch delete", description = "") + // + @PostMapping("/punch/delete") + public ResponseEntity punchDelete(@RequestBody VismaDeletePunchArgument arg) { + + arg = arg == null ? new VismaDeletePunchArgument() : arg; + + var permission = getPermission("", null, arg); + return handle(new VismaDeletePunchAction(), arg, permission); + } + + // ::: ADD MULTIPLE PUNCH + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "punch delete", description = "") + // + @PostMapping("/punch/multiple") + public ResponseEntity punchAddMultiple(@RequestBody VismaAddPunchMultipleArgument arg) { + + arg = arg == null ? new VismaAddPunchMultipleArgument() : arg; + + var permission = getPermission("", null, arg); + return handle(new VismaAddPunchMultipleAction(), arg, permission); + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/endpoint/rest/ClientRelationRest.java b/src/main/java/io/kumare/iqr/mod/clientele/endpoint/rest/ClientRelationRest.java new file mode 100644 index 0000000..2c0a41f --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/endpoint/rest/ClientRelationRest.java @@ -0,0 +1,24 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.endpoint.rest; + +// java +import io.swagger.v3.oas.annotations.tags.*; +// spring +import org.springframework.web.bind.annotation.*; + +/** +* +* @author afatecha +*/ + +// openapi +//@Tag(name = "client relation rest endpoint") +// +//@RestController +//@RequestMapping("/clientele/client-relations") +public class ClientRelationRest extends AbstractClientRelationRest { + + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/endpoint/rest/ClientRest.java b/src/main/java/io/kumare/iqr/mod/clientele/endpoint/rest/ClientRest.java new file mode 100644 index 0000000..30d7e16 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/endpoint/rest/ClientRest.java @@ -0,0 +1,24 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.endpoint.rest; + +// java +import io.swagger.v3.oas.annotations.tags.*; +// spring +import org.springframework.web.bind.annotation.*; + +/** +* +* @author afatecha +*/ + +// openapi +@Tag(name = "client rest endpoint") +// +@RestController +@RequestMapping("/clientele/clients") +public class ClientRest extends AbstractClientRest { + + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/endpoint/rest/ClienteleTaxonomyRest.java b/src/main/java/io/kumare/iqr/mod/clientele/endpoint/rest/ClienteleTaxonomyRest.java new file mode 100644 index 0000000..5f6004a --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/endpoint/rest/ClienteleTaxonomyRest.java @@ -0,0 +1,25 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.endpoint.rest; + +// java +import io.kumare.iqr.mod.taxonomy.endpoint.rest.AbstractTaxonRest; +import io.swagger.v3.oas.annotations.tags.*; +// spring +import org.springframework.web.bind.annotation.*; + +/** +* +* @author afatecha +*/ + +// openapi +@Tag(name = "workforce taxonomy rest endpoint") +// +@RestController +@RequestMapping("/clientele/{taxaKey}-taxons") +public class ClienteleTaxonomyRest extends AbstractTaxonRest { + + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/store/ClienteleEntities.java b/src/main/java/io/kumare/iqr/mod/clientele/store/ClienteleEntities.java new file mode 100644 index 0000000..adadab4 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/store/ClienteleEntities.java @@ -0,0 +1,102 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.store; + +// base +// base +import io.kumare.lib.app.api.module.ServiceModule; +import io.kumare.lib.app.api.store.EntityStore; +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app +import io.kumare.iqr.app.AppEngine; +import io.kumare.iqr.app.module.AppModules; +import io.kumare.iqr.mod.clientele.store.client.ClientEntity; +import io.kumare.iqr.mod.clientele.store.client.ClientStore; +import io.kumare.iqr.mod.clientele.store.clientrelation.ClientRelationEntity; +import io.kumare.iqr.mod.clientele.store.clientrelation.ClientRelationStore; + + +/** + * + * @author afatecha + */ +public enum ClienteleEntities implements EntityDescriptor { + + client(ClientEntity.class, ClientStore.class), + clientRelation(ClientRelationEntity.class, ClientRelationStore.class); + + // ::: vars + // + private final Class entityClass; + private final Class storeClass; + + // ::: constructor + // + ClienteleEntities(Class entityClass, Class storeClass) { + this.entityClass = entityClass; + this.storeClass = storeClass; + } + + // ::: entity descriptor api + // + @Override + public String getName() { + return name(); + } + + @Override + public ServiceModule getModule() { + return AppModules.clientele; + } + + @Override + public Class getEntityClass() { + return entityClass; + } + + @Override + public Class getStoreClass() { + return storeClass; + } + + @Override + public EntityStore getStore() { + return (EntityStore) AppEngine.getEngine().getInnerContext().getBean(storeClass); + } + + // ::: statics + // + public static boolean hasDescriptor(String name) { + try { + var value = valueOf(name); + return value != null; + + } catch (Throwable t) { + return false; + } + } + + public static EntityDescriptor descriptorOf(String name) { + try { + return valueOf(name); + + } catch (Throwable t) { + return null; + } + } + + public static EntityDescriptor descriptorOf(Class entityClass) { + try { + for (var i : values()) { + if (i.entityClass == entityClass) { + return i; + } + } + + } catch (Throwable t) { + } + + return null; + } +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/store/ClienteleTaxonomies.java b/src/main/java/io/kumare/iqr/mod/clientele/store/ClienteleTaxonomies.java new file mode 100644 index 0000000..054c83d --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/store/ClienteleTaxonomies.java @@ -0,0 +1,116 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.store; + +// base +import io.kumare.lib.app.api.Context; +import io.kumare.lib.v.ExceptionPrototype; +// app +import io.kumare.iqr.app.module.AppModules; +import io.kumare.iqr.mod.clientele.ClienteleErrors; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; +import java.util.List; + +/** + * + * @author administrador + */ +public enum ClienteleTaxonomies { + + clientState("client-state", ClienteleErrors.client_state_notfound), + clientRelationType("client-relation-type", ClienteleErrors.clientrelation_type_notfound), + clientRelationState("client-relation-state", ClienteleErrors.clientrelation_state_notfound); + + // ::: + // + private final String taxaKey; + private final ExceptionPrototype proto; + + // ::: constructor + // + ClienteleTaxonomies(String taxaKey, ExceptionPrototype proto) { + this.taxaKey = taxaKey; + this.proto = proto; + } + + public String getKey() { + return taxaKey; + } + + // ::: ensure + // + public TaxonEntity ensure(Context context, TaxonEntity taxon) { + return AppModules.taxonomy.getController().getTaxonStore() + .ensure(context, taxaKey, taxon, proto); + } + + public TaxonEntity ensureById(Context context, String taxonId) { + return AppModules.taxonomy.getController().getTaxonStore() + .ensureById(context, taxaKey, taxonId, proto); + } + + public TaxonEntity ensureByKey(Context context, String key) { + return AppModules.taxonomy.getController().getTaxonStore() + .ensureByKey(context, taxaKey, key, proto); + } + + public TaxonEntity ensureByValue(Context context, String value) { + return AppModules.taxonomy.getController().getTaxonStore() + .ensureByValue(context, taxaKey, value, proto); + } + + // ::: find + // + public TaxonEntity findById(Context context, String taxonId) { + return AppModules.taxonomy.getController() + .getTaxonStore() + .findById(context, taxaKey, taxonId); + } + + public TaxonEntity findByKey(Context context, String key) { + return AppModules.taxonomy.getController() + .getTaxonStore() + .findByKey(context, taxaKey, key); + } + + public TaxonEntity findByValue(Context context, String value) { + return AppModules.taxonomy.getController() + .getTaxonStore() + .findByValue(context, taxaKey, value); + } + + // ::: list + // + public List list(Context context) { + return AppModules.taxonomy.getController() + .getTaxonStore() + .listByTaxaKey(context, taxaKey); + } + + // ::: default + // + public TaxonEntity ensureDefault(Context context) { + return AppModules.taxonomy.getController() + .getTaxonStore() + .ensureDefault(context, taxaKey, proto); + } + + public TaxonEntity findDefault(Context context) { + return AppModules.taxonomy.getController() + .getTaxonStore() + .findDefault(context, taxaKey); + } + + // ::: statics + // + public static boolean hasTaxaKey(String taxaKey) { + for (var i : values()) { + if (i.getKey().equals(taxaKey)) { + return true; + } + } + + return false; + } +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/store/client/ClientData.java b/src/main/java/io/kumare/iqr/mod/clientele/store/client/ClientData.java new file mode 100644 index 0000000..491533f --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/store/client/ClientData.java @@ -0,0 +1,25 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.store.client; + +// base +import io.kumare.iqr.app.store.AppExtendedEntityData; +// imports + + +public class ClientData extends AppExtendedEntityData { + + // ::: vars + // + + + // ::: fields + // + + + // ::: fluent + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/store/client/ClientEntity.java b/src/main/java/io/kumare/iqr/mod/clientele/store/client/ClientEntity.java new file mode 100644 index 0000000..930fd10 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/store/client/ClientEntity.java @@ -0,0 +1,199 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.store.client; + +// jakarta +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.Index; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +// base +import io.kumare.lib.app.api.store.*; +import io.kumare.iqr.app.store.*; +// imports + +// relations +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; +import io.kumare.iqr.mod.authentication.store.authuser.AuthUserEntity; + +// annotations +@Entity +@Table( + name = "client", + indexes = { + @Index(name = "idx_client_external_id", columnList = "externalId"), + @Index(name = "idx_client_entity_key", columnList = "entityKey"), + @Index(name = "idx_client_alias", columnList = "alias"), + @Index(name = "idx_client_state_value", columnList = "stateValue"), + @Index(name = "idx_client_email", columnList = "email"), + @Index(name = "idx_client_phone", columnList = "phone"), + @Index(name = "idx_client_name", columnList = "name"), + @Index(name = "idx_client_description", columnList = "description") + } +) +public class ClientEntity extends AppEntity implements SupportedEntityKey { + + // ::: vars + // + private String externalId; + private String entityKey; + private String alias; + private String stateValue; + private String email; + private String phone; + private String name; + private String description; + // relations + @ManyToOne(fetch = FetchType.LAZY) + private AuthUserEntity authUser; + @ManyToOne(fetch = FetchType.LAZY) + private TaxonEntity state; + + // ::: constructors + // + public ClientEntity() { + } + + public ClientEntity(String id) { + super(id); + } + + // ::: fields + // + public String getExternalId() { + return externalId; + } + + public void setExternalId(String externalId) { + this.externalId = externalId; + } + + public String getEntityKey() { + return entityKey; + } + + public void setEntityKey(String entityKey) { + this.entityKey = entityKey; + } + + public String getAlias() { + return alias; + } + + public void setAlias(String alias) { + this.alias = alias; + } + + public String getStateValue() { + return stateValue; + } + + public void setStateValue(String stateValue) { + this.stateValue = stateValue; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + // relations + public AuthUserEntity getAuthUser() { + return authUser; + } + + public void setAuthUser(AuthUserEntity authUser) { + this.authUser = authUser; + } + + public TaxonEntity getState() { + return state; + } + + public void setState(TaxonEntity state) { + this.state = state; + } + + // ::: fluent + // + public ClientEntity externalId(String externalId) { + setExternalId(externalId); + return this; + } + + public ClientEntity entityKey(String entityKey) { + setEntityKey(entityKey); + return this; + } + + public ClientEntity alias(String alias) { + setAlias(alias); + return this; + } + + public ClientEntity stateValue(String stateValue) { + setStateValue(stateValue); + return this; + } + + public ClientEntity email(String email) { + setEmail(email); + return this; + } + + public ClientEntity phone(String phone) { + setPhone(phone); + return this; + } + + public ClientEntity name(String name) { + setName(name); + return this; + } + + public ClientEntity description(String description) { + setDescription(description); + return this; + } + + // relations + public ClientEntity authUser(AuthUserEntity authUser) { + setAuthUser(authUser); + return this; + } + + public ClientEntity state(TaxonEntity state) { + setState(state); + return this; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/store/client/ClientFields.java b/src/main/java/io/kumare/iqr/mod/clientele/store/client/ClientFields.java new file mode 100644 index 0000000..660d687 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/store/client/ClientFields.java @@ -0,0 +1,169 @@ +/* + */ +package io.kumare.iqr.mod.clientele.store.client; + +// java +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +// base +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app +import io.kumare.iqr.mod.authentication.store.AuthenticationEntities; +import io.kumare.iqr.mod.authentication.store.authuser.AuthUserFields; +import io.kumare.iqr.mod.taxonomy.store.TaxonomyEntities; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonFields; + +/** + * + * @author afatecha + */ +public enum ClientFields implements EntityFieldDescriptor { + + id(MAIN, FIND, LIST), + externalId(MAIN, FIND, LIST), + entityKey(MAIN, FIND, LIST), + alias(MAIN, FIND, LIST), + stateValue(MAIN, FIND, LIST), + email(MAIN, FIND, LIST), + phone(MAIN, FIND, LIST), + name(MAIN, FIND, LIST), + description(MAIN, FIND, LIST), + active(MAIN, FIND, LIST), + inserted(AUDIT, FIND, LIST), + inserter(AUDIT, FIND, LIST), + modified(AUDIT, FIND), + modifier(AUDIT, FIND), + deleted(AUDIT), + removed(AUDIT), + remover(AUDIT), + authUser(AuthenticationEntities.authUser, AuthUserFields.class, FIND, LIST), + state(TaxonomyEntities.taxon, TaxonFields.class, FIND, LIST); + + // ::: vars + // + private final boolean relation; + private final EntityDescriptor entityDescriptor; + private final Class enumClass; + private final List groups; + + // ::: constructors + // + ClientFields(String... groups) { + this(false, null, null, groups); + } + + ClientFields(EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this(true, entityDescriptor, enumClass, groups); + } + + ClientFields(boolean relation, EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this.relation = relation; + this.entityDescriptor = entityDescriptor; + this.enumClass = enumClass; + this.groups = groups == null ? Collections.EMPTY_LIST : Arrays.asList(groups); + } + + // ::: api + // + @Override + public String getName() { + return name(); + } + + @Override + public boolean isRelation() { + return relation; + } + + @Override + public Class getRelationEnumClass() { + return enumClass; + } + + @Override + public List getGroups() { + return groups; + } + + @Override + public EntityDescriptor getEntityDescriptor() { + return entityDescriptor; + } + + @Override + public Object fetchValue(ClientEntity entity) { + if (entity == null) { + return null; + } + + switch (this) { + case null -> { + return null; + } + case id -> { + return entity.getId(); + } + case externalId ->{ + return entity.getExternalId(); + } + case entityKey ->{ + return entity.getEntityKey(); + } + case alias ->{ + return entity.getAlias(); + } + case stateValue ->{ + return entity.getStateValue(); + } + case email ->{ + return entity.getEmail(); + } + case phone ->{ + return entity.getPhone(); + } + case name ->{ + return entity.getName(); + } + case description ->{ + return entity.getDescription(); + } + case active -> { + return entity.isActive(); + } + case inserted -> { + return entity.getInserted(); + } + case inserter -> { + return entity.getInserter(); + } + case modified -> { + return entity.getModified(); + } + case modifier -> { + return entity.getModifier(); + } + case deleted -> { + return entity.isDeleted(); + } + case removed -> { + return entity.getRemoved(); + } + case remover -> { + return entity.getRemover(); + } + case authUser ->{ + return entity.getAuthUser(); + } + case state ->{ + return entity.getState(); + } + default -> { + return null; + } + } + + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/store/client/ClientMapBuilder.java b/src/main/java/io/kumare/iqr/mod/clientele/store/client/ClientMapBuilder.java new file mode 100644 index 0000000..0fd03dc --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/store/client/ClientMapBuilder.java @@ -0,0 +1,185 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.store.client; + +// java +import java.util.List; +import java.util.Map; +// base +import io.kumare.lib.app.api.Context; +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.BaseEntityMapBuilder; +// app +import io.kumare.iqr.mod.authentication.store.authuser.AuthUserMapBuilder; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonMapBuilder; + +/** + * + * @author afatecha + */ +public class ClientMapBuilder extends BaseEntityMapBuilder { + + // ::: vars + // + private AuthUserMapBuilder authUserBuilder; + private TaxonMapBuilder stateBuilder; + + + // ::: fields + // + @Override + public ClientMapBuilder addGroup(String name, boolean cascade) { + includes.addAll(EntityFieldDescriptor.group(ClientFields.values(), name)); + + if(cascade) { + if (includes.contains(ClientFields.authUser)) { + getAuthUserBuilder().addGroup(name); + } + if (includes.contains(ClientFields.state)) { + getStateBuilder().addGroup(name); + } + } + return this; + } + + @Override + public ClientMapBuilder add(String fieldName) { + includes.add(ClientFields.valueOf(fieldName)); + return this; + } + + @Override + public ClientMapBuilder addAll(String... names) { + for (var i : names) { + includes.add(ClientFields.valueOf(i)); + } + return this; + } + + @Override + public ClientMapBuilder remove(String fieldName) { + excludes.add(ClientFields.valueOf(fieldName)); + return this; + } + + @Override + public ClientMapBuilder removeAll(String... names) { + for (var i : names) { + excludes.add(ClientFields.valueOf(i)); + } + return this; + } + + // ::: relations + // + @Override + public ClientMapBuilder addPlains(boolean cascade) { + includes.addAll(EntityFieldDescriptor.plains(ClientFields.values())); + + if(cascade) { + if (includes.contains(ClientFields.authUser)) { + getAuthUserBuilder().addPlains(); + } + if (includes.contains(ClientFields.state)) { + getStateBuilder().addPlains(); + } + } + return this; + } + + @Override + public ClientMapBuilder addRelations(boolean cascade) { + includes.addAll(EntityFieldDescriptor.relations(ClientFields.values())); + + if(cascade) { + if (includes.contains(ClientFields.authUser)) { + getAuthUserBuilder().addRelations(); + } + if (includes.contains(ClientFields.state)) { + getStateBuilder().addRelations(); + } + } + return this; + } + + // ::: auth user + // + public ClientMapBuilder addAuthUser() { + return addAuthUser(null); + } + + public ClientMapBuilder addAuthUser(String group) { + return addAuthUser(group, false); + } + + public ClientMapBuilder addAuthUser(String group, boolean cascade) { + includes.add(ClientFields.authUser); + + if (group != null) { + getAuthUserBuilder().addGroup(group); + } + + return this; + } + + public AuthUserMapBuilder getAuthUserBuilder() { + if(authUserBuilder == null) { + authUserBuilder = new AuthUserMapBuilder(); + } + return authUserBuilder; + } + + + // ::: state + // + public ClientMapBuilder addState() { + return addState(null); + } + + public ClientMapBuilder addState(String group) { + return addState(group, false); + } + + public ClientMapBuilder addState(String group, boolean cascade) { + includes.add(ClientFields.state); + + if (group != null) { + getStateBuilder().addGroup(group); + } + + return this; + } + + public TaxonMapBuilder getStateBuilder() { + if(stateBuilder == null) { + stateBuilder = new TaxonMapBuilder(); + } + return stateBuilder; + } + + // ::: internals + // + @Override + protected void internalAttachRelations(Context context, + ClientEntity entity, + List fields, + Map resultMap) { + + if (fields.contains(ClientFields.authUser)) { + attachRelation(context, + entity, + ClientFields.authUser, + getAuthUserBuilder(), + resultMap); + } + if (fields.contains(ClientFields.state)) { + attachRelation(context, + entity, + ClientFields.state, + getStateBuilder(), + resultMap); + } + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/store/client/ClientRepository.java b/src/main/java/io/kumare/iqr/mod/clientele/store/client/ClientRepository.java new file mode 100644 index 0000000..1426b7a --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/store/client/ClientRepository.java @@ -0,0 +1,18 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.store.client; + +// spring +import org.springframework.stereotype.Repository; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Repository +public interface ClientRepository extends AppKeyEntityRepository{ + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/store/client/ClientStore.java b/src/main/java/io/kumare/iqr/mod/clientele/store/client/ClientStore.java new file mode 100644 index 0000000..1caffef --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/store/client/ClientStore.java @@ -0,0 +1,35 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.store.client; + +// spring +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Service +public class ClientStore extends AppKeyEntityStore { + + // ::: vars + // + @Autowired + private ClientRepository repository; + + // ::: override + // + @Override + public ClientRepository getRepository() { + return repository; + } + + // ::: api + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/store/clientrelation/ClientRelationData.java b/src/main/java/io/kumare/iqr/mod/clientele/store/clientrelation/ClientRelationData.java new file mode 100644 index 0000000..5e538d4 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/store/clientrelation/ClientRelationData.java @@ -0,0 +1,25 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.store.clientrelation; + +// base +import io.kumare.iqr.app.store.AppExtendedEntityData; +// imports + + +public class ClientRelationData extends AppExtendedEntityData { + + // ::: vars + // + + + // ::: fields + // + + + // ::: fluent + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/store/clientrelation/ClientRelationEntity.java b/src/main/java/io/kumare/iqr/mod/clientele/store/clientrelation/ClientRelationEntity.java new file mode 100644 index 0000000..4de2183 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/store/clientrelation/ClientRelationEntity.java @@ -0,0 +1,152 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.store.clientrelation; + +// jakarta +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.Index; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +// base +import io.kumare.iqr.app.store.*; +// imports + +// relations +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; + +// annotations +@Entity +@Table( + name = "client_relation", + indexes = { + @Index(name = "idx_client_relation_type_value", columnList = "typeValue"), + @Index(name = "idx_client_relation_state_value", columnList = "stateValue"), + @Index(name = "idx_client_relation_resource_type", columnList = "resourceType"), + @Index(name = "idx_client_relation_resource_key", columnList = "resourceKey"), + @Index(name = "idx_client_relation_resource_id", columnList = "resourceId") + } +) +public class ClientRelationEntity extends AppEntity { + + // ::: vars + // + private String typeValue; + private String stateValue; + private String resourceType; + private String resourceKey; + private String resourceId; + // relations + @ManyToOne(fetch = FetchType.LAZY) + private TaxonEntity type; + @ManyToOne(fetch = FetchType.LAZY) + private TaxonEntity state; + + // ::: constructors + // + public ClientRelationEntity() { + } + + public ClientRelationEntity(String id) { + super(id); + } + + // ::: fields + // + public String getTypeValue() { + return typeValue; + } + + public void setTypeValue(String typeValue) { + this.typeValue = typeValue; + } + + public String getStateValue() { + return stateValue; + } + + public void setStateValue(String stateValue) { + this.stateValue = stateValue; + } + + public String getResourceType() { + return resourceType; + } + + public void setResourceType(String resourceType) { + this.resourceType = resourceType; + } + + public String getResourceKey() { + return resourceKey; + } + + public void setResourceKey(String resourceKey) { + this.resourceKey = resourceKey; + } + + public String getResourceId() { + return resourceId; + } + + public void setResourceId(String resourceId) { + this.resourceId = resourceId; + } + + // relations + public TaxonEntity getType() { + return type; + } + + public void setType(TaxonEntity type) { + this.type = type; + } + + public TaxonEntity getState() { + return state; + } + + public void setState(TaxonEntity state) { + this.state = state; + } + + // ::: fluent + // + public ClientRelationEntity typeValue(String typeValue) { + setTypeValue(typeValue); + return this; + } + + public ClientRelationEntity stateValue(String stateValue) { + setStateValue(stateValue); + return this; + } + + public ClientRelationEntity resourceType(String resourceType) { + setResourceType(resourceType); + return this; + } + + public ClientRelationEntity resourceKey(String resourceKey) { + setResourceKey(resourceKey); + return this; + } + + public ClientRelationEntity resourceId(String resourceId) { + setResourceId(resourceId); + return this; + } + + // relations + public ClientRelationEntity type(TaxonEntity type) { + setType(type); + return this; + } + + public ClientRelationEntity state(TaxonEntity state) { + setState(state); + return this; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/store/clientrelation/ClientRelationFields.java b/src/main/java/io/kumare/iqr/mod/clientele/store/clientrelation/ClientRelationFields.java new file mode 100644 index 0000000..9e36b96 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/store/clientrelation/ClientRelationFields.java @@ -0,0 +1,157 @@ +/* + */ +package io.kumare.iqr.mod.clientele.store.clientrelation; + +// java +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +// base +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app +import io.kumare.iqr.mod.taxonomy.store.TaxonomyEntities; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonFields; +import io.kumare.iqr.mod.taxonomy.store.TaxonomyEntities; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonFields; + +/** + * + * @author afatecha + */ +public enum ClientRelationFields implements EntityFieldDescriptor { + + id(MAIN, FIND, LIST), + typeValue(MAIN, FIND, LIST), + stateValue(MAIN, FIND, LIST), + resourceType(MAIN, FIND, LIST), + resourceKey(MAIN, FIND, LIST), + resourceId(MAIN, FIND, LIST), + active(MAIN, FIND, LIST), + inserted(AUDIT, FIND, LIST), + inserter(AUDIT, FIND, LIST), + modified(AUDIT, FIND), + modifier(AUDIT, FIND), + deleted(AUDIT), + removed(AUDIT), + remover(AUDIT), + type(TaxonomyEntities.taxon, TaxonFields.class, FIND, LIST), + state(TaxonomyEntities.taxon, TaxonFields.class, FIND, LIST); + + // ::: vars + // + private final boolean relation; + private final EntityDescriptor entityDescriptor; + private final Class enumClass; + private final List groups; + + // ::: constructors + // + ClientRelationFields(String... groups) { + this(false, null, null, groups); + } + + ClientRelationFields(EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this(true, entityDescriptor, enumClass, groups); + } + + ClientRelationFields(boolean relation, EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this.relation = relation; + this.entityDescriptor = entityDescriptor; + this.enumClass = enumClass; + this.groups = groups == null ? Collections.EMPTY_LIST : Arrays.asList(groups); + } + + // ::: api + // + @Override + public String getName() { + return name(); + } + + @Override + public boolean isRelation() { + return relation; + } + + @Override + public Class getRelationEnumClass() { + return enumClass; + } + + @Override + public List getGroups() { + return groups; + } + + @Override + public EntityDescriptor getEntityDescriptor() { + return entityDescriptor; + } + + @Override + public Object fetchValue(ClientRelationEntity entity) { + if (entity == null) { + return null; + } + + switch (this) { + case null -> { + return null; + } + case id -> { + return entity.getId(); + } + case typeValue ->{ + return entity.getTypeValue(); + } + case stateValue ->{ + return entity.getStateValue(); + } + case resourceType ->{ + return entity.getResourceType(); + } + case resourceKey ->{ + return entity.getResourceKey(); + } + case resourceId ->{ + return entity.getResourceId(); + } + case active -> { + return entity.isActive(); + } + case inserted -> { + return entity.getInserted(); + } + case inserter -> { + return entity.getInserter(); + } + case modified -> { + return entity.getModified(); + } + case modifier -> { + return entity.getModifier(); + } + case deleted -> { + return entity.isDeleted(); + } + case removed -> { + return entity.getRemoved(); + } + case remover -> { + return entity.getRemover(); + } + case type ->{ + return entity.getType(); + } + case state ->{ + return entity.getState(); + } + default -> { + return null; + } + } + + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/store/clientrelation/ClientRelationMapBuilder.java b/src/main/java/io/kumare/iqr/mod/clientele/store/clientrelation/ClientRelationMapBuilder.java new file mode 100644 index 0000000..3aff6ae --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/store/clientrelation/ClientRelationMapBuilder.java @@ -0,0 +1,184 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.store.clientrelation; + +// java +import java.util.List; +import java.util.Map; +// base +import io.kumare.lib.app.api.Context; +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.BaseEntityMapBuilder; +// app +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonMapBuilder; + +/** + * + * @author afatecha + */ +public class ClientRelationMapBuilder extends BaseEntityMapBuilder { + + // ::: vars + // + private TaxonMapBuilder typeBuilder; + private TaxonMapBuilder stateBuilder; + + + // ::: fields + // + @Override + public ClientRelationMapBuilder addGroup(String name, boolean cascade) { + includes.addAll(EntityFieldDescriptor.group(ClientRelationFields.values(), name)); + + if(cascade) { + if (includes.contains(ClientRelationFields.type)) { + getTypeBuilder().addGroup(name); + } + if (includes.contains(ClientRelationFields.state)) { + getStateBuilder().addGroup(name); + } + } + return this; + } + + @Override + public ClientRelationMapBuilder add(String fieldName) { + includes.add(ClientRelationFields.valueOf(fieldName)); + return this; + } + + @Override + public ClientRelationMapBuilder addAll(String... names) { + for (var i : names) { + includes.add(ClientRelationFields.valueOf(i)); + } + return this; + } + + @Override + public ClientRelationMapBuilder remove(String fieldName) { + excludes.add(ClientRelationFields.valueOf(fieldName)); + return this; + } + + @Override + public ClientRelationMapBuilder removeAll(String... names) { + for (var i : names) { + excludes.add(ClientRelationFields.valueOf(i)); + } + return this; + } + + // ::: relations + // + @Override + public ClientRelationMapBuilder addPlains(boolean cascade) { + includes.addAll(EntityFieldDescriptor.plains(ClientRelationFields.values())); + + if(cascade) { + if (includes.contains(ClientRelationFields.type)) { + getTypeBuilder().addPlains(); + } + if (includes.contains(ClientRelationFields.state)) { + getStateBuilder().addPlains(); + } + } + return this; + } + + @Override + public ClientRelationMapBuilder addRelations(boolean cascade) { + includes.addAll(EntityFieldDescriptor.relations(ClientRelationFields.values())); + + if(cascade) { + if (includes.contains(ClientRelationFields.type)) { + getTypeBuilder().addRelations(); + } + if (includes.contains(ClientRelationFields.state)) { + getStateBuilder().addRelations(); + } + } + return this; + } + + // ::: type + // + public ClientRelationMapBuilder addType() { + return addType(null); + } + + public ClientRelationMapBuilder addType(String group) { + return addType(group, false); + } + + public ClientRelationMapBuilder addType(String group, boolean cascade) { + includes.add(ClientRelationFields.type); + + if (group != null) { + getTypeBuilder().addGroup(group); + } + + return this; + } + + public TaxonMapBuilder getTypeBuilder() { + if(typeBuilder == null) { + typeBuilder = new TaxonMapBuilder(); + } + return typeBuilder; + } + + + // ::: state + // + public ClientRelationMapBuilder addState() { + return addState(null); + } + + public ClientRelationMapBuilder addState(String group) { + return addState(group, false); + } + + public ClientRelationMapBuilder addState(String group, boolean cascade) { + includes.add(ClientRelationFields.state); + + if (group != null) { + getStateBuilder().addGroup(group); + } + + return this; + } + + public TaxonMapBuilder getStateBuilder() { + if(stateBuilder == null) { + stateBuilder = new TaxonMapBuilder(); + } + return stateBuilder; + } + + // ::: internals + // + @Override + protected void internalAttachRelations(Context context, + ClientRelationEntity entity, + List fields, + Map resultMap) { + + if (fields.contains(ClientRelationFields.type)) { + attachRelation(context, + entity, + ClientRelationFields.type, + getTypeBuilder(), + resultMap); + } + if (fields.contains(ClientRelationFields.state)) { + attachRelation(context, + entity, + ClientRelationFields.state, + getStateBuilder(), + resultMap); + } + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/store/clientrelation/ClientRelationRepository.java b/src/main/java/io/kumare/iqr/mod/clientele/store/clientrelation/ClientRelationRepository.java new file mode 100644 index 0000000..1686ea1 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/store/clientrelation/ClientRelationRepository.java @@ -0,0 +1,18 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.store.clientrelation; + +// spring +import org.springframework.stereotype.Repository; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Repository +public interface ClientRelationRepository extends AppEntityRepository{ + +} diff --git a/src/main/java/io/kumare/iqr/mod/clientele/store/clientrelation/ClientRelationStore.java b/src/main/java/io/kumare/iqr/mod/clientele/store/clientrelation/ClientRelationStore.java new file mode 100644 index 0000000..6a731d3 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/clientele/store/clientrelation/ClientRelationStore.java @@ -0,0 +1,35 @@ +/* + * + */ +package io.kumare.iqr.mod.clientele.store.clientrelation; + +// spring +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Service +public class ClientRelationStore extends AppEntityStore { + + // ::: vars + // + @Autowired + private ClientRelationRepository repository; + + // ::: override + // + @Override + public ClientRelationRepository getRepository() { + return repository; + } + + // ::: api + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/LoyaltyConstants.java b/src/main/java/io/kumare/iqr/mod/loyalty/LoyaltyConstants.java new file mode 100644 index 0000000..be630fa --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/LoyaltyConstants.java @@ -0,0 +1,20 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty; + +// base +import io.kumare.iqr.app.AppConstants; + +/** + * + * @author afatecha + */ +public class LoyaltyConstants { + + // ::: codes + // + public static final int CODE = AppConstants.LOYALTY_CODE; + public static final String NAME = "loyalty"; + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/LoyaltyController.java b/src/main/java/io/kumare/iqr/mod/loyalty/LoyaltyController.java new file mode 100644 index 0000000..5d57e2a --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/LoyaltyController.java @@ -0,0 +1,62 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty; + +// java +import io.kumare.iqr.mod.loyalty.store.LoyaltyEntities; +import java.util.Arrays; +import java.util.List; +// base +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app +import io.kumare.iqr.app.module.AppModuleController; +// module +import io.kumare.iqr.mod.loyalty.store.subscription.SubscriptionStore; +import io.kumare.iqr.mod.loyalty.store.subscriptiontx.SubscriptionTxStore; +import io.kumare.iqr.mod.loyalty.store.subscriptiontxtag.SubscriptionTxTagStore; + +/** + * + * @author afatecha + */ +public class LoyaltyController extends AppModuleController { + + // ::: api + // + @Override + public boolean hasStore(String name) { + return LoyaltyEntities.hasDescriptor(name); + } + + @Override + public EntityDescriptor getEntityDescriptor(Class entityClass) { + return LoyaltyEntities.descriptorOf(entityClass); + } + + @Override + public EntityDescriptor getEntityDescriptor(String name) { + return LoyaltyEntities.descriptorOf(name); + } + + @Override + public List getEntityDescriptors() { + return Arrays.asList(LoyaltyEntities.values()); + } + + // ::: stores + // + public SubscriptionStore getSubscriptionStore() { + return getService(SubscriptionStore.class); + } + + public SubscriptionTxStore getSubscriptionTxStore() { + return getService(SubscriptionTxStore.class); + } + + public SubscriptionTxTagStore getSubscriptionTxTagStore() { + return getService(SubscriptionTxTagStore.class); + } + + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/LoyaltyErrors.java b/src/main/java/io/kumare/iqr/mod/loyalty/LoyaltyErrors.java new file mode 100644 index 0000000..a5e8204 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/LoyaltyErrors.java @@ -0,0 +1,102 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty; + +// java +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.transport.TransportCode; +import static io.kumare.lib.transport.Transports.code; +import io.kumare.lib.v.ExceptionPrototype; +// app +import io.kumare.iqr.app.AppException; +import io.kumare.iqr.app.endpoint.AppTransports; + + +/** + * + * @author afatecha + */ +public enum LoyaltyErrors implements ExceptionPrototype { + + + // subscription + subscription_notfound(1, code(AppTransports.http, 400)), + subscription_data_notfound(1, code(AppTransports.http, 400)), + subscription_preload_empty(1, code(AppTransports.http, 400)), + subscription_entitykey_empty(1, code(AppTransports.http, 400)), + subscription_statevalue_empty(1, code(AppTransports.http, 400)), + subscription_business_notfound(1, code(AppTransports.http, 400)), + subscription_client_notfound(1, code(AppTransports.http, 400)), + subscription_walletslot_notfound(1, code(AppTransports.http, 400)), + subscription_state_notfound(1, code(AppTransports.http, 400)), + + // subscription tx + subscriptiontx_notfound(1, code(AppTransports.http, 400)), + subscriptiontx_data_notfound(1, code(AppTransports.http, 400)), + subscriptiontx_preload_empty(1, code(AppTransports.http, 400)), + subscriptiontx_typevalue_empty(1, code(AppTransports.http, 400)), + subscriptiontx_statevalue_empty(1, code(AppTransports.http, 400)), + subscriptiontx_points_empty(1, code(AppTransports.http, 400)), + subscriptiontx_subscription_notfound(1, code(AppTransports.http, 400)), + subscriptiontx_promo_notfound(1, code(AppTransports.http, 400)), + subscriptiontx_worker_notfound(1, code(AppTransports.http, 400)), + subscriptiontx_type_notfound(1, code(AppTransports.http, 400)), + subscriptiontx_state_notfound(1, code(AppTransports.http, 400)), + subscriptiontx_capturer_notfound(1, code(AppTransports.http, 400)), + + // subscription tx tag + subscriptiontxtag_notfound(1, code(AppTransports.http, 400)), + subscriptiontxtag_data_notfound(1, code(AppTransports.http, 400)), + subscriptiontxtag_preload_empty(1, code(AppTransports.http, 400)), + subscriptiontxtag_tagkey_empty(1, code(AppTransports.http, 400)), + subscriptiontxtag_subscription_notfound(1, code(AppTransports.http, 400)), + subscriptiontxtag_transaction_notfound(1, code(AppTransports.http, 400)), + subscriptiontxtag_tag_notfound(1, code(AppTransports.http, 400)); + + // ::: vars + // + private final Map transportCodes = new HashMap(); + private final int code; + + // ::: constructors + // + private LoyaltyErrors(int code, TransportCode... codes) { + this.code = code; + if (codes != null) { + for (var i : codes) { + if (i != null) { + transportCodes.put(i.getId(), i.getCode()); + } + } + } + } + + // ::: prototype api + // + @Override + public int getCode() { + return code; + } + + @Override + public String getName() { + return name(); + } + + @Override + public Map getTransportCodes() { + return transportCodes; + } + + @Override + public RuntimeException newInstance(String msg, Throwable cause, Map extra) { + var ex = new AppException(this, msg, cause); + ex.setExtra(extra); + return ex; + } + + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/LoyaltyModule.java b/src/main/java/io/kumare/iqr/mod/loyalty/LoyaltyModule.java new file mode 100644 index 0000000..5670383 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/LoyaltyModule.java @@ -0,0 +1,37 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty; + +// java +import io.kumare.lib.base.server.spring.module.BaseModule; + + +/** + * + * @author afatecha + */ +public class LoyaltyModule extends BaseModule { + + // ::: + // + public static final LoyaltyController controller = new LoyaltyController(); + + // ::: api + // + @Override + public int getId() { + return LoyaltyConstants.CODE; + } + + @Override + public String getName() { + return LoyaltyConstants.NAME; + } + + @Override + public LoyaltyController getController() { + return controller; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/LoyaltyPermissions.java b/src/main/java/io/kumare/iqr/mod/loyalty/LoyaltyPermissions.java new file mode 100644 index 0000000..fe2f96e --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/LoyaltyPermissions.java @@ -0,0 +1,103 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty; + +// base +import io.kumare.iqr.mod.loyalty.store.LoyaltyEntities; +import io.kumare.lib.app.api.security.PermissionReference; +// app +import io.kumare.iqr.app.AppErrors; + +/** + * + * @author afatecha + */ +public enum LoyaltyPermissions { + + // subscription + //subscription_add(LoyaltyEntities.subscription), + //subscription_edit(LoyaltyEntities.subscription), + //subscription_find(LoyaltyEntities.subscription), + //subscription_enable(LoyaltyEntities.subscription), + //subscription_disable(LoyaltyEntities.subscription), + //subscription_list(LoyaltyEntities.subscription), + //subscription_delete(LoyaltyEntities.subscription), + //subscription_preload(LoyaltyEntities.subscription), + // + subscription_viewer(LoyaltyEntities.subscription), + //subscription_guest(LoyaltyEntities.subscription), + //subscription_collab(LoyaltyEntities.subscription), + subscription_worker(LoyaltyEntities.subscription), + //subscription_control(LoyaltyEntities.subscription), + subscription_manager(LoyaltyEntities.subscription), + subscription_admin(null), + subscription_system(null), + + // subscription tx + //subscription_tx_add(LoyaltyEntities.subscriptionTx), + //subscription_tx_edit(LoyaltyEntities.subscriptionTx), + //subscription_tx_find(LoyaltyEntities.subscriptionTx), + //subscription_tx_enable(LoyaltyEntities.subscriptionTx), + //subscription_tx_disable(LoyaltyEntities.subscriptionTx), + //subscription_tx_list(LoyaltyEntities.subscriptionTx), + //subscription_tx_delete(LoyaltyEntities.subscriptionTx), + //subscription_tx_preload(LoyaltyEntities.subscriptionTx), + // + subscription_tx_viewer(LoyaltyEntities.subscriptionTx), + //subscription_tx_guest(LoyaltyEntities.subscriptionTx), + //subscription_tx_collab(LoyaltyEntities.subscriptionTx), + subscription_tx_worker(LoyaltyEntities.subscriptionTx), + //subscription_tx_control(LoyaltyEntities.subscriptionTx), + subscription_tx_manager(LoyaltyEntities.subscriptionTx), + subscription_tx_admin(null), + subscription_tx_system(null), + + // subscription tx tag + //subscription_tx_tag_add(LoyaltyEntities.subscriptionTxTag), + //subscription_tx_tag_edit(LoyaltyEntities.subscriptionTxTag), + //subscription_tx_tag_find(LoyaltyEntities.subscriptionTxTag), + //subscription_tx_tag_enable(LoyaltyEntities.subscriptionTxTag), + //subscription_tx_tag_disable(LoyaltyEntities.subscriptionTxTag), + //subscription_tx_tag_list(LoyaltyEntities.subscriptionTxTag), + //subscription_tx_tag_delete(LoyaltyEntities.subscriptionTxTag), + //subscription_tx_tag_preload(LoyaltyEntities.subscriptionTxTag), + // + subscription_tx_tag_viewer(LoyaltyEntities.subscriptionTxTag), + //subscription_tx_tag_guest(LoyaltyEntities.subscriptionTxTag), + //subscription_tx_tag_collab(LoyaltyEntities.subscriptionTxTag), + subscription_tx_tag_worker(LoyaltyEntities.subscriptionTxTag), + //subscription_tx_tag_control(LoyaltyEntities.subscriptionTxTag), + subscription_tx_tag_manager(LoyaltyEntities.subscriptionTxTag), + subscription_tx_tag_admin(null), + subscription_tx_tag_system(null); + + + // ::: + // + private final LoyaltyEntities resourceType; + + LoyaltyPermissions(LoyaltyEntities entityRef) { + this.resourceType = entityRef; + } + + // + public PermissionReference toReference() { + return toReference(null); + } + + public PermissionReference toReference(String resourceKey) { + var ref = new PermissionReference() + .module(LoyaltyConstants.NAME) + .permission(name()) + .error(AppErrors.action_unauthorized); + + if (resourceType != null && resourceKey != null) { + ref.resourceType(resourceType.name()) + .resourceKey(resourceKey); + } + + return ref; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionActionArgument.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionActionArgument.java new file mode 100644 index 0000000..e7dfaa7 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionActionArgument.java @@ -0,0 +1,29 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscription; + +// base +import io.kumare.iqr.app.action.AppEntityActionArgument; +// entity +import io.kumare.iqr.mod.loyalty.store.subscription.SubscriptionEntity; + +/** + * + * @author afatecha + */ +public class SubscriptionActionArgument extends AppEntityActionArgument { + + // ::: constructors + // + public SubscriptionActionArgument() { + } + + public SubscriptionActionArgument(SubscriptionEntity entity) { + super(entity); + } + + // ::: api + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionAddAction.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionAddAction.java new file mode 100644 index 0000000..3036c41 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionAddAction.java @@ -0,0 +1,144 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscription; + +// java +import java.util.List; +// lib +import io.kumare.lib.base.server.spring.action.Actions; +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.loyalty.LoyaltyErrors; +// entity +import io.kumare.iqr.mod.loyalty.store.subscription.SubscriptionEntity; +import io.kumare.iqr.mod.clientele.store.client.ClientEntity; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; +import io.kumare.iqr.mod.pocket.store.walletslot.WalletSlotEntity; +import io.kumare.iqr.mod.loyalty.action.subscriptiontx.SubscriptionTxAddAction; +import io.kumare.iqr.mod.loyalty.action.subscriptiontx.SubscriptionTxAddArgument; + +/** + * + * @author afatecha + */ +public class SubscriptionAddAction extends AppAction> { + + // ::: vars + // + private SubscriptionEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, LoyaltyErrors.subscription_notfound); + + // relations + V.ifNull(model.getBusiness(), LoyaltyErrors.subscription_business_notfound); + V.ifNull(model.getClient(), LoyaltyErrors.subscription_client_notfound); + V.ifNull(model.getWalletSlot(), LoyaltyErrors.subscription_walletslot_notfound); + V.ifNull(model.getState(), LoyaltyErrors.subscription_state_notfound); + + // fields + V.ifEmpty(model.getEntityKey(), LoyaltyErrors.subscription_entitykey_empty); + V.ifEmpty(model.getStateValue(), LoyaltyErrors.subscription_statevalue_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + var biz = AppModules.biz.getController(); + var clientele = AppModules.clientele.getController(); + var taxonomy = AppModules.taxonomy.getController(); + var pocket = AppModules.pocket.getController(); + + var businessStore = biz.getBusinessStore(); + var clientStore = clientele.getClientStore(); + var taxonStore = taxonomy.getTaxonStore(); + var walletSlotStore = pocket.getWalletSlotStore(); + + var business = businessStore.ensure(getContext(), argModel.getBusiness(), LoyaltyErrors.subscription_business_notfound); + var client = clientStore.ensure(getContext(), argModel.getClient(), LoyaltyErrors.subscription_client_notfound); + var walletSlot = walletSlotStore.ensure(getContext(), argModel.getWalletSlot(), LoyaltyErrors.subscription_walletslot_notfound); + var state = taxonStore.ensure(getContext(), argModel.getState(), LoyaltyErrors.subscription_state_notfound); + + // model + var model = makeModel(business, client, walletSlot, state); + + // add + entity = saveEntity(model); + + // add others + addTransactions(getArgument().getTransactions()); + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private SubscriptionEntity makeModel(BusinessEntity business, ClientEntity client, WalletSlotEntity walletSlot, TaxonEntity state) { + + var argModel = getArgument().getEntity(); + var model = new SubscriptionEntity(); + + // relations + model.setBusiness(business); + model.setClient(client); + model.setWalletSlot(walletSlot); + model.setState(state); + + // fields + model.setEntityKey(argModel.getEntityKey()); + model.setStateValue(argModel.getStateValue()); + model.setActive(true); + + + + return model; + } + + // ::: save + // + private SubscriptionEntity saveEntity(SubscriptionEntity model) { + + var store = AppModules.loyalty.getController().getSubscriptionStore(); + + var saved = store.add(getContext(), model); + getContext().attach(saved.getId(), saved); + return saved; + } + + // ::: add transactions + // + private void addTransactions(List list) { + if(list != null) { + list.forEach(i->{ + i.getEntity().subscription(entity); + Actions.perform(getContext(), new SubscriptionTxAddAction(), i); + }); + } + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionAddArgument.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionAddArgument.java new file mode 100644 index 0000000..1533cb6 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionAddArgument.java @@ -0,0 +1,41 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscription; + +// java +import java.util.List; +// app +import io.kumare.iqr.mod.loyalty.store.subscription.SubscriptionEntity; +import io.kumare.iqr.mod.loyalty.action.subscriptiontx.SubscriptionTxAddArgument; + +/** + * + * @author afatecha + */ +public class SubscriptionAddArgument extends SubscriptionActionArgument { + + // ::: vars + // + private List transactions; + + // ::: constructors + // + public SubscriptionAddArgument() { + } + + public SubscriptionAddArgument(SubscriptionEntity entity) { + super(entity); + } + + // ::: fields + // + public List getTransactions() { + return transactions; + } + + public void setTransactions(List list) { + this.transactions = list; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionDeleteAction.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionDeleteAction.java new file mode 100644 index 0000000..b1175cb --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionDeleteAction.java @@ -0,0 +1,59 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscription; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.loyalty.LoyaltyErrors; +// entity +import io.kumare.iqr.mod.loyalty.store.subscription.SubscriptionEntity; + +/** + * + * @author afatecha + */ +public class SubscriptionDeleteAction extends AppAction> { + + // ::: vars + // + private SubscriptionEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), LoyaltyErrors.subscription_notfound); + V.ifNull(getArgument().getEntity().getId(), LoyaltyErrors.subscription_notfound); + } + + @Override + protected void doAction() { + + var argModel = getArgument().getEntity(); + + deleteEntity(argModel); + } + + @Override + protected void setResultOnly() { + } + + // ::: delete + // + private void deleteEntity(SubscriptionEntity model) { + + var store = AppModules.loyalty.getController().getSubscriptionStore(); + + store.deleteById(getContext(), model.getId()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionEditAction.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionEditAction.java new file mode 100644 index 0000000..b999be6 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionEditAction.java @@ -0,0 +1,95 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscription; + +// lib +import io.kumare.lib.v.V; +// app +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.loyalty.LoyaltyErrors; +// entity +import io.kumare.iqr.mod.loyalty.store.subscription.SubscriptionEntity; + +/** + * + * @author afatecha + */ +public class SubscriptionEditAction extends AppAction> { + + // ::: vars + // + private SubscriptionEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, LoyaltyErrors.subscription_notfound); + + // fields + V.ifEmpty(model.getEntityKey(), LoyaltyErrors.subscription_entitykey_empty); + V.ifEmpty(model.getStateValue(), LoyaltyErrors.subscription_statevalue_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + + var loyalty = AppModules.loyalty.getController(); + var subscriptionStore = loyalty.getSubscriptionStore(); + + // edit + entity = subscriptionStore.ensure(getContext(), argModel, LoyaltyErrors.subscription_notfound); + + editEntity(); + + entity = saveEntity(); + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private void editEntity() { + + var model = getArgument().getEntity(); + + // fields + entity.setEntityKey(V.firstNotEmpty(model.getEntityKey(), entity.getEntityKey())); + entity.setStateValue(V.firstNotEmpty(model.getStateValue(), entity.getStateValue())); + + + } + + // ::: save + // + private SubscriptionEntity saveEntity() { + + var store = AppModules.loyalty.getController().getSubscriptionStore(); + + var saved = store.edit(getContext(), entity); + getContext().attach(saved.getId(), saved); + return saved; + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionEditArgument.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionEditArgument.java new file mode 100644 index 0000000..2fc00b8 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionEditArgument.java @@ -0,0 +1,32 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscription; + +// app +import io.kumare.iqr.mod.loyalty.store.subscription.SubscriptionEntity; + +/** + * + * @author afatecha + */ +public class SubscriptionEditArgument extends SubscriptionActionArgument { + + // ::: vars + // + + + // ::: constructors + // + public SubscriptionEditArgument() { + } + + public SubscriptionEditArgument(SubscriptionEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionEnableAction.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionEnableAction.java new file mode 100644 index 0000000..597cea4 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionEnableAction.java @@ -0,0 +1,60 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscription; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.loyalty.LoyaltyErrors; +// entity +import io.kumare.iqr.mod.loyalty.store.subscription.SubscriptionEntity; + + +/** + * + * @author afatecha + */ +public class SubscriptionEnableAction extends AppAction { + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), LoyaltyErrors.subscription_notfound); + V.ifNull(getArgument().getEntity().getId(), LoyaltyErrors.subscription_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + + enableEntity(model); + } + + @Override + protected void setResultOnly() { + } + + // ::: enable + // + private void enableEntity(SubscriptionEntity model) { + + var store = AppModules.loyalty.getController().getSubscriptionStore(); + + if (getArgument().getEntity().isActive()) { + store.enableById(getContext(), model.getId()); + } else { + store.disableById(getContext(), model.getId()); + } + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionFindAction.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionFindAction.java new file mode 100644 index 0000000..e991bd9 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionFindAction.java @@ -0,0 +1,64 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscription; + +// java +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.loyalty.LoyaltyErrors; +// entity +import io.kumare.iqr.mod.loyalty.store.subscription.SubscriptionEntity; + + +/** + * + * @author afatecha + */ +public class SubscriptionFindAction extends AppAction { + + // ::: vars + // + private SubscriptionEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), LoyaltyErrors.subscription_notfound); + V.ifNull(getArgument().getEntity().getId(), LoyaltyErrors.subscription_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + entity = findEntity(model); + } + + @Override + protected void setResultOnly() { + var result = new HashMap(); + result.put("entity", entity); + setResult(result); + } + + // ::: find + // + private SubscriptionEntity findEntity(SubscriptionEntity model) { + + var store = AppModules.loyalty.getController().getSubscriptionStore(); + return store.findById(getContext(), model.getId()); + } + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionListAction.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionListAction.java new file mode 100644 index 0000000..4b3ebc0 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionListAction.java @@ -0,0 +1,151 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscription; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.LinkedList; +import java.util.Map; +// spring +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// entity +import io.kumare.iqr.mod.loyalty.store.subscription.SubscriptionEntity; +import io.kumare.iqr.mod.loyalty.store.subscription.SubscriptionMapBuilder; + + +/** + * + * @author afatecha + */ +public class SubscriptionListAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private final List entities = new LinkedList<>(); + + // ::: public api + // + public List getEntities() { + return entities; + } + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + } + + @Override + protected void doAction() { + + result.put("pageable", getArgument().isPageable()); + result.put("wrapped", getArgument().isWrapped()); + + if (getArgument().isPageable()) { + + var page = makePage(); + entities.addAll(page.toList()); + + if (getArgument().isWrapped()) { + result.put("page", makeWrappedPage(page)); + } else { + result.put("page", page); + } + + } else { + + var list = makeList(); + entities.addAll(list); + + if (getArgument().isWrapped()) { + result.put("list", makeWrappedList()); + } else { + result.put("list", list); + } + } + + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: page + // + private Page makePage() { + + var page = getArgument().getPageNumber(); + var size = getArgument().getPageSize(); + //var sort = getArgument().getSort(); + + var pageable = PageRequest.of(page, size); + + var store = AppModules.loyalty.getController().getSubscriptionStore(); + return store.getRepository().findAll(pageable); + } + + // ::: wrapped page + // + private Map makeWrappedPage(Page found) { + + var page = new HashMap(); + var content = new LinkedList(); + + wrapList(entities, content); + + page.put("size", found.getSize()); + page.put("number", found.getNumber()); + page.put("totalElements", found.getTotalElements()); + page.put("totalPages", found.getTotalPages()); + page.put("content", content); + + return page; + } + + + // ::: list + // + + private List makeList() { + + var store = AppModules.loyalty.getController().getSubscriptionStore(); + + return store.listAll(getContext()); + } + + // ::: wrapped list + private List makeWrappedList() { + var list = new LinkedList(); + + wrapList(entities, list); + + return list; + } + + // ::: wrapper + // + private void wrapList(List found, List output) { + + var builder = new SubscriptionMapBuilder().addListGroup(); + builder.getBusinessBuilder().addMainGroup(); + builder.getClientBuilder().addMainGroup(); + builder.getWalletSlotBuilder().addMainGroup(); + builder.getStateBuilder().addMainGroup(); + + output.addAll(builder.build(getContext(), found)); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionListArgument.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionListArgument.java new file mode 100644 index 0000000..aee5126 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionListArgument.java @@ -0,0 +1,33 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscription; + +// app +import io.kumare.iqr.app.action.AppListActionArgument; +// store +import io.kumare.iqr.mod.loyalty.store.subscription.SubscriptionEntity; + +/** + * + * @author afatecha + */ +public class SubscriptionListArgument extends AppListActionArgument { + + // ::: vars + // + + // ::: constructors + // + public SubscriptionListArgument() { + } + + public SubscriptionListArgument(SubscriptionEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionPreloadAction.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionPreloadAction.java new file mode 100644 index 0000000..942cb43 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionPreloadAction.java @@ -0,0 +1,132 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscription; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.loyalty.LoyaltyErrors; +// entity +import io.kumare.iqr.mod.loyalty.store.subscription.SubscriptionEntity; +// relations +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; +import io.kumare.iqr.mod.clientele.store.client.ClientEntity; +import io.kumare.iqr.mod.pocket.store.walletslot.WalletSlotEntity; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; + +/** + * + * @author afatecha + */ +public class SubscriptionPreloadAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private Map params = new HashMap<>(); + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifEmpty(getArgument().getAction(), LoyaltyErrors.subscription_preload_empty); + } + + @Override + protected void doAction() { + if(getArgument().getParams() != null) { + params = getArgument().getParams(); + } + + switch (getArgument().getAction()) { + case "find" -> + prepareFind(); + case "list" -> + prepareList(); + case "add" -> + prepareAdd(); + case "edit" -> + prepareEdit(); + } + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: preload + // + private void prepareAdd() { + result.put("taxons", listTaxons()); + result.put("walletSlots", listWalletSlots()); + result.put("clients", listClients()); + result.put("businesss", listBusinesss()); + } + + private void prepareEdit() { + var entity = findEntity(); + result.put("entity", entity); + result.put("business", entity.getBusiness()); + result.put("client", entity.getClient()); + result.put("walletSlot", entity.getWalletSlot()); + result.put("state", entity.getState()); + } + + private void prepareList() { + } + + private void prepareFind() { + var entity = findEntity(); + result.put("entity", entity); + result.put("business", entity.getBusiness()); + result.put("client", entity.getClient()); + result.put("walletSlot", entity.getWalletSlot()); + result.put("state", entity.getState()); + } + + // ::: queries + // + private SubscriptionEntity findEntity() { + var store = AppModules.loyalty.getController().getSubscriptionStore(); + + var id = (String) params.get("id"); + if(id == null && getArgument().getEntity() != null) { + id = getArgument().getEntity().getId(); + } + return store.findById(getContext(), id); + } + + public List listClients() { + var store = AppModules.clientele.getController().getClientStore(); + + return store.listAll(getContext()); + } + public List listBusinesss() { + var store = AppModules.biz.getController().getBusinessStore(); + + return store.listAll(getContext()); + } + public List listWalletSlots() { + var store = AppModules.pocket.getController().getWalletSlotStore(); + + return store.listAll(getContext()); + } + public List listTaxons() { + var store = AppModules.taxonomy.getController().getTaxonStore(); + + return store.listAll(getContext()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionPreloadArgument.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionPreloadArgument.java new file mode 100644 index 0000000..cd74182 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscription/SubscriptionPreloadArgument.java @@ -0,0 +1,26 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscription; + +/** + * + * @author afatecha + */ +public class SubscriptionPreloadArgument extends SubscriptionActionArgument { + + // ::: vars + // + private String action; + + // ::: fields + // + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxActionArgument.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxActionArgument.java new file mode 100644 index 0000000..43e79da --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxActionArgument.java @@ -0,0 +1,29 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscriptiontx; + +// base +import io.kumare.iqr.app.action.AppEntityActionArgument; +// entity +import io.kumare.iqr.mod.loyalty.store.subscriptiontx.SubscriptionTxEntity; + +/** + * + * @author afatecha + */ +public class SubscriptionTxActionArgument extends AppEntityActionArgument { + + // ::: constructors + // + public SubscriptionTxActionArgument() { + } + + public SubscriptionTxActionArgument(SubscriptionTxEntity entity) { + super(entity); + } + + // ::: api + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxAddAction.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxAddAction.java new file mode 100644 index 0000000..8697bf8 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxAddAction.java @@ -0,0 +1,154 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscriptiontx; + +// java +import java.util.List; +// lib +import io.kumare.lib.base.server.spring.action.Actions; +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.loyalty.LoyaltyErrors; +// entity +import io.kumare.iqr.mod.loyalty.store.subscriptiontx.SubscriptionTxEntity; +import io.kumare.iqr.mod.biz.store.businesspromo.BusinessPromoEntity; +import io.kumare.iqr.mod.clientele.store.client.ClientEntity; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; +import io.kumare.iqr.mod.loyalty.store.subscription.SubscriptionEntity; +import io.kumare.iqr.mod.biz.store.businessworker.BusinessWorkerEntity; +import io.kumare.iqr.mod.loyalty.action.subscriptiontxtag.SubscriptionTxTagAddAction; +import io.kumare.iqr.mod.loyalty.action.subscriptiontxtag.SubscriptionTxTagAddArgument; + +/** + * + * @author afatecha + */ +public class SubscriptionTxAddAction extends AppAction> { + + // ::: vars + // + private SubscriptionTxEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, LoyaltyErrors.subscriptiontx_notfound); + + // relations + V.ifNull(model.getSubscription(), LoyaltyErrors.subscriptiontx_subscription_notfound); + V.ifNull(model.getPromo(), LoyaltyErrors.subscriptiontx_promo_notfound); + V.ifNull(model.getWorker(), LoyaltyErrors.subscriptiontx_worker_notfound); + V.ifNull(model.getType(), LoyaltyErrors.subscriptiontx_type_notfound); + V.ifNull(model.getState(), LoyaltyErrors.subscriptiontx_state_notfound); + V.ifNull(model.getCapturer(), LoyaltyErrors.subscriptiontx_capturer_notfound); + + // fields + V.ifEmpty(model.getTypeValue(), LoyaltyErrors.subscriptiontx_typevalue_empty); + V.ifEmpty(model.getStateValue(), LoyaltyErrors.subscriptiontx_statevalue_empty); + V.ifEmpty(model.getPoints(), LoyaltyErrors.subscriptiontx_points_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + var biz = AppModules.biz.getController(); + var clientele = AppModules.clientele.getController(); + var loyalty = AppModules.loyalty.getController(); + var taxonomy = AppModules.taxonomy.getController(); + + var businessPromoStore = biz.getBusinessPromoStore(); + var businessWorkerStore = biz.getBusinessWorkerStore(); + var subscriptionStore = loyalty.getSubscriptionStore(); + var clientStore = clientele.getClientStore(); + var taxonStore = taxonomy.getTaxonStore(); + + var subscription = subscriptionStore.ensure(getContext(), argModel.getSubscription(), LoyaltyErrors.subscriptiontx_subscription_notfound); + var promo = businessPromoStore.ensure(getContext(), argModel.getPromo(), LoyaltyErrors.subscriptiontx_promo_notfound); + var worker = businessWorkerStore.ensure(getContext(), argModel.getWorker(), LoyaltyErrors.subscriptiontx_worker_notfound); + var type = taxonStore.ensure(getContext(), argModel.getType(), LoyaltyErrors.subscriptiontx_type_notfound); + var state = taxonStore.ensure(getContext(), argModel.getState(), LoyaltyErrors.subscriptiontx_state_notfound); + var capturer = clientStore.ensure(getContext(), argModel.getCapturer(), LoyaltyErrors.subscriptiontx_capturer_notfound); + + // model + var model = makeModel(subscription, promo, worker, type, state, capturer); + + // add + entity = saveEntity(model); + + // add others + addTags(getArgument().getTags()); + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private SubscriptionTxEntity makeModel(SubscriptionEntity subscription, BusinessPromoEntity promo, BusinessWorkerEntity worker, TaxonEntity type, TaxonEntity state, ClientEntity capturer) { + + var argModel = getArgument().getEntity(); + var model = new SubscriptionTxEntity(); + + // relations + model.setSubscription(subscription); + model.setPromo(promo); + model.setWorker(worker); + model.setType(type); + model.setState(state); + model.setCapturer(capturer); + + // fields + model.setTypeValue(argModel.getTypeValue()); + model.setStateValue(argModel.getStateValue()); + model.setPoints(argModel.getPoints()); + model.setActive(true); + + + + return model; + } + + // ::: save + // + private SubscriptionTxEntity saveEntity(SubscriptionTxEntity model) { + + var store = AppModules.loyalty.getController().getSubscriptionTxStore(); + + var saved = store.add(getContext(), model); + getContext().attach(saved.getId(), saved); + return saved; + } + + // ::: add tags + // + private void addTags(List list) { + if(list != null) { + list.forEach(i->{ + i.getEntity().transaction(entity); + Actions.perform(getContext(), new SubscriptionTxTagAddAction(), i); + }); + } + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxAddArgument.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxAddArgument.java new file mode 100644 index 0000000..f6601a2 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxAddArgument.java @@ -0,0 +1,41 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscriptiontx; + +// java +import java.util.List; +// app +import io.kumare.iqr.mod.loyalty.store.subscriptiontx.SubscriptionTxEntity; +import io.kumare.iqr.mod.loyalty.action.subscriptiontxtag.SubscriptionTxTagAddArgument; + +/** + * + * @author afatecha + */ +public class SubscriptionTxAddArgument extends SubscriptionTxActionArgument { + + // ::: vars + // + private List tags; + + // ::: constructors + // + public SubscriptionTxAddArgument() { + } + + public SubscriptionTxAddArgument(SubscriptionTxEntity entity) { + super(entity); + } + + // ::: fields + // + public List getTags() { + return tags; + } + + public void setTags(List list) { + this.tags = list; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxDeleteAction.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxDeleteAction.java new file mode 100644 index 0000000..0b0aa8c --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxDeleteAction.java @@ -0,0 +1,59 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscriptiontx; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.loyalty.LoyaltyErrors; +// entity +import io.kumare.iqr.mod.loyalty.store.subscriptiontx.SubscriptionTxEntity; + +/** + * + * @author afatecha + */ +public class SubscriptionTxDeleteAction extends AppAction> { + + // ::: vars + // + private SubscriptionTxEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), LoyaltyErrors.subscriptiontx_notfound); + V.ifNull(getArgument().getEntity().getId(), LoyaltyErrors.subscriptiontx_notfound); + } + + @Override + protected void doAction() { + + var argModel = getArgument().getEntity(); + + deleteEntity(argModel); + } + + @Override + protected void setResultOnly() { + } + + // ::: delete + // + private void deleteEntity(SubscriptionTxEntity model) { + + var store = AppModules.loyalty.getController().getSubscriptionTxStore(); + + store.deleteById(getContext(), model.getId()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxEditAction.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxEditAction.java new file mode 100644 index 0000000..b082a3c --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxEditAction.java @@ -0,0 +1,97 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscriptiontx; + +// lib +import io.kumare.lib.v.V; +// app +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.loyalty.LoyaltyErrors; +// entity +import io.kumare.iqr.mod.loyalty.store.subscriptiontx.SubscriptionTxEntity; + +/** + * + * @author afatecha + */ +public class SubscriptionTxEditAction extends AppAction> { + + // ::: vars + // + private SubscriptionTxEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, LoyaltyErrors.subscriptiontx_notfound); + + // fields + V.ifEmpty(model.getTypeValue(), LoyaltyErrors.subscriptiontx_typevalue_empty); + V.ifEmpty(model.getStateValue(), LoyaltyErrors.subscriptiontx_statevalue_empty); + V.ifEmpty(model.getPoints(), LoyaltyErrors.subscriptiontx_points_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + + var loyalty = AppModules.loyalty.getController(); + var subscriptionTxStore = loyalty.getSubscriptionTxStore(); + + // edit + entity = subscriptionTxStore.ensure(getContext(), argModel, LoyaltyErrors.subscriptiontx_notfound); + + editEntity(); + + entity = saveEntity(); + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private void editEntity() { + + var model = getArgument().getEntity(); + + // fields + entity.setTypeValue(V.firstNotEmpty(model.getTypeValue(), entity.getTypeValue())); + entity.setStateValue(V.firstNotEmpty(model.getStateValue(), entity.getStateValue())); + entity.setPoints(V.firstNotEmpty(model.getPoints(), entity.getPoints())); + + + } + + // ::: save + // + private SubscriptionTxEntity saveEntity() { + + var store = AppModules.loyalty.getController().getSubscriptionTxStore(); + + var saved = store.edit(getContext(), entity); + getContext().attach(saved.getId(), saved); + return saved; + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxEditArgument.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxEditArgument.java new file mode 100644 index 0000000..fceac7d --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxEditArgument.java @@ -0,0 +1,32 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscriptiontx; + +// app +import io.kumare.iqr.mod.loyalty.store.subscriptiontx.SubscriptionTxEntity; + +/** + * + * @author afatecha + */ +public class SubscriptionTxEditArgument extends SubscriptionTxActionArgument { + + // ::: vars + // + + + // ::: constructors + // + public SubscriptionTxEditArgument() { + } + + public SubscriptionTxEditArgument(SubscriptionTxEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxEnableAction.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxEnableAction.java new file mode 100644 index 0000000..9c6ed10 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxEnableAction.java @@ -0,0 +1,60 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscriptiontx; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.loyalty.LoyaltyErrors; +// entity +import io.kumare.iqr.mod.loyalty.store.subscriptiontx.SubscriptionTxEntity; + + +/** + * + * @author afatecha + */ +public class SubscriptionTxEnableAction extends AppAction { + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), LoyaltyErrors.subscriptiontx_notfound); + V.ifNull(getArgument().getEntity().getId(), LoyaltyErrors.subscriptiontx_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + + enableEntity(model); + } + + @Override + protected void setResultOnly() { + } + + // ::: enable + // + private void enableEntity(SubscriptionTxEntity model) { + + var store = AppModules.loyalty.getController().getSubscriptionTxStore(); + + if (getArgument().getEntity().isActive()) { + store.enableById(getContext(), model.getId()); + } else { + store.disableById(getContext(), model.getId()); + } + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxFindAction.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxFindAction.java new file mode 100644 index 0000000..0f3c1e9 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxFindAction.java @@ -0,0 +1,64 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscriptiontx; + +// java +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.loyalty.LoyaltyErrors; +// entity +import io.kumare.iqr.mod.loyalty.store.subscriptiontx.SubscriptionTxEntity; + + +/** + * + * @author afatecha + */ +public class SubscriptionTxFindAction extends AppAction { + + // ::: vars + // + private SubscriptionTxEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), LoyaltyErrors.subscriptiontx_notfound); + V.ifNull(getArgument().getEntity().getId(), LoyaltyErrors.subscriptiontx_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + entity = findEntity(model); + } + + @Override + protected void setResultOnly() { + var result = new HashMap(); + result.put("entity", entity); + setResult(result); + } + + // ::: find + // + private SubscriptionTxEntity findEntity(SubscriptionTxEntity model) { + + var store = AppModules.loyalty.getController().getSubscriptionTxStore(); + return store.findById(getContext(), model.getId()); + } + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxListAction.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxListAction.java new file mode 100644 index 0000000..cb41008 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxListAction.java @@ -0,0 +1,153 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscriptiontx; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.LinkedList; +import java.util.Map; +// spring +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// entity +import io.kumare.iqr.mod.loyalty.store.subscriptiontx.SubscriptionTxEntity; +import io.kumare.iqr.mod.loyalty.store.subscriptiontx.SubscriptionTxMapBuilder; + + +/** + * + * @author afatecha + */ +public class SubscriptionTxListAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private final List entities = new LinkedList<>(); + + // ::: public api + // + public List getEntities() { + return entities; + } + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + } + + @Override + protected void doAction() { + + result.put("pageable", getArgument().isPageable()); + result.put("wrapped", getArgument().isWrapped()); + + if (getArgument().isPageable()) { + + var page = makePage(); + entities.addAll(page.toList()); + + if (getArgument().isWrapped()) { + result.put("page", makeWrappedPage(page)); + } else { + result.put("page", page); + } + + } else { + + var list = makeList(); + entities.addAll(list); + + if (getArgument().isWrapped()) { + result.put("list", makeWrappedList()); + } else { + result.put("list", list); + } + } + + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: page + // + private Page makePage() { + + var page = getArgument().getPageNumber(); + var size = getArgument().getPageSize(); + //var sort = getArgument().getSort(); + + var pageable = PageRequest.of(page, size); + + var store = AppModules.loyalty.getController().getSubscriptionTxStore(); + return store.getRepository().findAll(pageable); + } + + // ::: wrapped page + // + private Map makeWrappedPage(Page found) { + + var page = new HashMap(); + var content = new LinkedList(); + + wrapList(entities, content); + + page.put("size", found.getSize()); + page.put("number", found.getNumber()); + page.put("totalElements", found.getTotalElements()); + page.put("totalPages", found.getTotalPages()); + page.put("content", content); + + return page; + } + + + // ::: list + // + + private List makeList() { + + var store = AppModules.loyalty.getController().getSubscriptionTxStore(); + + return store.listAll(getContext()); + } + + // ::: wrapped list + private List makeWrappedList() { + var list = new LinkedList(); + + wrapList(entities, list); + + return list; + } + + // ::: wrapper + // + private void wrapList(List found, List output) { + + var builder = new SubscriptionTxMapBuilder().addListGroup(); + builder.getSubscriptionBuilder().addMainGroup(); + builder.getPromoBuilder().addMainGroup(); + builder.getWorkerBuilder().addMainGroup(); + builder.getTypeBuilder().addMainGroup(); + builder.getStateBuilder().addMainGroup(); + builder.getCapturerBuilder().addMainGroup(); + + output.addAll(builder.build(getContext(), found)); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxListArgument.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxListArgument.java new file mode 100644 index 0000000..cac5c11 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxListArgument.java @@ -0,0 +1,33 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscriptiontx; + +// app +import io.kumare.iqr.app.action.AppListActionArgument; +// store +import io.kumare.iqr.mod.loyalty.store.subscriptiontx.SubscriptionTxEntity; + +/** + * + * @author afatecha + */ +public class SubscriptionTxListArgument extends AppListActionArgument { + + // ::: vars + // + + // ::: constructors + // + public SubscriptionTxListArgument() { + } + + public SubscriptionTxListArgument(SubscriptionTxEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxPreloadAction.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxPreloadAction.java new file mode 100644 index 0000000..40d51eb --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxPreloadAction.java @@ -0,0 +1,143 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscriptiontx; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.loyalty.LoyaltyErrors; +// entity +import io.kumare.iqr.mod.loyalty.store.subscriptiontx.SubscriptionTxEntity; +// relations +import io.kumare.iqr.mod.loyalty.store.subscription.SubscriptionEntity; +import io.kumare.iqr.mod.biz.store.businesspromo.BusinessPromoEntity; +import io.kumare.iqr.mod.biz.store.businessworker.BusinessWorkerEntity; +import io.kumare.iqr.mod.clientele.store.client.ClientEntity; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; + +/** + * + * @author afatecha + */ +public class SubscriptionTxPreloadAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private Map params = new HashMap<>(); + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifEmpty(getArgument().getAction(), LoyaltyErrors.subscriptiontx_preload_empty); + } + + @Override + protected void doAction() { + if(getArgument().getParams() != null) { + params = getArgument().getParams(); + } + + switch (getArgument().getAction()) { + case "find" -> + prepareFind(); + case "list" -> + prepareList(); + case "add" -> + prepareAdd(); + case "edit" -> + prepareEdit(); + } + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: preload + // + private void prepareAdd() { + result.put("taxons", listTaxons()); + result.put("businessPromos", listBusinessPromos()); + result.put("businessWorkers", listBusinessWorkers()); + result.put("clients", listClients()); + result.put("subscriptions", listSubscriptions()); + } + + private void prepareEdit() { + var entity = findEntity(); + result.put("entity", entity); + result.put("subscription", entity.getSubscription()); + result.put("promo", entity.getPromo()); + result.put("worker", entity.getWorker()); + result.put("type", entity.getType()); + result.put("state", entity.getState()); + result.put("capturer", entity.getCapturer()); + } + + private void prepareList() { + } + + private void prepareFind() { + var entity = findEntity(); + result.put("entity", entity); + result.put("subscription", entity.getSubscription()); + result.put("promo", entity.getPromo()); + result.put("worker", entity.getWorker()); + result.put("type", entity.getType()); + result.put("state", entity.getState()); + result.put("capturer", entity.getCapturer()); + } + + // ::: queries + // + private SubscriptionTxEntity findEntity() { + var store = AppModules.loyalty.getController().getSubscriptionTxStore(); + + var id = (String) params.get("id"); + if(id == null && getArgument().getEntity() != null) { + id = getArgument().getEntity().getId(); + } + return store.findById(getContext(), id); + } + + public List listBusinessPromos() { + var store = AppModules.biz.getController().getBusinessPromoStore(); + + return store.listAll(getContext()); + } + public List listClients() { + var store = AppModules.clientele.getController().getClientStore(); + + return store.listAll(getContext()); + } + public List listBusinessWorkers() { + var store = AppModules.biz.getController().getBusinessWorkerStore(); + + return store.listAll(getContext()); + } + public List listTaxons() { + var store = AppModules.taxonomy.getController().getTaxonStore(); + + return store.listAll(getContext()); + } + public List listSubscriptions() { + var store = AppModules.loyalty.getController().getSubscriptionStore(); + + return store.listAll(getContext()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxPreloadArgument.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxPreloadArgument.java new file mode 100644 index 0000000..0b02a13 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontx/SubscriptionTxPreloadArgument.java @@ -0,0 +1,26 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscriptiontx; + +/** + * + * @author afatecha + */ +public class SubscriptionTxPreloadArgument extends SubscriptionTxActionArgument { + + // ::: vars + // + private String action; + + // ::: fields + // + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagActionArgument.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagActionArgument.java new file mode 100644 index 0000000..7ce5576 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagActionArgument.java @@ -0,0 +1,29 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscriptiontxtag; + +// base +import io.kumare.iqr.app.action.AppEntityActionArgument; +// entity +import io.kumare.iqr.mod.loyalty.store.subscriptiontxtag.SubscriptionTxTagEntity; + +/** + * + * @author afatecha + */ +public class SubscriptionTxTagActionArgument extends AppEntityActionArgument { + + // ::: constructors + // + public SubscriptionTxTagActionArgument() { + } + + public SubscriptionTxTagActionArgument(SubscriptionTxTagEntity entity) { + super(entity); + } + + // ::: api + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagAddAction.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagAddAction.java new file mode 100644 index 0000000..7e2b653 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagAddAction.java @@ -0,0 +1,124 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscriptiontxtag; + + +// lib +import io.kumare.lib.base.server.spring.action.Actions; +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.loyalty.LoyaltyErrors; +// entity +import io.kumare.iqr.mod.loyalty.store.subscriptiontxtag.SubscriptionTxTagEntity; +import io.kumare.iqr.mod.biz.store.businesstag.BusinessTagEntity; +import io.kumare.iqr.mod.loyalty.store.subscriptiontx.SubscriptionTxEntity; +import io.kumare.iqr.mod.loyalty.store.subscription.SubscriptionEntity; + + +/** + * + * @author afatecha + */ +public class SubscriptionTxTagAddAction extends AppAction> { + + // ::: vars + // + private SubscriptionTxTagEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, LoyaltyErrors.subscriptiontxtag_notfound); + + // relations + V.ifNull(model.getSubscription(), LoyaltyErrors.subscriptiontxtag_subscription_notfound); + V.ifNull(model.getTransaction(), LoyaltyErrors.subscriptiontxtag_transaction_notfound); + V.ifNull(model.getTag(), LoyaltyErrors.subscriptiontxtag_tag_notfound); + + // fields + V.ifEmpty(model.getTagKey(), LoyaltyErrors.subscriptiontxtag_tagkey_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + var biz = AppModules.biz.getController(); + var loyalty = AppModules.loyalty.getController(); + + var businessTagStore = biz.getBusinessTagStore(); + var subscriptionStore = loyalty.getSubscriptionStore(); + var subscriptionTxStore = loyalty.getSubscriptionTxStore(); + + var subscription = subscriptionStore.ensure(getContext(), argModel.getSubscription(), LoyaltyErrors.subscriptiontxtag_subscription_notfound); + var transaction = subscriptionTxStore.ensure(getContext(), argModel.getTransaction(), LoyaltyErrors.subscriptiontxtag_transaction_notfound); + var tag = businessTagStore.ensure(getContext(), argModel.getTag(), LoyaltyErrors.subscriptiontxtag_tag_notfound); + + // model + var model = makeModel(subscription, transaction, tag); + + // add + entity = saveEntity(model); + + // add others + + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private SubscriptionTxTagEntity makeModel(SubscriptionEntity subscription, SubscriptionTxEntity transaction, BusinessTagEntity tag) { + + var argModel = getArgument().getEntity(); + var model = new SubscriptionTxTagEntity(); + + // relations + model.setSubscription(subscription); + model.setTransaction(transaction); + model.setTag(tag); + + // fields + model.setTagKey(argModel.getTagKey()); + model.setActive(true); + + + + return model; + } + + // ::: save + // + private SubscriptionTxTagEntity saveEntity(SubscriptionTxTagEntity model) { + + var store = AppModules.loyalty.getController().getSubscriptionTxTagStore(); + + var saved = store.add(getContext(), model); + getContext().attach(saved.getId(), saved); + return saved; + } + + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagAddArgument.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagAddArgument.java new file mode 100644 index 0000000..ae32a12 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagAddArgument.java @@ -0,0 +1,34 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscriptiontxtag; + + +// app +import io.kumare.iqr.mod.loyalty.store.subscriptiontxtag.SubscriptionTxTagEntity; + + +/** + * + * @author afatecha + */ +public class SubscriptionTxTagAddArgument extends SubscriptionTxTagActionArgument { + + // ::: vars + // + + + // ::: constructors + // + public SubscriptionTxTagAddArgument() { + } + + public SubscriptionTxTagAddArgument(SubscriptionTxTagEntity entity) { + super(entity); + } + + // ::: fields + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagDeleteAction.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagDeleteAction.java new file mode 100644 index 0000000..ce752ef --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagDeleteAction.java @@ -0,0 +1,59 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscriptiontxtag; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.loyalty.LoyaltyErrors; +// entity +import io.kumare.iqr.mod.loyalty.store.subscriptiontxtag.SubscriptionTxTagEntity; + +/** + * + * @author afatecha + */ +public class SubscriptionTxTagDeleteAction extends AppAction> { + + // ::: vars + // + private SubscriptionTxTagEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), LoyaltyErrors.subscriptiontxtag_notfound); + V.ifNull(getArgument().getEntity().getId(), LoyaltyErrors.subscriptiontxtag_notfound); + } + + @Override + protected void doAction() { + + var argModel = getArgument().getEntity(); + + deleteEntity(argModel); + } + + @Override + protected void setResultOnly() { + } + + // ::: delete + // + private void deleteEntity(SubscriptionTxTagEntity model) { + + var store = AppModules.loyalty.getController().getSubscriptionTxTagStore(); + + store.deleteById(getContext(), model.getId()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagEditAction.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagEditAction.java new file mode 100644 index 0000000..fd9c639 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagEditAction.java @@ -0,0 +1,93 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscriptiontxtag; + +// lib +import io.kumare.lib.v.V; +// app +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.loyalty.LoyaltyErrors; +// entity +import io.kumare.iqr.mod.loyalty.store.subscriptiontxtag.SubscriptionTxTagEntity; + +/** + * + * @author afatecha + */ +public class SubscriptionTxTagEditAction extends AppAction> { + + // ::: vars + // + private SubscriptionTxTagEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, LoyaltyErrors.subscriptiontxtag_notfound); + + // fields + V.ifEmpty(model.getTagKey(), LoyaltyErrors.subscriptiontxtag_tagkey_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + + var loyalty = AppModules.loyalty.getController(); + var subscriptionTxTagStore = loyalty.getSubscriptionTxTagStore(); + + // edit + entity = subscriptionTxTagStore.ensure(getContext(), argModel, LoyaltyErrors.subscriptiontxtag_notfound); + + editEntity(); + + entity = saveEntity(); + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private void editEntity() { + + var model = getArgument().getEntity(); + + // fields + entity.setTagKey(V.firstNotEmpty(model.getTagKey(), entity.getTagKey())); + + + } + + // ::: save + // + private SubscriptionTxTagEntity saveEntity() { + + var store = AppModules.loyalty.getController().getSubscriptionTxTagStore(); + + var saved = store.edit(getContext(), entity); + getContext().attach(saved.getId(), saved); + return saved; + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagEditArgument.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagEditArgument.java new file mode 100644 index 0000000..5e049a8 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagEditArgument.java @@ -0,0 +1,32 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscriptiontxtag; + +// app +import io.kumare.iqr.mod.loyalty.store.subscriptiontxtag.SubscriptionTxTagEntity; + +/** + * + * @author afatecha + */ +public class SubscriptionTxTagEditArgument extends SubscriptionTxTagActionArgument { + + // ::: vars + // + + + // ::: constructors + // + public SubscriptionTxTagEditArgument() { + } + + public SubscriptionTxTagEditArgument(SubscriptionTxTagEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagEnableAction.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagEnableAction.java new file mode 100644 index 0000000..a5b01fc --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagEnableAction.java @@ -0,0 +1,60 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscriptiontxtag; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.loyalty.LoyaltyErrors; +// entity +import io.kumare.iqr.mod.loyalty.store.subscriptiontxtag.SubscriptionTxTagEntity; + + +/** + * + * @author afatecha + */ +public class SubscriptionTxTagEnableAction extends AppAction { + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), LoyaltyErrors.subscriptiontxtag_notfound); + V.ifNull(getArgument().getEntity().getId(), LoyaltyErrors.subscriptiontxtag_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + + enableEntity(model); + } + + @Override + protected void setResultOnly() { + } + + // ::: enable + // + private void enableEntity(SubscriptionTxTagEntity model) { + + var store = AppModules.loyalty.getController().getSubscriptionTxTagStore(); + + if (getArgument().getEntity().isActive()) { + store.enableById(getContext(), model.getId()); + } else { + store.disableById(getContext(), model.getId()); + } + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagFindAction.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagFindAction.java new file mode 100644 index 0000000..6aed4a0 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagFindAction.java @@ -0,0 +1,64 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscriptiontxtag; + +// java +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.loyalty.LoyaltyErrors; +// entity +import io.kumare.iqr.mod.loyalty.store.subscriptiontxtag.SubscriptionTxTagEntity; + + +/** + * + * @author afatecha + */ +public class SubscriptionTxTagFindAction extends AppAction { + + // ::: vars + // + private SubscriptionTxTagEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), LoyaltyErrors.subscriptiontxtag_notfound); + V.ifNull(getArgument().getEntity().getId(), LoyaltyErrors.subscriptiontxtag_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + entity = findEntity(model); + } + + @Override + protected void setResultOnly() { + var result = new HashMap(); + result.put("entity", entity); + setResult(result); + } + + // ::: find + // + private SubscriptionTxTagEntity findEntity(SubscriptionTxTagEntity model) { + + var store = AppModules.loyalty.getController().getSubscriptionTxTagStore(); + return store.findById(getContext(), model.getId()); + } + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagListAction.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagListAction.java new file mode 100644 index 0000000..5d4318f --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagListAction.java @@ -0,0 +1,150 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscriptiontxtag; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.LinkedList; +import java.util.Map; +// spring +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// entity +import io.kumare.iqr.mod.loyalty.store.subscriptiontxtag.SubscriptionTxTagEntity; +import io.kumare.iqr.mod.loyalty.store.subscriptiontxtag.SubscriptionTxTagMapBuilder; + + +/** + * + * @author afatecha + */ +public class SubscriptionTxTagListAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private final List entities = new LinkedList<>(); + + // ::: public api + // + public List getEntities() { + return entities; + } + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + } + + @Override + protected void doAction() { + + result.put("pageable", getArgument().isPageable()); + result.put("wrapped", getArgument().isWrapped()); + + if (getArgument().isPageable()) { + + var page = makePage(); + entities.addAll(page.toList()); + + if (getArgument().isWrapped()) { + result.put("page", makeWrappedPage(page)); + } else { + result.put("page", page); + } + + } else { + + var list = makeList(); + entities.addAll(list); + + if (getArgument().isWrapped()) { + result.put("list", makeWrappedList()); + } else { + result.put("list", list); + } + } + + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: page + // + private Page makePage() { + + var page = getArgument().getPageNumber(); + var size = getArgument().getPageSize(); + //var sort = getArgument().getSort(); + + var pageable = PageRequest.of(page, size); + + var store = AppModules.loyalty.getController().getSubscriptionTxTagStore(); + return store.getRepository().findAll(pageable); + } + + // ::: wrapped page + // + private Map makeWrappedPage(Page found) { + + var page = new HashMap(); + var content = new LinkedList(); + + wrapList(entities, content); + + page.put("size", found.getSize()); + page.put("number", found.getNumber()); + page.put("totalElements", found.getTotalElements()); + page.put("totalPages", found.getTotalPages()); + page.put("content", content); + + return page; + } + + + // ::: list + // + + private List makeList() { + + var store = AppModules.loyalty.getController().getSubscriptionTxTagStore(); + + return store.listAll(getContext()); + } + + // ::: wrapped list + private List makeWrappedList() { + var list = new LinkedList(); + + wrapList(entities, list); + + return list; + } + + // ::: wrapper + // + private void wrapList(List found, List output) { + + var builder = new SubscriptionTxTagMapBuilder().addListGroup(); + builder.getSubscriptionBuilder().addMainGroup(); + builder.getTransactionBuilder().addMainGroup(); + builder.getTagBuilder().addMainGroup(); + + output.addAll(builder.build(getContext(), found)); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagListArgument.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagListArgument.java new file mode 100644 index 0000000..aec2055 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagListArgument.java @@ -0,0 +1,33 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscriptiontxtag; + +// app +import io.kumare.iqr.app.action.AppListActionArgument; +// store +import io.kumare.iqr.mod.loyalty.store.subscriptiontxtag.SubscriptionTxTagEntity; + +/** + * + * @author afatecha + */ +public class SubscriptionTxTagListArgument extends AppListActionArgument { + + // ::: vars + // + + // ::: constructors + // + public SubscriptionTxTagListArgument() { + } + + public SubscriptionTxTagListArgument(SubscriptionTxTagEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagPreloadAction.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagPreloadAction.java new file mode 100644 index 0000000..92657a3 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagPreloadAction.java @@ -0,0 +1,123 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscriptiontxtag; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.loyalty.LoyaltyErrors; +// entity +import io.kumare.iqr.mod.loyalty.store.subscriptiontxtag.SubscriptionTxTagEntity; +// relations +import io.kumare.iqr.mod.loyalty.store.subscription.SubscriptionEntity; +import io.kumare.iqr.mod.biz.store.businesstag.BusinessTagEntity; +import io.kumare.iqr.mod.loyalty.store.subscriptiontx.SubscriptionTxEntity; + +/** + * + * @author afatecha + */ +public class SubscriptionTxTagPreloadAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private Map params = new HashMap<>(); + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifEmpty(getArgument().getAction(), LoyaltyErrors.subscriptiontxtag_preload_empty); + } + + @Override + protected void doAction() { + if(getArgument().getParams() != null) { + params = getArgument().getParams(); + } + + switch (getArgument().getAction()) { + case "find" -> + prepareFind(); + case "list" -> + prepareList(); + case "add" -> + prepareAdd(); + case "edit" -> + prepareEdit(); + } + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: preload + // + private void prepareAdd() { + result.put("subscriptionTxs", listSubscriptionTxs()); + result.put("businessTags", listBusinessTags()); + result.put("subscriptions", listSubscriptions()); + } + + private void prepareEdit() { + var entity = findEntity(); + result.put("entity", entity); + result.put("subscription", entity.getSubscription()); + result.put("transaction", entity.getTransaction()); + result.put("tag", entity.getTag()); + } + + private void prepareList() { + } + + private void prepareFind() { + var entity = findEntity(); + result.put("entity", entity); + result.put("subscription", entity.getSubscription()); + result.put("transaction", entity.getTransaction()); + result.put("tag", entity.getTag()); + } + + // ::: queries + // + private SubscriptionTxTagEntity findEntity() { + var store = AppModules.loyalty.getController().getSubscriptionTxTagStore(); + + var id = (String) params.get("id"); + if(id == null && getArgument().getEntity() != null) { + id = getArgument().getEntity().getId(); + } + return store.findById(getContext(), id); + } + + public List listBusinessTags() { + var store = AppModules.biz.getController().getBusinessTagStore(); + + return store.listAll(getContext()); + } + public List listSubscriptionTxs() { + var store = AppModules.loyalty.getController().getSubscriptionTxStore(); + + return store.listAll(getContext()); + } + public List listSubscriptions() { + var store = AppModules.loyalty.getController().getSubscriptionStore(); + + return store.listAll(getContext()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagPreloadArgument.java b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagPreloadArgument.java new file mode 100644 index 0000000..837d66c --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/action/subscriptiontxtag/SubscriptionTxTagPreloadArgument.java @@ -0,0 +1,26 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.action.subscriptiontxtag; + +/** + * + * @author afatecha + */ +public class SubscriptionTxTagPreloadArgument extends SubscriptionTxTagActionArgument { + + // ::: vars + // + private String action; + + // ::: fields + // + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/endpoint/rest/AbstractSubscriptionRest.java b/src/main/java/io/kumare/iqr/mod/loyalty/endpoint/rest/AbstractSubscriptionRest.java new file mode 100644 index 0000000..4357df8 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/endpoint/rest/AbstractSubscriptionRest.java @@ -0,0 +1,214 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.endpoint.rest; + +// java +import java.util.Map; +// openapi +import io.swagger.v3.oas.annotations.*; +import io.swagger.v3.oas.annotations.media.*; +import io.swagger.v3.oas.annotations.responses.*; +// spring +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +// base +import io.kumare.lib.app.api.operation.TransactionType; +import io.kumare.lib.app.api.security.PermissionReference; +// app +import io.kumare.iqr.app.endpoint.rest.AppEndpointRest; +import io.kumare.iqr.app.action.*; +// module +import io.kumare.iqr.mod.loyalty.LoyaltyPermissions; +import io.kumare.iqr.mod.loyalty.store.subscription.SubscriptionEntity; +import io.kumare.iqr.mod.loyalty.action.subscription.*; + +/** +* +* @author afatecha +*/ +public abstract class AbstractSubscriptionRest extends AppEndpointRest { + + // ::: DEFAULT PERMISSIONS + // + protected PermissionReference getPermission(String action, String ref, Object extra) { + switch (action) { + case null -> { + return null; + } + case "add" -> { + return LoyaltyPermissions.subscription_worker.toReference(ref); + } + case "edit" -> { + return LoyaltyPermissions.subscription_worker.toReference(ref); + } + case "enable" -> { + return LoyaltyPermissions.subscription_manager.toReference(ref); + } + case "disable" -> { + return LoyaltyPermissions.subscription_manager.toReference(ref); + } + case "delete" -> { + return LoyaltyPermissions.subscription_manager.toReference(ref); + } + case "find" -> { + return LoyaltyPermissions.subscription_viewer.toReference(ref); + } + case "list" -> { + return LoyaltyPermissions.subscription_viewer.toReference(ref); + } + default -> { + return null; + } + } + } + + + // ::: ADD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "subscription add operation", description = "") + // + @PostMapping + public ResponseEntity add(@RequestBody SubscriptionAddArgument arg) { + + var permission = getPermission("add", null, arg); + return handle(new SubscriptionAddAction(), arg, permission, TransactionType.service); + } + + // ::: EDIT + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "subscription edit operation", description = "") + // + @PutMapping("/{id}") + public ResponseEntity edit(@PathVariable("id") String id, + @RequestBody SubscriptionEditArgument arg) { + + arg.getEntity().id(id); + + var permission = getPermission("edit", id, arg); + return handle(new SubscriptionEditAction(), arg, permission, TransactionType.service); + } + + // ::: FIND + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "subscription find operation", description = "") + // + @GetMapping("/{id}") + public ResponseEntity find(@PathVariable("id") String id, + @ModelAttribute SubscriptionActionArgument arg) { + + + arg = arg == null ? new SubscriptionActionArgument() : arg; + + arg.entity(new SubscriptionEntity(id)); + + var permission = getPermission("find", id, arg); + return handle(new SubscriptionFindAction(), arg, permission); + } + + // ::: ENABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "subscription enable operation", description = "") + // + @PutMapping("/{id}/enable") + public ResponseEntity enable(@PathVariable("id") String id) { + + var arg = new SubscriptionActionArgument(); + arg.setEntity(new SubscriptionEntity(id)); + arg.getEntity().setActive(true); + + var permission = getPermission("disable", id, arg); + return handle(new SubscriptionEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: DISABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "subscription disable operation", description = "") + // + @PutMapping("/{id}/disable") + public ResponseEntity disable(@PathVariable("id") String id) { + + var arg = new SubscriptionActionArgument(); + arg.setEntity(new SubscriptionEntity(id)); + arg.getEntity().setActive(false); + + var permission = getPermission("disable", id, arg); + return handle(new SubscriptionEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: LIST + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "subscription list operation", description = "") + // + @GetMapping + public ResponseEntity list(@ModelAttribute SubscriptionListArgument arg) { + + arg = arg == null ? new SubscriptionListArgument() : arg; + + var permission = getPermission("list", null, arg); + return handle(new SubscriptionListAction(), arg, permission); + } + + // ::: DELETE + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "subscription delete operation", description = "") + // + @DeleteMapping("/{id}") + public ResponseEntity delete(@PathVariable("id") String id) { + + var arg = new SubscriptionActionArgument(); + + arg.setEntity(new SubscriptionEntity(id)); + + var permission = getPermission("delete", id, arg); + return handle(new SubscriptionDeleteAction(), arg, permission, TransactionType.service); + } + + // ::: PRELOAD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "subscription preload operation", description = "") + // + @PostMapping("/preload") + public ResponseEntity preload(@RequestBody SubscriptionPreloadArgument arg) { + + var permission = getPermission(arg.getAction(), null, arg); + return handle(new SubscriptionPreloadAction(), arg, permission); + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/endpoint/rest/AbstractSubscriptionTxRest.java b/src/main/java/io/kumare/iqr/mod/loyalty/endpoint/rest/AbstractSubscriptionTxRest.java new file mode 100644 index 0000000..838f10b --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/endpoint/rest/AbstractSubscriptionTxRest.java @@ -0,0 +1,214 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.endpoint.rest; + +// java +import java.util.Map; +// openapi +import io.swagger.v3.oas.annotations.*; +import io.swagger.v3.oas.annotations.media.*; +import io.swagger.v3.oas.annotations.responses.*; +// spring +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +// base +import io.kumare.lib.app.api.operation.TransactionType; +import io.kumare.lib.app.api.security.PermissionReference; +// app +import io.kumare.iqr.app.endpoint.rest.AppEndpointRest; +import io.kumare.iqr.app.action.*; +// module +import io.kumare.iqr.mod.loyalty.LoyaltyPermissions; +import io.kumare.iqr.mod.loyalty.store.subscriptiontx.SubscriptionTxEntity; +import io.kumare.iqr.mod.loyalty.action.subscriptiontx.*; + +/** +* +* @author afatecha +*/ +public abstract class AbstractSubscriptionTxRest extends AppEndpointRest { + + // ::: DEFAULT PERMISSIONS + // + protected PermissionReference getPermission(String action, String ref, Object extra) { + switch (action) { + case null -> { + return null; + } + case "add" -> { + return LoyaltyPermissions.subscription_tx_worker.toReference(ref); + } + case "edit" -> { + return LoyaltyPermissions.subscription_tx_worker.toReference(ref); + } + case "enable" -> { + return LoyaltyPermissions.subscription_tx_manager.toReference(ref); + } + case "disable" -> { + return LoyaltyPermissions.subscription_tx_manager.toReference(ref); + } + case "delete" -> { + return LoyaltyPermissions.subscription_tx_manager.toReference(ref); + } + case "find" -> { + return LoyaltyPermissions.subscription_tx_viewer.toReference(ref); + } + case "list" -> { + return LoyaltyPermissions.subscription_tx_viewer.toReference(ref); + } + default -> { + return null; + } + } + } + + + // ::: ADD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "subscription tx add operation", description = "") + // + @PostMapping + public ResponseEntity add(@RequestBody SubscriptionTxAddArgument arg) { + + var permission = getPermission("add", null, arg); + return handle(new SubscriptionTxAddAction(), arg, permission, TransactionType.service); + } + + // ::: EDIT + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "subscription tx edit operation", description = "") + // + @PutMapping("/{id}") + public ResponseEntity edit(@PathVariable("id") String id, + @RequestBody SubscriptionTxEditArgument arg) { + + arg.getEntity().id(id); + + var permission = getPermission("edit", id, arg); + return handle(new SubscriptionTxEditAction(), arg, permission, TransactionType.service); + } + + // ::: FIND + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "subscription tx find operation", description = "") + // + @GetMapping("/{id}") + public ResponseEntity find(@PathVariable("id") String id, + @ModelAttribute SubscriptionTxActionArgument arg) { + + + arg = arg == null ? new SubscriptionTxActionArgument() : arg; + + arg.entity(new SubscriptionTxEntity(id)); + + var permission = getPermission("find", id, arg); + return handle(new SubscriptionTxFindAction(), arg, permission); + } + + // ::: ENABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "subscription tx enable operation", description = "") + // + @PutMapping("/{id}/enable") + public ResponseEntity enable(@PathVariable("id") String id) { + + var arg = new SubscriptionTxActionArgument(); + arg.setEntity(new SubscriptionTxEntity(id)); + arg.getEntity().setActive(true); + + var permission = getPermission("disable", id, arg); + return handle(new SubscriptionTxEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: DISABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "subscription tx disable operation", description = "") + // + @PutMapping("/{id}/disable") + public ResponseEntity disable(@PathVariable("id") String id) { + + var arg = new SubscriptionTxActionArgument(); + arg.setEntity(new SubscriptionTxEntity(id)); + arg.getEntity().setActive(false); + + var permission = getPermission("disable", id, arg); + return handle(new SubscriptionTxEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: LIST + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "subscription tx list operation", description = "") + // + @GetMapping + public ResponseEntity list(@ModelAttribute SubscriptionTxListArgument arg) { + + arg = arg == null ? new SubscriptionTxListArgument() : arg; + + var permission = getPermission("list", null, arg); + return handle(new SubscriptionTxListAction(), arg, permission); + } + + // ::: DELETE + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "subscription tx delete operation", description = "") + // + @DeleteMapping("/{id}") + public ResponseEntity delete(@PathVariable("id") String id) { + + var arg = new SubscriptionTxActionArgument(); + + arg.setEntity(new SubscriptionTxEntity(id)); + + var permission = getPermission("delete", id, arg); + return handle(new SubscriptionTxDeleteAction(), arg, permission, TransactionType.service); + } + + // ::: PRELOAD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "subscription tx preload operation", description = "") + // + @PostMapping("/preload") + public ResponseEntity preload(@RequestBody SubscriptionTxPreloadArgument arg) { + + var permission = getPermission(arg.getAction(), null, arg); + return handle(new SubscriptionTxPreloadAction(), arg, permission); + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/endpoint/rest/AbstractSubscriptionTxTagRest.java b/src/main/java/io/kumare/iqr/mod/loyalty/endpoint/rest/AbstractSubscriptionTxTagRest.java new file mode 100644 index 0000000..d93aab6 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/endpoint/rest/AbstractSubscriptionTxTagRest.java @@ -0,0 +1,214 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.endpoint.rest; + +// java +import java.util.Map; +// openapi +import io.swagger.v3.oas.annotations.*; +import io.swagger.v3.oas.annotations.media.*; +import io.swagger.v3.oas.annotations.responses.*; +// spring +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +// base +import io.kumare.lib.app.api.operation.TransactionType; +import io.kumare.lib.app.api.security.PermissionReference; +// app +import io.kumare.iqr.app.endpoint.rest.AppEndpointRest; +import io.kumare.iqr.app.action.*; +// module +import io.kumare.iqr.mod.loyalty.LoyaltyPermissions; +import io.kumare.iqr.mod.loyalty.store.subscriptiontxtag.SubscriptionTxTagEntity; +import io.kumare.iqr.mod.loyalty.action.subscriptiontxtag.*; + +/** +* +* @author afatecha +*/ +public abstract class AbstractSubscriptionTxTagRest extends AppEndpointRest { + + // ::: DEFAULT PERMISSIONS + // + protected PermissionReference getPermission(String action, String ref, Object extra) { + switch (action) { + case null -> { + return null; + } + case "add" -> { + return LoyaltyPermissions.subscription_tx_tag_worker.toReference(ref); + } + case "edit" -> { + return LoyaltyPermissions.subscription_tx_tag_worker.toReference(ref); + } + case "enable" -> { + return LoyaltyPermissions.subscription_tx_tag_manager.toReference(ref); + } + case "disable" -> { + return LoyaltyPermissions.subscription_tx_tag_manager.toReference(ref); + } + case "delete" -> { + return LoyaltyPermissions.subscription_tx_tag_manager.toReference(ref); + } + case "find" -> { + return LoyaltyPermissions.subscription_tx_tag_viewer.toReference(ref); + } + case "list" -> { + return LoyaltyPermissions.subscription_tx_tag_viewer.toReference(ref); + } + default -> { + return null; + } + } + } + + + // ::: ADD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "subscription tx tag add operation", description = "") + // + @PostMapping + public ResponseEntity add(@RequestBody SubscriptionTxTagAddArgument arg) { + + var permission = getPermission("add", null, arg); + return handle(new SubscriptionTxTagAddAction(), arg, permission, TransactionType.service); + } + + // ::: EDIT + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "subscription tx tag edit operation", description = "") + // + @PutMapping("/{id}") + public ResponseEntity edit(@PathVariable("id") String id, + @RequestBody SubscriptionTxTagEditArgument arg) { + + arg.getEntity().id(id); + + var permission = getPermission("edit", id, arg); + return handle(new SubscriptionTxTagEditAction(), arg, permission, TransactionType.service); + } + + // ::: FIND + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "subscription tx tag find operation", description = "") + // + @GetMapping("/{id}") + public ResponseEntity find(@PathVariable("id") String id, + @ModelAttribute SubscriptionTxTagActionArgument arg) { + + + arg = arg == null ? new SubscriptionTxTagActionArgument() : arg; + + arg.entity(new SubscriptionTxTagEntity(id)); + + var permission = getPermission("find", id, arg); + return handle(new SubscriptionTxTagFindAction(), arg, permission); + } + + // ::: ENABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "subscription tx tag enable operation", description = "") + // + @PutMapping("/{id}/enable") + public ResponseEntity enable(@PathVariable("id") String id) { + + var arg = new SubscriptionTxTagActionArgument(); + arg.setEntity(new SubscriptionTxTagEntity(id)); + arg.getEntity().setActive(true); + + var permission = getPermission("disable", id, arg); + return handle(new SubscriptionTxTagEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: DISABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "subscription tx tag disable operation", description = "") + // + @PutMapping("/{id}/disable") + public ResponseEntity disable(@PathVariable("id") String id) { + + var arg = new SubscriptionTxTagActionArgument(); + arg.setEntity(new SubscriptionTxTagEntity(id)); + arg.getEntity().setActive(false); + + var permission = getPermission("disable", id, arg); + return handle(new SubscriptionTxTagEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: LIST + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "subscription tx tag list operation", description = "") + // + @GetMapping + public ResponseEntity list(@ModelAttribute SubscriptionTxTagListArgument arg) { + + arg = arg == null ? new SubscriptionTxTagListArgument() : arg; + + var permission = getPermission("list", null, arg); + return handle(new SubscriptionTxTagListAction(), arg, permission); + } + + // ::: DELETE + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "subscription tx tag delete operation", description = "") + // + @DeleteMapping("/{id}") + public ResponseEntity delete(@PathVariable("id") String id) { + + var arg = new SubscriptionTxTagActionArgument(); + + arg.setEntity(new SubscriptionTxTagEntity(id)); + + var permission = getPermission("delete", id, arg); + return handle(new SubscriptionTxTagDeleteAction(), arg, permission, TransactionType.service); + } + + // ::: PRELOAD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "subscription tx tag preload operation", description = "") + // + @PostMapping("/preload") + public ResponseEntity preload(@RequestBody SubscriptionTxTagPreloadArgument arg) { + + var permission = getPermission(arg.getAction(), null, arg); + return handle(new SubscriptionTxTagPreloadAction(), arg, permission); + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/endpoint/rest/LoyaltyTaxonomyRest.java b/src/main/java/io/kumare/iqr/mod/loyalty/endpoint/rest/LoyaltyTaxonomyRest.java new file mode 100644 index 0000000..2ddc7da --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/endpoint/rest/LoyaltyTaxonomyRest.java @@ -0,0 +1,25 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.endpoint.rest; + +// java +import io.kumare.iqr.mod.taxonomy.endpoint.rest.AbstractTaxonRest; +import io.swagger.v3.oas.annotations.tags.*; +// spring +import org.springframework.web.bind.annotation.*; + +/** +* +* @author afatecha +*/ + +// openapi +@Tag(name = "workforce taxonomy rest endpoint") +// +@RestController +@RequestMapping("/loyalty/{taxaKey}-taxons") +public class LoyaltyTaxonomyRest extends AbstractTaxonRest { + + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/endpoint/rest/SubscriptionRest.java b/src/main/java/io/kumare/iqr/mod/loyalty/endpoint/rest/SubscriptionRest.java new file mode 100644 index 0000000..c841b8e --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/endpoint/rest/SubscriptionRest.java @@ -0,0 +1,24 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.endpoint.rest; + +// java +import io.swagger.v3.oas.annotations.tags.*; +// spring +import org.springframework.web.bind.annotation.*; + +/** +* +* @author afatecha +*/ + +// openapi +//@Tag(name = "subscription rest endpoint") +// +//@RestController +//@RequestMapping("/loyalty/subscriptions") +public class SubscriptionRest extends AbstractSubscriptionRest { + + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/endpoint/rest/SubscriptionTxRest.java b/src/main/java/io/kumare/iqr/mod/loyalty/endpoint/rest/SubscriptionTxRest.java new file mode 100644 index 0000000..c429ce4 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/endpoint/rest/SubscriptionTxRest.java @@ -0,0 +1,24 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.endpoint.rest; + +// java +import io.swagger.v3.oas.annotations.tags.*; +// spring +import org.springframework.web.bind.annotation.*; + +/** +* +* @author afatecha +*/ + +// openapi +//@Tag(name = "subscription tx rest endpoint") +// +//@RestController +//@RequestMapping("/loyalty/subscription-txs") +public class SubscriptionTxRest extends AbstractSubscriptionTxRest { + + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/endpoint/rest/SubscriptionTxTagRest.java b/src/main/java/io/kumare/iqr/mod/loyalty/endpoint/rest/SubscriptionTxTagRest.java new file mode 100644 index 0000000..1bd8507 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/endpoint/rest/SubscriptionTxTagRest.java @@ -0,0 +1,24 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.endpoint.rest; + +// java +import io.swagger.v3.oas.annotations.tags.*; +// spring +import org.springframework.web.bind.annotation.*; + +/** +* +* @author afatecha +*/ + +// openapi +//@Tag(name = "subscription tx tag rest endpoint") +// +//@RestController +//@RequestMapping("/loyalty/subscription-tx-tags") +public class SubscriptionTxTagRest extends AbstractSubscriptionTxTagRest { + + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/store/LoyaltyEntities.java b/src/main/java/io/kumare/iqr/mod/loyalty/store/LoyaltyEntities.java new file mode 100644 index 0000000..87bc0ff --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/store/LoyaltyEntities.java @@ -0,0 +1,105 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.store; + +// base +// base +import io.kumare.lib.app.api.module.ServiceModule; +import io.kumare.lib.app.api.store.EntityStore; +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app +import io.kumare.iqr.app.AppEngine; +import io.kumare.iqr.app.module.AppModules; +import io.kumare.iqr.mod.loyalty.store.subscription.SubscriptionEntity; +import io.kumare.iqr.mod.loyalty.store.subscription.SubscriptionStore; +import io.kumare.iqr.mod.loyalty.store.subscriptiontx.SubscriptionTxEntity; +import io.kumare.iqr.mod.loyalty.store.subscriptiontx.SubscriptionTxStore; +import io.kumare.iqr.mod.loyalty.store.subscriptiontxtag.SubscriptionTxTagEntity; +import io.kumare.iqr.mod.loyalty.store.subscriptiontxtag.SubscriptionTxTagStore; + + +/** + * + * @author afatecha + */ +public enum LoyaltyEntities implements EntityDescriptor { + + subscription(SubscriptionEntity.class, SubscriptionStore.class), + subscriptionTx(SubscriptionTxEntity.class, SubscriptionTxStore.class), + subscriptionTxTag(SubscriptionTxTagEntity.class, SubscriptionTxTagStore.class); + + // ::: vars + // + private final Class entityClass; + private final Class storeClass; + + // ::: constructor + // + LoyaltyEntities(Class entityClass, Class storeClass) { + this.entityClass = entityClass; + this.storeClass = storeClass; + } + + // ::: entity descriptor api + // + @Override + public String getName() { + return name(); + } + + @Override + public ServiceModule getModule() { + return AppModules.loyalty; + } + + @Override + public Class getEntityClass() { + return entityClass; + } + + @Override + public Class getStoreClass() { + return storeClass; + } + + @Override + public EntityStore getStore() { + return (EntityStore) AppEngine.getEngine().getInnerContext().getBean(storeClass); + } + + // ::: statics + // + public static boolean hasDescriptor(String name) { + try { + var value = valueOf(name); + return value != null; + + } catch (Throwable t) { + return false; + } + } + + public static EntityDescriptor descriptorOf(String name) { + try { + return valueOf(name); + + } catch (Throwable t) { + return null; + } + } + + public static EntityDescriptor descriptorOf(Class entityClass) { + try { + for (var i : values()) { + if (i.entityClass == entityClass) { + return i; + } + } + + } catch (Throwable t) { + } + + return null; + } +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/store/LoyaltyTaxonomies.java b/src/main/java/io/kumare/iqr/mod/loyalty/store/LoyaltyTaxonomies.java new file mode 100644 index 0000000..b4e64d1 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/store/LoyaltyTaxonomies.java @@ -0,0 +1,116 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.store; + +// base +import io.kumare.lib.app.api.Context; +import io.kumare.lib.v.ExceptionPrototype; +// app +import io.kumare.iqr.app.module.AppModules; +import io.kumare.iqr.mod.loyalty.LoyaltyErrors; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; +import java.util.List; + +/** + * + * @author administrador + */ +public enum LoyaltyTaxonomies { + + susbcriptionState("subscription-state", LoyaltyErrors.subscription_state_notfound), + susbcriptionTxType("subscription-tx-type", LoyaltyErrors.subscriptiontx_type_notfound), + susbcriptionTxState("subscription-tx-state", LoyaltyErrors.subscriptiontx_state_notfound); + + // ::: + // + private final String taxaKey; + private final ExceptionPrototype proto; + + // ::: constructor + // + LoyaltyTaxonomies(String taxaKey, ExceptionPrototype proto) { + this.taxaKey = taxaKey; + this.proto = proto; + } + + public String getKey() { + return taxaKey; + } + + // ::: ensure + // + public TaxonEntity ensure(Context context, TaxonEntity taxon) { + return AppModules.taxonomy.getController().getTaxonStore() + .ensure(context, taxaKey, taxon, proto); + } + + public TaxonEntity ensureById(Context context, String taxonId) { + return AppModules.taxonomy.getController().getTaxonStore() + .ensureById(context, taxaKey, taxonId, proto); + } + + public TaxonEntity ensureByKey(Context context, String key) { + return AppModules.taxonomy.getController().getTaxonStore() + .ensureByKey(context, taxaKey, key, proto); + } + + public TaxonEntity ensureByValue(Context context, String value) { + return AppModules.taxonomy.getController().getTaxonStore() + .ensureByValue(context, taxaKey, value, proto); + } + + // ::: find + // + public TaxonEntity findById(Context context, String taxonId) { + return AppModules.taxonomy.getController() + .getTaxonStore() + .findById(context, taxaKey, taxonId); + } + + public TaxonEntity findByKey(Context context, String key) { + return AppModules.taxonomy.getController() + .getTaxonStore() + .findByKey(context, taxaKey, key); + } + + public TaxonEntity findByValue(Context context, String value) { + return AppModules.taxonomy.getController() + .getTaxonStore() + .findByValue(context, taxaKey, value); + } + + // ::: list + // + public List list(Context context) { + return AppModules.taxonomy.getController() + .getTaxonStore() + .listByTaxaKey(context, taxaKey); + } + + // ::: default + // + public TaxonEntity ensureDefault(Context context) { + return AppModules.taxonomy.getController() + .getTaxonStore() + .ensureDefault(context, taxaKey, proto); + } + + public TaxonEntity findDefault(Context context) { + return AppModules.taxonomy.getController() + .getTaxonStore() + .findDefault(context, taxaKey); + } + + // ::: statics + // + public static boolean hasTaxaKey(String taxaKey) { + for (var i : values()) { + if (i.getKey().equals(taxaKey)) { + return true; + } + } + + return false; + } +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/store/subscription/SubscriptionData.java b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscription/SubscriptionData.java new file mode 100644 index 0000000..2dce10a --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscription/SubscriptionData.java @@ -0,0 +1,25 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.store.subscription; + +// base +import io.kumare.iqr.app.store.AppExtendedEntityData; +// imports + + +public class SubscriptionData extends AppExtendedEntityData { + + // ::: vars + // + + + // ::: fields + // + + + // ::: fluent + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/store/subscription/SubscriptionEntity.java b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscription/SubscriptionEntity.java new file mode 100644 index 0000000..a84fb66 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscription/SubscriptionEntity.java @@ -0,0 +1,141 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.store.subscription; + +// jakarta +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.Index; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +// base +import io.kumare.lib.app.api.store.*; +import io.kumare.iqr.app.store.*; +// imports + +// relations +import io.kumare.iqr.mod.clientele.store.client.ClientEntity; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; +import io.kumare.iqr.mod.biz.store.business.BusinessEntity; +import io.kumare.iqr.mod.pocket.store.walletslot.WalletSlotEntity; + +// annotations +@Entity +@Table( + name = "subscription", + indexes = { + @Index(name = "idx_subscription_entity_key", columnList = "entityKey"), + @Index(name = "idx_subscription_state_value", columnList = "stateValue") + } +) +public class SubscriptionEntity extends AppEntity implements SupportedEntityKey { + + // ::: vars + // + private String entityKey; + private String stateValue; + // relations + @ManyToOne(fetch = FetchType.LAZY) + private BusinessEntity business; + @ManyToOne(fetch = FetchType.LAZY) + private ClientEntity client; + @ManyToOne(fetch = FetchType.LAZY) + private WalletSlotEntity walletSlot; + @ManyToOne(fetch = FetchType.LAZY) + private TaxonEntity state; + + // ::: constructors + // + public SubscriptionEntity() { + } + + public SubscriptionEntity(String id) { + super(id); + } + + // ::: fields + // + public String getEntityKey() { + return entityKey; + } + + public void setEntityKey(String entityKey) { + this.entityKey = entityKey; + } + + public String getStateValue() { + return stateValue; + } + + public void setStateValue(String stateValue) { + this.stateValue = stateValue; + } + + // relations + public BusinessEntity getBusiness() { + return business; + } + + public void setBusiness(BusinessEntity business) { + this.business = business; + } + + public ClientEntity getClient() { + return client; + } + + public void setClient(ClientEntity client) { + this.client = client; + } + + public WalletSlotEntity getWalletSlot() { + return walletSlot; + } + + public void setWalletSlot(WalletSlotEntity walletSlot) { + this.walletSlot = walletSlot; + } + + public TaxonEntity getState() { + return state; + } + + public void setState(TaxonEntity state) { + this.state = state; + } + + // ::: fluent + // + public SubscriptionEntity entityKey(String entityKey) { + setEntityKey(entityKey); + return this; + } + + public SubscriptionEntity stateValue(String stateValue) { + setStateValue(stateValue); + return this; + } + + // relations + public SubscriptionEntity business(BusinessEntity business) { + setBusiness(business); + return this; + } + + public SubscriptionEntity client(ClientEntity client) { + setClient(client); + return this; + } + + public SubscriptionEntity walletSlot(WalletSlotEntity walletSlot) { + setWalletSlot(walletSlot); + return this; + } + + public SubscriptionEntity state(TaxonEntity state) { + setState(state); + return this; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/store/subscription/SubscriptionFields.java b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscription/SubscriptionFields.java new file mode 100644 index 0000000..ed22282 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscription/SubscriptionFields.java @@ -0,0 +1,157 @@ +/* + */ +package io.kumare.iqr.mod.loyalty.store.subscription; + +// java +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +// base +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app +import io.kumare.iqr.mod.biz.store.BizEntities; +import io.kumare.iqr.mod.biz.store.business.BusinessFields; +import io.kumare.iqr.mod.clientele.store.ClienteleEntities; +import io.kumare.iqr.mod.clientele.store.client.ClientFields; +import io.kumare.iqr.mod.pocket.store.PocketEntities; +import io.kumare.iqr.mod.pocket.store.walletslot.WalletSlotFields; +import io.kumare.iqr.mod.taxonomy.store.TaxonomyEntities; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonFields; + +/** + * + * @author afatecha + */ +public enum SubscriptionFields implements EntityFieldDescriptor { + + id(MAIN, FIND, LIST), + entityKey(MAIN, FIND, LIST), + stateValue(MAIN, FIND, LIST), + active(MAIN, FIND, LIST), + inserted(AUDIT, FIND, LIST), + inserter(AUDIT, FIND, LIST), + modified(AUDIT, FIND), + modifier(AUDIT, FIND), + deleted(AUDIT), + removed(AUDIT), + remover(AUDIT), + business(BizEntities.business, BusinessFields.class, FIND, LIST), + client(ClienteleEntities.client, ClientFields.class, FIND, LIST), + walletSlot(PocketEntities.walletSlot, WalletSlotFields.class, FIND, LIST), + state(TaxonomyEntities.taxon, TaxonFields.class, FIND, LIST); + + // ::: vars + // + private final boolean relation; + private final EntityDescriptor entityDescriptor; + private final Class enumClass; + private final List groups; + + // ::: constructors + // + SubscriptionFields(String... groups) { + this(false, null, null, groups); + } + + SubscriptionFields(EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this(true, entityDescriptor, enumClass, groups); + } + + SubscriptionFields(boolean relation, EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this.relation = relation; + this.entityDescriptor = entityDescriptor; + this.enumClass = enumClass; + this.groups = groups == null ? Collections.EMPTY_LIST : Arrays.asList(groups); + } + + // ::: api + // + @Override + public String getName() { + return name(); + } + + @Override + public boolean isRelation() { + return relation; + } + + @Override + public Class getRelationEnumClass() { + return enumClass; + } + + @Override + public List getGroups() { + return groups; + } + + @Override + public EntityDescriptor getEntityDescriptor() { + return entityDescriptor; + } + + @Override + public Object fetchValue(SubscriptionEntity entity) { + if (entity == null) { + return null; + } + + switch (this) { + case null -> { + return null; + } + case id -> { + return entity.getId(); + } + case entityKey ->{ + return entity.getEntityKey(); + } + case stateValue ->{ + return entity.getStateValue(); + } + case active -> { + return entity.isActive(); + } + case inserted -> { + return entity.getInserted(); + } + case inserter -> { + return entity.getInserter(); + } + case modified -> { + return entity.getModified(); + } + case modifier -> { + return entity.getModifier(); + } + case deleted -> { + return entity.isDeleted(); + } + case removed -> { + return entity.getRemoved(); + } + case remover -> { + return entity.getRemover(); + } + case business ->{ + return entity.getBusiness(); + } + case client ->{ + return entity.getClient(); + } + case walletSlot ->{ + return entity.getWalletSlot(); + } + case state ->{ + return entity.getState(); + } + default -> { + return null; + } + } + + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/store/subscription/SubscriptionMapBuilder.java b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscription/SubscriptionMapBuilder.java new file mode 100644 index 0000000..99d6480 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscription/SubscriptionMapBuilder.java @@ -0,0 +1,277 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.store.subscription; + +// java +import java.util.List; +import java.util.Map; +// base +import io.kumare.lib.app.api.Context; +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.BaseEntityMapBuilder; +// app +import io.kumare.iqr.mod.pocket.store.walletslot.WalletSlotMapBuilder; +import io.kumare.iqr.mod.biz.store.business.BusinessMapBuilder; +import io.kumare.iqr.mod.clientele.store.client.ClientMapBuilder; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonMapBuilder; + +/** + * + * @author afatecha + */ +public class SubscriptionMapBuilder extends BaseEntityMapBuilder { + + // ::: vars + // + private BusinessMapBuilder businessBuilder; + private ClientMapBuilder clientBuilder; + private WalletSlotMapBuilder walletSlotBuilder; + private TaxonMapBuilder stateBuilder; + + + // ::: fields + // + @Override + public SubscriptionMapBuilder addGroup(String name, boolean cascade) { + includes.addAll(EntityFieldDescriptor.group(SubscriptionFields.values(), name)); + + if(cascade) { + if (includes.contains(SubscriptionFields.business)) { + getBusinessBuilder().addGroup(name); + } + if (includes.contains(SubscriptionFields.client)) { + getClientBuilder().addGroup(name); + } + if (includes.contains(SubscriptionFields.walletSlot)) { + getWalletSlotBuilder().addGroup(name); + } + if (includes.contains(SubscriptionFields.state)) { + getStateBuilder().addGroup(name); + } + } + return this; + } + + @Override + public SubscriptionMapBuilder add(String fieldName) { + includes.add(SubscriptionFields.valueOf(fieldName)); + return this; + } + + @Override + public SubscriptionMapBuilder addAll(String... names) { + for (var i : names) { + includes.add(SubscriptionFields.valueOf(i)); + } + return this; + } + + @Override + public SubscriptionMapBuilder remove(String fieldName) { + excludes.add(SubscriptionFields.valueOf(fieldName)); + return this; + } + + @Override + public SubscriptionMapBuilder removeAll(String... names) { + for (var i : names) { + excludes.add(SubscriptionFields.valueOf(i)); + } + return this; + } + + // ::: relations + // + @Override + public SubscriptionMapBuilder addPlains(boolean cascade) { + includes.addAll(EntityFieldDescriptor.plains(SubscriptionFields.values())); + + if(cascade) { + if (includes.contains(SubscriptionFields.business)) { + getBusinessBuilder().addPlains(); + } + if (includes.contains(SubscriptionFields.client)) { + getClientBuilder().addPlains(); + } + if (includes.contains(SubscriptionFields.walletSlot)) { + getWalletSlotBuilder().addPlains(); + } + if (includes.contains(SubscriptionFields.state)) { + getStateBuilder().addPlains(); + } + } + return this; + } + + @Override + public SubscriptionMapBuilder addRelations(boolean cascade) { + includes.addAll(EntityFieldDescriptor.relations(SubscriptionFields.values())); + + if(cascade) { + if (includes.contains(SubscriptionFields.business)) { + getBusinessBuilder().addRelations(); + } + if (includes.contains(SubscriptionFields.client)) { + getClientBuilder().addRelations(); + } + if (includes.contains(SubscriptionFields.walletSlot)) { + getWalletSlotBuilder().addRelations(); + } + if (includes.contains(SubscriptionFields.state)) { + getStateBuilder().addRelations(); + } + } + return this; + } + + // ::: business + // + public SubscriptionMapBuilder addBusiness() { + return addBusiness(null); + } + + public SubscriptionMapBuilder addBusiness(String group) { + return addBusiness(group, false); + } + + public SubscriptionMapBuilder addBusiness(String group, boolean cascade) { + includes.add(SubscriptionFields.business); + + if (group != null) { + getBusinessBuilder().addGroup(group); + } + + return this; + } + + public BusinessMapBuilder getBusinessBuilder() { + if(businessBuilder == null) { + businessBuilder = new BusinessMapBuilder(); + } + return businessBuilder; + } + + + // ::: client + // + public SubscriptionMapBuilder addClient() { + return addClient(null); + } + + public SubscriptionMapBuilder addClient(String group) { + return addClient(group, false); + } + + public SubscriptionMapBuilder addClient(String group, boolean cascade) { + includes.add(SubscriptionFields.client); + + if (group != null) { + getClientBuilder().addGroup(group); + } + + return this; + } + + public ClientMapBuilder getClientBuilder() { + if(clientBuilder == null) { + clientBuilder = new ClientMapBuilder(); + } + return clientBuilder; + } + + + // ::: wallet slot + // + public SubscriptionMapBuilder addWalletSlot() { + return addWalletSlot(null); + } + + public SubscriptionMapBuilder addWalletSlot(String group) { + return addWalletSlot(group, false); + } + + public SubscriptionMapBuilder addWalletSlot(String group, boolean cascade) { + includes.add(SubscriptionFields.walletSlot); + + if (group != null) { + getWalletSlotBuilder().addGroup(group); + } + + return this; + } + + public WalletSlotMapBuilder getWalletSlotBuilder() { + if(walletSlotBuilder == null) { + walletSlotBuilder = new WalletSlotMapBuilder(); + } + return walletSlotBuilder; + } + + + // ::: state + // + public SubscriptionMapBuilder addState() { + return addState(null); + } + + public SubscriptionMapBuilder addState(String group) { + return addState(group, false); + } + + public SubscriptionMapBuilder addState(String group, boolean cascade) { + includes.add(SubscriptionFields.state); + + if (group != null) { + getStateBuilder().addGroup(group); + } + + return this; + } + + public TaxonMapBuilder getStateBuilder() { + if(stateBuilder == null) { + stateBuilder = new TaxonMapBuilder(); + } + return stateBuilder; + } + + // ::: internals + // + @Override + protected void internalAttachRelations(Context context, + SubscriptionEntity entity, + List fields, + Map resultMap) { + + if (fields.contains(SubscriptionFields.business)) { + attachRelation(context, + entity, + SubscriptionFields.business, + getBusinessBuilder(), + resultMap); + } + if (fields.contains(SubscriptionFields.client)) { + attachRelation(context, + entity, + SubscriptionFields.client, + getClientBuilder(), + resultMap); + } + if (fields.contains(SubscriptionFields.walletSlot)) { + attachRelation(context, + entity, + SubscriptionFields.walletSlot, + getWalletSlotBuilder(), + resultMap); + } + if (fields.contains(SubscriptionFields.state)) { + attachRelation(context, + entity, + SubscriptionFields.state, + getStateBuilder(), + resultMap); + } + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/store/subscription/SubscriptionRepository.java b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscription/SubscriptionRepository.java new file mode 100644 index 0000000..b54836b --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscription/SubscriptionRepository.java @@ -0,0 +1,18 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.store.subscription; + +// spring +import org.springframework.stereotype.Repository; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Repository +public interface SubscriptionRepository extends AppKeyEntityRepository{ + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/store/subscription/SubscriptionStore.java b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscription/SubscriptionStore.java new file mode 100644 index 0000000..f7d008f --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscription/SubscriptionStore.java @@ -0,0 +1,35 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.store.subscription; + +// spring +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Service +public class SubscriptionStore extends AppKeyEntityStore { + + // ::: vars + // + @Autowired + private SubscriptionRepository repository; + + // ::: override + // + @Override + public SubscriptionRepository getRepository() { + return repository; + } + + // ::: api + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontx/SubscriptionTxData.java b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontx/SubscriptionTxData.java new file mode 100644 index 0000000..08720eb --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontx/SubscriptionTxData.java @@ -0,0 +1,25 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.store.subscriptiontx; + +// base +import io.kumare.iqr.app.store.AppExtendedEntityData; +// imports + + +public class SubscriptionTxData extends AppExtendedEntityData { + + // ::: vars + // + + + // ::: fields + // + + + // ::: fluent + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontx/SubscriptionTxEntity.java b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontx/SubscriptionTxEntity.java new file mode 100644 index 0000000..b043c29 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontx/SubscriptionTxEntity.java @@ -0,0 +1,187 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.store.subscriptiontx; + +// jakarta +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.Index; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +// base +import io.kumare.lib.app.api.store.*; +import io.kumare.iqr.app.store.*; +// imports + +// relations +import io.kumare.iqr.mod.biz.store.businesspromo.BusinessPromoEntity; +import io.kumare.iqr.mod.clientele.store.client.ClientEntity; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; +import io.kumare.iqr.mod.loyalty.store.subscription.SubscriptionEntity; +import io.kumare.iqr.mod.biz.store.businessworker.BusinessWorkerEntity; + +// annotations +@Entity +@Table( + name = "subscription_tx", + indexes = { + @Index(name = "idx_subscription_tx_type_value", columnList = "typeValue"), + @Index(name = "idx_subscription_tx_state_value", columnList = "stateValue"), + @Index(name = "idx_subscription_tx_points", columnList = "points") + } +) +public class SubscriptionTxEntity extends AppEntity { + + // ::: vars + // + private String typeValue; + private String stateValue; + private int points; + // relations + @ManyToOne(fetch = FetchType.LAZY) + private SubscriptionEntity subscription; + @ManyToOne(fetch = FetchType.LAZY) + private BusinessPromoEntity promo; + @ManyToOne(fetch = FetchType.LAZY) + private BusinessWorkerEntity worker; + @ManyToOne(fetch = FetchType.LAZY) + private TaxonEntity type; + @ManyToOne(fetch = FetchType.LAZY) + private TaxonEntity state; + @ManyToOne(fetch = FetchType.LAZY) + private ClientEntity capturer; + + // ::: constructors + // + public SubscriptionTxEntity() { + } + + public SubscriptionTxEntity(String id) { + super(id); + } + + // ::: fields + // + public String getTypeValue() { + return typeValue; + } + + public void setTypeValue(String typeValue) { + this.typeValue = typeValue; + } + + public String getStateValue() { + return stateValue; + } + + public void setStateValue(String stateValue) { + this.stateValue = stateValue; + } + + public int getPoints() { + return points; + } + + public void setPoints(int points) { + this.points = points; + } + + // relations + public SubscriptionEntity getSubscription() { + return subscription; + } + + public void setSubscription(SubscriptionEntity subscription) { + this.subscription = subscription; + } + + public BusinessPromoEntity getPromo() { + return promo; + } + + public void setPromo(BusinessPromoEntity promo) { + this.promo = promo; + } + + public BusinessWorkerEntity getWorker() { + return worker; + } + + public void setWorker(BusinessWorkerEntity worker) { + this.worker = worker; + } + + public TaxonEntity getType() { + return type; + } + + public void setType(TaxonEntity type) { + this.type = type; + } + + public TaxonEntity getState() { + return state; + } + + public void setState(TaxonEntity state) { + this.state = state; + } + + public ClientEntity getCapturer() { + return capturer; + } + + public void setCapturer(ClientEntity capturer) { + this.capturer = capturer; + } + + // ::: fluent + // + public SubscriptionTxEntity typeValue(String typeValue) { + setTypeValue(typeValue); + return this; + } + + public SubscriptionTxEntity stateValue(String stateValue) { + setStateValue(stateValue); + return this; + } + + public SubscriptionTxEntity points(int points) { + setPoints(points); + return this; + } + + // relations + public SubscriptionTxEntity subscription(SubscriptionEntity subscription) { + setSubscription(subscription); + return this; + } + + public SubscriptionTxEntity promo(BusinessPromoEntity promo) { + setPromo(promo); + return this; + } + + public SubscriptionTxEntity worker(BusinessWorkerEntity worker) { + setWorker(worker); + return this; + } + + public SubscriptionTxEntity type(TaxonEntity type) { + setType(type); + return this; + } + + public SubscriptionTxEntity state(TaxonEntity state) { + setState(state); + return this; + } + + public SubscriptionTxEntity capturer(ClientEntity capturer) { + setCapturer(capturer); + return this; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontx/SubscriptionTxFields.java b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontx/SubscriptionTxFields.java new file mode 100644 index 0000000..6811bbe --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontx/SubscriptionTxFields.java @@ -0,0 +1,173 @@ +/* + */ +package io.kumare.iqr.mod.loyalty.store.subscriptiontx; + +// java +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +// base +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app +import io.kumare.iqr.mod.loyalty.store.LoyaltyEntities; +import io.kumare.iqr.mod.loyalty.store.subscription.SubscriptionFields; +import io.kumare.iqr.mod.biz.store.BizEntities; +import io.kumare.iqr.mod.biz.store.businesspromo.BusinessPromoFields; +import io.kumare.iqr.mod.biz.store.BizEntities; +import io.kumare.iqr.mod.biz.store.businessworker.BusinessWorkerFields; +import io.kumare.iqr.mod.taxonomy.store.TaxonomyEntities; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonFields; +import io.kumare.iqr.mod.taxonomy.store.TaxonomyEntities; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonFields; +import io.kumare.iqr.mod.clientele.store.ClienteleEntities; +import io.kumare.iqr.mod.clientele.store.client.ClientFields; + +/** + * + * @author afatecha + */ +public enum SubscriptionTxFields implements EntityFieldDescriptor { + + id(MAIN, FIND, LIST), + typeValue(MAIN, FIND, LIST), + stateValue(MAIN, FIND, LIST), + points(MAIN, FIND, LIST), + active(MAIN, FIND, LIST), + inserted(AUDIT, FIND, LIST), + inserter(AUDIT, FIND, LIST), + modified(AUDIT, FIND), + modifier(AUDIT, FIND), + deleted(AUDIT), + removed(AUDIT), + remover(AUDIT), + subscription(LoyaltyEntities.subscription, SubscriptionFields.class, FIND, LIST), + promo(BizEntities.businessPromo, BusinessPromoFields.class, FIND, LIST), + worker(BizEntities.businessWorker, BusinessWorkerFields.class, FIND, LIST), + type(TaxonomyEntities.taxon, TaxonFields.class, FIND, LIST), + state(TaxonomyEntities.taxon, TaxonFields.class, FIND, LIST), + capturer(ClienteleEntities.client, ClientFields.class, FIND, LIST); + + // ::: vars + // + private final boolean relation; + private final EntityDescriptor entityDescriptor; + private final Class enumClass; + private final List groups; + + // ::: constructors + // + SubscriptionTxFields(String... groups) { + this(false, null, null, groups); + } + + SubscriptionTxFields(EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this(true, entityDescriptor, enumClass, groups); + } + + SubscriptionTxFields(boolean relation, EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this.relation = relation; + this.entityDescriptor = entityDescriptor; + this.enumClass = enumClass; + this.groups = groups == null ? Collections.EMPTY_LIST : Arrays.asList(groups); + } + + // ::: api + // + @Override + public String getName() { + return name(); + } + + @Override + public boolean isRelation() { + return relation; + } + + @Override + public Class getRelationEnumClass() { + return enumClass; + } + + @Override + public List getGroups() { + return groups; + } + + @Override + public EntityDescriptor getEntityDescriptor() { + return entityDescriptor; + } + + @Override + public Object fetchValue(SubscriptionTxEntity entity) { + if (entity == null) { + return null; + } + + switch (this) { + case null -> { + return null; + } + case id -> { + return entity.getId(); + } + case typeValue ->{ + return entity.getTypeValue(); + } + case stateValue ->{ + return entity.getStateValue(); + } + case points ->{ + return entity.getPoints(); + } + case active -> { + return entity.isActive(); + } + case inserted -> { + return entity.getInserted(); + } + case inserter -> { + return entity.getInserter(); + } + case modified -> { + return entity.getModified(); + } + case modifier -> { + return entity.getModifier(); + } + case deleted -> { + return entity.isDeleted(); + } + case removed -> { + return entity.getRemoved(); + } + case remover -> { + return entity.getRemover(); + } + case subscription ->{ + return entity.getSubscription(); + } + case promo ->{ + return entity.getPromo(); + } + case worker ->{ + return entity.getWorker(); + } + case type ->{ + return entity.getType(); + } + case state ->{ + return entity.getState(); + } + case capturer ->{ + return entity.getCapturer(); + } + default -> { + return null; + } + } + + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontx/SubscriptionTxMapBuilder.java b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontx/SubscriptionTxMapBuilder.java new file mode 100644 index 0000000..a806ed7 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontx/SubscriptionTxMapBuilder.java @@ -0,0 +1,368 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.store.subscriptiontx; + +// java +import java.util.List; +import java.util.Map; +// base +import io.kumare.lib.app.api.Context; +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.BaseEntityMapBuilder; +// app +import io.kumare.iqr.mod.biz.store.businesspromo.BusinessPromoMapBuilder; +import io.kumare.iqr.mod.loyalty.store.subscription.SubscriptionMapBuilder; +import io.kumare.iqr.mod.biz.store.businessworker.BusinessWorkerMapBuilder; +import io.kumare.iqr.mod.clientele.store.client.ClientMapBuilder; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonMapBuilder; + +/** + * + * @author afatecha + */ +public class SubscriptionTxMapBuilder extends BaseEntityMapBuilder { + + // ::: vars + // + private SubscriptionMapBuilder subscriptionBuilder; + private BusinessPromoMapBuilder promoBuilder; + private BusinessWorkerMapBuilder workerBuilder; + private TaxonMapBuilder typeBuilder; + private TaxonMapBuilder stateBuilder; + private ClientMapBuilder capturerBuilder; + + + // ::: fields + // + @Override + public SubscriptionTxMapBuilder addGroup(String name, boolean cascade) { + includes.addAll(EntityFieldDescriptor.group(SubscriptionTxFields.values(), name)); + + if(cascade) { + if (includes.contains(SubscriptionTxFields.subscription)) { + getSubscriptionBuilder().addGroup(name); + } + if (includes.contains(SubscriptionTxFields.promo)) { + getPromoBuilder().addGroup(name); + } + if (includes.contains(SubscriptionTxFields.worker)) { + getWorkerBuilder().addGroup(name); + } + if (includes.contains(SubscriptionTxFields.type)) { + getTypeBuilder().addGroup(name); + } + if (includes.contains(SubscriptionTxFields.state)) { + getStateBuilder().addGroup(name); + } + if (includes.contains(SubscriptionTxFields.capturer)) { + getCapturerBuilder().addGroup(name); + } + } + return this; + } + + @Override + public SubscriptionTxMapBuilder add(String fieldName) { + includes.add(SubscriptionTxFields.valueOf(fieldName)); + return this; + } + + @Override + public SubscriptionTxMapBuilder addAll(String... names) { + for (var i : names) { + includes.add(SubscriptionTxFields.valueOf(i)); + } + return this; + } + + @Override + public SubscriptionTxMapBuilder remove(String fieldName) { + excludes.add(SubscriptionTxFields.valueOf(fieldName)); + return this; + } + + @Override + public SubscriptionTxMapBuilder removeAll(String... names) { + for (var i : names) { + excludes.add(SubscriptionTxFields.valueOf(i)); + } + return this; + } + + // ::: relations + // + @Override + public SubscriptionTxMapBuilder addPlains(boolean cascade) { + includes.addAll(EntityFieldDescriptor.plains(SubscriptionTxFields.values())); + + if(cascade) { + if (includes.contains(SubscriptionTxFields.subscription)) { + getSubscriptionBuilder().addPlains(); + } + if (includes.contains(SubscriptionTxFields.promo)) { + getPromoBuilder().addPlains(); + } + if (includes.contains(SubscriptionTxFields.worker)) { + getWorkerBuilder().addPlains(); + } + if (includes.contains(SubscriptionTxFields.type)) { + getTypeBuilder().addPlains(); + } + if (includes.contains(SubscriptionTxFields.state)) { + getStateBuilder().addPlains(); + } + if (includes.contains(SubscriptionTxFields.capturer)) { + getCapturerBuilder().addPlains(); + } + } + return this; + } + + @Override + public SubscriptionTxMapBuilder addRelations(boolean cascade) { + includes.addAll(EntityFieldDescriptor.relations(SubscriptionTxFields.values())); + + if(cascade) { + if (includes.contains(SubscriptionTxFields.subscription)) { + getSubscriptionBuilder().addRelations(); + } + if (includes.contains(SubscriptionTxFields.promo)) { + getPromoBuilder().addRelations(); + } + if (includes.contains(SubscriptionTxFields.worker)) { + getWorkerBuilder().addRelations(); + } + if (includes.contains(SubscriptionTxFields.type)) { + getTypeBuilder().addRelations(); + } + if (includes.contains(SubscriptionTxFields.state)) { + getStateBuilder().addRelations(); + } + if (includes.contains(SubscriptionTxFields.capturer)) { + getCapturerBuilder().addRelations(); + } + } + return this; + } + + // ::: subscription + // + public SubscriptionTxMapBuilder addSubscription() { + return addSubscription(null); + } + + public SubscriptionTxMapBuilder addSubscription(String group) { + return addSubscription(group, false); + } + + public SubscriptionTxMapBuilder addSubscription(String group, boolean cascade) { + includes.add(SubscriptionTxFields.subscription); + + if (group != null) { + getSubscriptionBuilder().addGroup(group); + } + + return this; + } + + public SubscriptionMapBuilder getSubscriptionBuilder() { + if(subscriptionBuilder == null) { + subscriptionBuilder = new SubscriptionMapBuilder(); + } + return subscriptionBuilder; + } + + + // ::: promo + // + public SubscriptionTxMapBuilder addPromo() { + return addPromo(null); + } + + public SubscriptionTxMapBuilder addPromo(String group) { + return addPromo(group, false); + } + + public SubscriptionTxMapBuilder addPromo(String group, boolean cascade) { + includes.add(SubscriptionTxFields.promo); + + if (group != null) { + getPromoBuilder().addGroup(group); + } + + return this; + } + + public BusinessPromoMapBuilder getPromoBuilder() { + if(promoBuilder == null) { + promoBuilder = new BusinessPromoMapBuilder(); + } + return promoBuilder; + } + + + // ::: worker + // + public SubscriptionTxMapBuilder addWorker() { + return addWorker(null); + } + + public SubscriptionTxMapBuilder addWorker(String group) { + return addWorker(group, false); + } + + public SubscriptionTxMapBuilder addWorker(String group, boolean cascade) { + includes.add(SubscriptionTxFields.worker); + + if (group != null) { + getWorkerBuilder().addGroup(group); + } + + return this; + } + + public BusinessWorkerMapBuilder getWorkerBuilder() { + if(workerBuilder == null) { + workerBuilder = new BusinessWorkerMapBuilder(); + } + return workerBuilder; + } + + + // ::: type + // + public SubscriptionTxMapBuilder addType() { + return addType(null); + } + + public SubscriptionTxMapBuilder addType(String group) { + return addType(group, false); + } + + public SubscriptionTxMapBuilder addType(String group, boolean cascade) { + includes.add(SubscriptionTxFields.type); + + if (group != null) { + getTypeBuilder().addGroup(group); + } + + return this; + } + + public TaxonMapBuilder getTypeBuilder() { + if(typeBuilder == null) { + typeBuilder = new TaxonMapBuilder(); + } + return typeBuilder; + } + + + // ::: state + // + public SubscriptionTxMapBuilder addState() { + return addState(null); + } + + public SubscriptionTxMapBuilder addState(String group) { + return addState(group, false); + } + + public SubscriptionTxMapBuilder addState(String group, boolean cascade) { + includes.add(SubscriptionTxFields.state); + + if (group != null) { + getStateBuilder().addGroup(group); + } + + return this; + } + + public TaxonMapBuilder getStateBuilder() { + if(stateBuilder == null) { + stateBuilder = new TaxonMapBuilder(); + } + return stateBuilder; + } + + + // ::: capturer + // + public SubscriptionTxMapBuilder addCapturer() { + return addCapturer(null); + } + + public SubscriptionTxMapBuilder addCapturer(String group) { + return addCapturer(group, false); + } + + public SubscriptionTxMapBuilder addCapturer(String group, boolean cascade) { + includes.add(SubscriptionTxFields.capturer); + + if (group != null) { + getCapturerBuilder().addGroup(group); + } + + return this; + } + + public ClientMapBuilder getCapturerBuilder() { + if(capturerBuilder == null) { + capturerBuilder = new ClientMapBuilder(); + } + return capturerBuilder; + } + + // ::: internals + // + @Override + protected void internalAttachRelations(Context context, + SubscriptionTxEntity entity, + List fields, + Map resultMap) { + + if (fields.contains(SubscriptionTxFields.subscription)) { + attachRelation(context, + entity, + SubscriptionTxFields.subscription, + getSubscriptionBuilder(), + resultMap); + } + if (fields.contains(SubscriptionTxFields.promo)) { + attachRelation(context, + entity, + SubscriptionTxFields.promo, + getPromoBuilder(), + resultMap); + } + if (fields.contains(SubscriptionTxFields.worker)) { + attachRelation(context, + entity, + SubscriptionTxFields.worker, + getWorkerBuilder(), + resultMap); + } + if (fields.contains(SubscriptionTxFields.type)) { + attachRelation(context, + entity, + SubscriptionTxFields.type, + getTypeBuilder(), + resultMap); + } + if (fields.contains(SubscriptionTxFields.state)) { + attachRelation(context, + entity, + SubscriptionTxFields.state, + getStateBuilder(), + resultMap); + } + if (fields.contains(SubscriptionTxFields.capturer)) { + attachRelation(context, + entity, + SubscriptionTxFields.capturer, + getCapturerBuilder(), + resultMap); + } + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontx/SubscriptionTxRepository.java b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontx/SubscriptionTxRepository.java new file mode 100644 index 0000000..1dde18a --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontx/SubscriptionTxRepository.java @@ -0,0 +1,18 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.store.subscriptiontx; + +// spring +import org.springframework.stereotype.Repository; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Repository +public interface SubscriptionTxRepository extends AppEntityRepository{ + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontx/SubscriptionTxStore.java b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontx/SubscriptionTxStore.java new file mode 100644 index 0000000..380db10 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontx/SubscriptionTxStore.java @@ -0,0 +1,35 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.store.subscriptiontx; + +// spring +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Service +public class SubscriptionTxStore extends AppEntityStore { + + // ::: vars + // + @Autowired + private SubscriptionTxRepository repository; + + // ::: override + // + @Override + public SubscriptionTxRepository getRepository() { + return repository; + } + + // ::: api + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontxtag/SubscriptionTxTagData.java b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontxtag/SubscriptionTxTagData.java new file mode 100644 index 0000000..b6eb415 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontxtag/SubscriptionTxTagData.java @@ -0,0 +1,25 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.store.subscriptiontxtag; + +// base +import io.kumare.iqr.app.store.AppExtendedEntityData; +// imports + + +public class SubscriptionTxTagData extends AppExtendedEntityData { + + // ::: vars + // + + + // ::: fields + // + + + // ::: fluent + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontxtag/SubscriptionTxTagEntity.java b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontxtag/SubscriptionTxTagEntity.java new file mode 100644 index 0000000..8eec310 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontxtag/SubscriptionTxTagEntity.java @@ -0,0 +1,110 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.store.subscriptiontxtag; + +// jakarta +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.Index; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +// base +import io.kumare.lib.app.api.store.*; +import io.kumare.iqr.app.store.*; +// imports + +// relations +import io.kumare.iqr.mod.biz.store.businesstag.BusinessTagEntity; +import io.kumare.iqr.mod.loyalty.store.subscriptiontx.SubscriptionTxEntity; +import io.kumare.iqr.mod.loyalty.store.subscription.SubscriptionEntity; + +// annotations +@Entity +@Table( + name = "subscription_tx_tag", + indexes = { + @Index(name = "idx_subscription_tx_tag_tag_key", columnList = "tagKey") + } +) +public class SubscriptionTxTagEntity extends AppEntity { + + // ::: vars + // + private String tagKey; + // relations + @ManyToOne(fetch = FetchType.LAZY) + private SubscriptionEntity subscription; + @ManyToOne(fetch = FetchType.LAZY) + private SubscriptionTxEntity transaction; + @ManyToOne(fetch = FetchType.LAZY) + private BusinessTagEntity tag; + + // ::: constructors + // + public SubscriptionTxTagEntity() { + } + + public SubscriptionTxTagEntity(String id) { + super(id); + } + + // ::: fields + // + public String getTagKey() { + return tagKey; + } + + public void setTagKey(String tagKey) { + this.tagKey = tagKey; + } + + // relations + public SubscriptionEntity getSubscription() { + return subscription; + } + + public void setSubscription(SubscriptionEntity subscription) { + this.subscription = subscription; + } + + public SubscriptionTxEntity getTransaction() { + return transaction; + } + + public void setTransaction(SubscriptionTxEntity transaction) { + this.transaction = transaction; + } + + public BusinessTagEntity getTag() { + return tag; + } + + public void setTag(BusinessTagEntity tag) { + this.tag = tag; + } + + // ::: fluent + // + public SubscriptionTxTagEntity tagKey(String tagKey) { + setTagKey(tagKey); + return this; + } + + // relations + public SubscriptionTxTagEntity subscription(SubscriptionEntity subscription) { + setSubscription(subscription); + return this; + } + + public SubscriptionTxTagEntity transaction(SubscriptionTxEntity transaction) { + setTransaction(transaction); + return this; + } + + public SubscriptionTxTagEntity tag(BusinessTagEntity tag) { + setTag(tag); + return this; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontxtag/SubscriptionTxTagFields.java b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontxtag/SubscriptionTxTagFields.java new file mode 100644 index 0000000..2d7809b --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontxtag/SubscriptionTxTagFields.java @@ -0,0 +1,147 @@ +/* + */ +package io.kumare.iqr.mod.loyalty.store.subscriptiontxtag; + +// java +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +// base +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app +import io.kumare.iqr.mod.loyalty.store.LoyaltyEntities; +import io.kumare.iqr.mod.loyalty.store.subscription.SubscriptionFields; +import io.kumare.iqr.mod.loyalty.store.LoyaltyEntities; +import io.kumare.iqr.mod.loyalty.store.subscriptiontx.SubscriptionTxFields; +import io.kumare.iqr.mod.biz.store.BizEntities; +import io.kumare.iqr.mod.biz.store.businesstag.BusinessTagFields; + +/** + * + * @author afatecha + */ +public enum SubscriptionTxTagFields implements EntityFieldDescriptor { + + id(MAIN, FIND, LIST), + tagKey(MAIN, FIND, LIST), + active(MAIN, FIND, LIST), + inserted(AUDIT, FIND, LIST), + inserter(AUDIT, FIND, LIST), + modified(AUDIT, FIND), + modifier(AUDIT, FIND), + deleted(AUDIT), + removed(AUDIT), + remover(AUDIT), + subscription(LoyaltyEntities.subscription, SubscriptionFields.class, FIND, LIST), + transaction(LoyaltyEntities.subscriptionTx, SubscriptionTxFields.class, FIND, LIST), + tag(BizEntities.businessTag, BusinessTagFields.class, FIND, LIST); + + // ::: vars + // + private final boolean relation; + private final EntityDescriptor entityDescriptor; + private final Class enumClass; + private final List groups; + + // ::: constructors + // + SubscriptionTxTagFields(String... groups) { + this(false, null, null, groups); + } + + SubscriptionTxTagFields(EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this(true, entityDescriptor, enumClass, groups); + } + + SubscriptionTxTagFields(boolean relation, EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this.relation = relation; + this.entityDescriptor = entityDescriptor; + this.enumClass = enumClass; + this.groups = groups == null ? Collections.EMPTY_LIST : Arrays.asList(groups); + } + + // ::: api + // + @Override + public String getName() { + return name(); + } + + @Override + public boolean isRelation() { + return relation; + } + + @Override + public Class getRelationEnumClass() { + return enumClass; + } + + @Override + public List getGroups() { + return groups; + } + + @Override + public EntityDescriptor getEntityDescriptor() { + return entityDescriptor; + } + + @Override + public Object fetchValue(SubscriptionTxTagEntity entity) { + if (entity == null) { + return null; + } + + switch (this) { + case null -> { + return null; + } + case id -> { + return entity.getId(); + } + case tagKey ->{ + return entity.getTagKey(); + } + case active -> { + return entity.isActive(); + } + case inserted -> { + return entity.getInserted(); + } + case inserter -> { + return entity.getInserter(); + } + case modified -> { + return entity.getModified(); + } + case modifier -> { + return entity.getModifier(); + } + case deleted -> { + return entity.isDeleted(); + } + case removed -> { + return entity.getRemoved(); + } + case remover -> { + return entity.getRemover(); + } + case subscription ->{ + return entity.getSubscription(); + } + case transaction ->{ + return entity.getTransaction(); + } + case tag ->{ + return entity.getTag(); + } + default -> { + return null; + } + } + + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontxtag/SubscriptionTxTagMapBuilder.java b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontxtag/SubscriptionTxTagMapBuilder.java new file mode 100644 index 0000000..43a7cea --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontxtag/SubscriptionTxTagMapBuilder.java @@ -0,0 +1,231 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.store.subscriptiontxtag; + +// java +import java.util.List; +import java.util.Map; +// base +import io.kumare.lib.app.api.Context; +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.BaseEntityMapBuilder; +// app +import io.kumare.iqr.mod.biz.store.businesstag.BusinessTagMapBuilder; +import io.kumare.iqr.mod.loyalty.store.subscription.SubscriptionMapBuilder; +import io.kumare.iqr.mod.loyalty.store.subscriptiontx.SubscriptionTxMapBuilder; + +/** + * + * @author afatecha + */ +public class SubscriptionTxTagMapBuilder extends BaseEntityMapBuilder { + + // ::: vars + // + private SubscriptionMapBuilder subscriptionBuilder; + private SubscriptionTxMapBuilder transactionBuilder; + private BusinessTagMapBuilder tagBuilder; + + + // ::: fields + // + @Override + public SubscriptionTxTagMapBuilder addGroup(String name, boolean cascade) { + includes.addAll(EntityFieldDescriptor.group(SubscriptionTxTagFields.values(), name)); + + if(cascade) { + if (includes.contains(SubscriptionTxTagFields.subscription)) { + getSubscriptionBuilder().addGroup(name); + } + if (includes.contains(SubscriptionTxTagFields.transaction)) { + getTransactionBuilder().addGroup(name); + } + if (includes.contains(SubscriptionTxTagFields.tag)) { + getTagBuilder().addGroup(name); + } + } + return this; + } + + @Override + public SubscriptionTxTagMapBuilder add(String fieldName) { + includes.add(SubscriptionTxTagFields.valueOf(fieldName)); + return this; + } + + @Override + public SubscriptionTxTagMapBuilder addAll(String... names) { + for (var i : names) { + includes.add(SubscriptionTxTagFields.valueOf(i)); + } + return this; + } + + @Override + public SubscriptionTxTagMapBuilder remove(String fieldName) { + excludes.add(SubscriptionTxTagFields.valueOf(fieldName)); + return this; + } + + @Override + public SubscriptionTxTagMapBuilder removeAll(String... names) { + for (var i : names) { + excludes.add(SubscriptionTxTagFields.valueOf(i)); + } + return this; + } + + // ::: relations + // + @Override + public SubscriptionTxTagMapBuilder addPlains(boolean cascade) { + includes.addAll(EntityFieldDescriptor.plains(SubscriptionTxTagFields.values())); + + if(cascade) { + if (includes.contains(SubscriptionTxTagFields.subscription)) { + getSubscriptionBuilder().addPlains(); + } + if (includes.contains(SubscriptionTxTagFields.transaction)) { + getTransactionBuilder().addPlains(); + } + if (includes.contains(SubscriptionTxTagFields.tag)) { + getTagBuilder().addPlains(); + } + } + return this; + } + + @Override + public SubscriptionTxTagMapBuilder addRelations(boolean cascade) { + includes.addAll(EntityFieldDescriptor.relations(SubscriptionTxTagFields.values())); + + if(cascade) { + if (includes.contains(SubscriptionTxTagFields.subscription)) { + getSubscriptionBuilder().addRelations(); + } + if (includes.contains(SubscriptionTxTagFields.transaction)) { + getTransactionBuilder().addRelations(); + } + if (includes.contains(SubscriptionTxTagFields.tag)) { + getTagBuilder().addRelations(); + } + } + return this; + } + + // ::: subscription + // + public SubscriptionTxTagMapBuilder addSubscription() { + return addSubscription(null); + } + + public SubscriptionTxTagMapBuilder addSubscription(String group) { + return addSubscription(group, false); + } + + public SubscriptionTxTagMapBuilder addSubscription(String group, boolean cascade) { + includes.add(SubscriptionTxTagFields.subscription); + + if (group != null) { + getSubscriptionBuilder().addGroup(group); + } + + return this; + } + + public SubscriptionMapBuilder getSubscriptionBuilder() { + if(subscriptionBuilder == null) { + subscriptionBuilder = new SubscriptionMapBuilder(); + } + return subscriptionBuilder; + } + + + // ::: transaction + // + public SubscriptionTxTagMapBuilder addTransaction() { + return addTransaction(null); + } + + public SubscriptionTxTagMapBuilder addTransaction(String group) { + return addTransaction(group, false); + } + + public SubscriptionTxTagMapBuilder addTransaction(String group, boolean cascade) { + includes.add(SubscriptionTxTagFields.transaction); + + if (group != null) { + getTransactionBuilder().addGroup(group); + } + + return this; + } + + public SubscriptionTxMapBuilder getTransactionBuilder() { + if(transactionBuilder == null) { + transactionBuilder = new SubscriptionTxMapBuilder(); + } + return transactionBuilder; + } + + + // ::: tag + // + public SubscriptionTxTagMapBuilder addTag() { + return addTag(null); + } + + public SubscriptionTxTagMapBuilder addTag(String group) { + return addTag(group, false); + } + + public SubscriptionTxTagMapBuilder addTag(String group, boolean cascade) { + includes.add(SubscriptionTxTagFields.tag); + + if (group != null) { + getTagBuilder().addGroup(group); + } + + return this; + } + + public BusinessTagMapBuilder getTagBuilder() { + if(tagBuilder == null) { + tagBuilder = new BusinessTagMapBuilder(); + } + return tagBuilder; + } + + // ::: internals + // + @Override + protected void internalAttachRelations(Context context, + SubscriptionTxTagEntity entity, + List fields, + Map resultMap) { + + if (fields.contains(SubscriptionTxTagFields.subscription)) { + attachRelation(context, + entity, + SubscriptionTxTagFields.subscription, + getSubscriptionBuilder(), + resultMap); + } + if (fields.contains(SubscriptionTxTagFields.transaction)) { + attachRelation(context, + entity, + SubscriptionTxTagFields.transaction, + getTransactionBuilder(), + resultMap); + } + if (fields.contains(SubscriptionTxTagFields.tag)) { + attachRelation(context, + entity, + SubscriptionTxTagFields.tag, + getTagBuilder(), + resultMap); + } + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontxtag/SubscriptionTxTagRepository.java b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontxtag/SubscriptionTxTagRepository.java new file mode 100644 index 0000000..23ae2b2 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontxtag/SubscriptionTxTagRepository.java @@ -0,0 +1,18 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.store.subscriptiontxtag; + +// spring +import org.springframework.stereotype.Repository; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Repository +public interface SubscriptionTxTagRepository extends AppEntityRepository{ + +} diff --git a/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontxtag/SubscriptionTxTagStore.java b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontxtag/SubscriptionTxTagStore.java new file mode 100644 index 0000000..9ae4c67 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/loyalty/store/subscriptiontxtag/SubscriptionTxTagStore.java @@ -0,0 +1,35 @@ +/* + * + */ +package io.kumare.iqr.mod.loyalty.store.subscriptiontxtag; + +// spring +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Service +public class SubscriptionTxTagStore extends AppEntityStore { + + // ::: vars + // + @Autowired + private SubscriptionTxTagRepository repository; + + // ::: override + // + @Override + public SubscriptionTxTagRepository getRepository() { + return repository; + } + + // ::: api + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/PocketConstants.java b/src/main/java/io/kumare/iqr/mod/pocket/PocketConstants.java new file mode 100644 index 0000000..5fe7556 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/PocketConstants.java @@ -0,0 +1,20 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket; + +// base +import io.kumare.iqr.app.AppConstants; + +/** + * + * @author afatecha + */ +public class PocketConstants { + + // ::: codes + // + public static final int CODE = AppConstants.POCKET_CODE; + public static final String NAME = "pocket"; + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/PocketController.java b/src/main/java/io/kumare/iqr/mod/pocket/PocketController.java new file mode 100644 index 0000000..8ba6de2 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/PocketController.java @@ -0,0 +1,62 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket; + +// java +import io.kumare.iqr.mod.pocket.store.PocketEntities; +import java.util.Arrays; +import java.util.List; +// base +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app +import io.kumare.iqr.app.module.AppModuleController; +// module +import io.kumare.iqr.mod.pocket.store.wallet.WalletStore; +import io.kumare.iqr.mod.pocket.store.walletslot.WalletSlotStore; +import io.kumare.iqr.mod.pocket.store.walletmovement.WalletMovementStore; + +/** + * + * @author afatecha + */ +public class PocketController extends AppModuleController { + + // ::: api + // + @Override + public boolean hasStore(String name) { + return PocketEntities.hasDescriptor(name); + } + + @Override + public EntityDescriptor getEntityDescriptor(Class entityClass) { + return PocketEntities.descriptorOf(entityClass); + } + + @Override + public EntityDescriptor getEntityDescriptor(String name) { + return PocketEntities.descriptorOf(name); + } + + @Override + public List getEntityDescriptors() { + return Arrays.asList(PocketEntities.values()); + } + + // ::: stores + // + public WalletStore getWalletStore() { + return getService(WalletStore.class); + } + + public WalletSlotStore getWalletSlotStore() { + return getService(WalletSlotStore.class); + } + + public WalletMovementStore getWalletMovementStore() { + return getService(WalletMovementStore.class); + } + + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/PocketErrors.java b/src/main/java/io/kumare/iqr/mod/pocket/PocketErrors.java new file mode 100644 index 0000000..7d96659 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/PocketErrors.java @@ -0,0 +1,99 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket; + +// java +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.transport.TransportCode; +import static io.kumare.lib.transport.Transports.code; +import io.kumare.lib.v.ExceptionPrototype; +// app +import io.kumare.iqr.app.AppException; +import io.kumare.iqr.app.endpoint.AppTransports; + + +/** + * + * @author afatecha + */ +public enum PocketErrors implements ExceptionPrototype { + + + // wallet + wallet_notfound(1, code(AppTransports.http, 400)), + wallet_data_notfound(1, code(AppTransports.http, 400)), + wallet_preload_empty(1, code(AppTransports.http, 400)), + wallet_externalid_empty(1, code(AppTransports.http, 400)), + wallet_entitykey_empty(1, code(AppTransports.http, 400)), + + // wallet slot + walletslot_notfound(1, code(AppTransports.http, 400)), + walletslot_data_notfound(1, code(AppTransports.http, 400)), + walletslot_preload_empty(1, code(AppTransports.http, 400)), + walletslot_entitykey_empty(1, code(AppTransports.http, 400)), + walletslot_conceptkey_empty(1, code(AppTransports.http, 400)), + walletslot_points_empty(1, code(AppTransports.http, 400)), + walletslot_wallet_notfound(1, code(AppTransports.http, 400)), + + // wallet movement + walletmovement_notfound(1, code(AppTransports.http, 400)), + walletmovement_data_notfound(1, code(AppTransports.http, 400)), + walletmovement_preload_empty(1, code(AppTransports.http, 400)), + walletmovement_externalid_empty(1, code(AppTransports.http, 400)), + walletmovement_typevalue_empty(1, code(AppTransports.http, 400)), + walletmovement_statevalue_empty(1, code(AppTransports.http, 400)), + walletmovement_donedate_empty(1, code(AppTransports.http, 400)), + walletmovement_value_empty(1, code(AppTransports.http, 400)), + walletmovement_unsignedvalue_empty(1, code(AppTransports.http, 400)), + walletmovement_wallet_notfound(1, code(AppTransports.http, 400)), + walletmovement_walletslot_notfound(1, code(AppTransports.http, 400)), + walletmovement_type_notfound(1, code(AppTransports.http, 400)), + walletmovement_state_notfound(1, code(AppTransports.http, 400)); + + // ::: vars + // + private final Map transportCodes = new HashMap(); + private final int code; + + // ::: constructors + // + private PocketErrors(int code, TransportCode... codes) { + this.code = code; + if (codes != null) { + for (var i : codes) { + if (i != null) { + transportCodes.put(i.getId(), i.getCode()); + } + } + } + } + + // ::: prototype api + // + @Override + public int getCode() { + return code; + } + + @Override + public String getName() { + return name(); + } + + @Override + public Map getTransportCodes() { + return transportCodes; + } + + @Override + public RuntimeException newInstance(String msg, Throwable cause, Map extra) { + var ex = new AppException(this, msg, cause); + ex.setExtra(extra); + return ex; + } + + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/PocketModule.java b/src/main/java/io/kumare/iqr/mod/pocket/PocketModule.java new file mode 100644 index 0000000..3b73f50 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/PocketModule.java @@ -0,0 +1,37 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket; + +// java +import io.kumare.lib.base.server.spring.module.BaseModule; + + +/** + * + * @author afatecha + */ +public class PocketModule extends BaseModule { + + // ::: + // + public static final PocketController controller = new PocketController(); + + // ::: api + // + @Override + public int getId() { + return PocketConstants.CODE; + } + + @Override + public String getName() { + return PocketConstants.NAME; + } + + @Override + public PocketController getController() { + return controller; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/PocketPermissions.java b/src/main/java/io/kumare/iqr/mod/pocket/PocketPermissions.java new file mode 100644 index 0000000..c180e60 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/PocketPermissions.java @@ -0,0 +1,103 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket; + +// base +import io.kumare.iqr.mod.pocket.store.PocketEntities; +import io.kumare.lib.app.api.security.PermissionReference; +// app +import io.kumare.iqr.app.AppErrors; + +/** + * + * @author afatecha + */ +public enum PocketPermissions { + + // wallet + //wallet_add(PocketEntities.wallet), + //wallet_edit(PocketEntities.wallet), + //wallet_find(PocketEntities.wallet), + //wallet_enable(PocketEntities.wallet), + //wallet_disable(PocketEntities.wallet), + //wallet_list(PocketEntities.wallet), + //wallet_delete(PocketEntities.wallet), + //wallet_preload(PocketEntities.wallet), + // + wallet_viewer(PocketEntities.wallet), + //wallet_guest(PocketEntities.wallet), + //wallet_collab(PocketEntities.wallet), + wallet_worker(PocketEntities.wallet), + //wallet_control(PocketEntities.wallet), + wallet_manager(PocketEntities.wallet), + wallet_admin(null), + wallet_system(null), + + // wallet slot + //wallet_slot_add(PocketEntities.walletSlot), + //wallet_slot_edit(PocketEntities.walletSlot), + //wallet_slot_find(PocketEntities.walletSlot), + //wallet_slot_enable(PocketEntities.walletSlot), + //wallet_slot_disable(PocketEntities.walletSlot), + //wallet_slot_list(PocketEntities.walletSlot), + //wallet_slot_delete(PocketEntities.walletSlot), + //wallet_slot_preload(PocketEntities.walletSlot), + // + wallet_slot_viewer(PocketEntities.walletSlot), + //wallet_slot_guest(PocketEntities.walletSlot), + //wallet_slot_collab(PocketEntities.walletSlot), + wallet_slot_worker(PocketEntities.walletSlot), + //wallet_slot_control(PocketEntities.walletSlot), + wallet_slot_manager(PocketEntities.walletSlot), + wallet_slot_admin(null), + wallet_slot_system(null), + + // wallet movement + //wallet_movement_add(PocketEntities.walletMovement), + //wallet_movement_edit(PocketEntities.walletMovement), + //wallet_movement_find(PocketEntities.walletMovement), + //wallet_movement_enable(PocketEntities.walletMovement), + //wallet_movement_disable(PocketEntities.walletMovement), + //wallet_movement_list(PocketEntities.walletMovement), + //wallet_movement_delete(PocketEntities.walletMovement), + //wallet_movement_preload(PocketEntities.walletMovement), + // + wallet_movement_viewer(PocketEntities.walletMovement), + //wallet_movement_guest(PocketEntities.walletMovement), + //wallet_movement_collab(PocketEntities.walletMovement), + wallet_movement_worker(PocketEntities.walletMovement), + //wallet_movement_control(PocketEntities.walletMovement), + wallet_movement_manager(PocketEntities.walletMovement), + wallet_movement_admin(null), + wallet_movement_system(null); + + + // ::: + // + private final PocketEntities resourceType; + + PocketPermissions(PocketEntities entityRef) { + this.resourceType = entityRef; + } + + // + public PermissionReference toReference() { + return toReference(null); + } + + public PermissionReference toReference(String resourceKey) { + var ref = new PermissionReference() + .module(PocketConstants.NAME) + .permission(name()) + .error(AppErrors.action_unauthorized); + + if (resourceType != null && resourceKey != null) { + ref.resourceType(resourceType.name()) + .resourceKey(resourceKey); + } + + return ref; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletActionArgument.java b/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletActionArgument.java new file mode 100644 index 0000000..c168bbb --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletActionArgument.java @@ -0,0 +1,29 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.wallet; + +// base +import io.kumare.iqr.app.action.AppEntityActionArgument; +// entity +import io.kumare.iqr.mod.pocket.store.wallet.WalletEntity; + +/** + * + * @author afatecha + */ +public class WalletActionArgument extends AppEntityActionArgument { + + // ::: constructors + // + public WalletActionArgument() { + } + + public WalletActionArgument(WalletEntity entity) { + super(entity); + } + + // ::: api + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletAddAction.java b/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletAddAction.java new file mode 100644 index 0000000..3b49054 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletAddAction.java @@ -0,0 +1,125 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.wallet; + +// java +import java.util.List; +// lib +import io.kumare.lib.base.server.spring.action.Actions; +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.pocket.PocketErrors; +// entity +import io.kumare.iqr.mod.pocket.store.wallet.WalletEntity; + +import io.kumare.iqr.mod.pocket.action.walletslot.WalletSlotAddAction; +import io.kumare.iqr.mod.pocket.action.walletslot.WalletSlotAddArgument; + +/** + * + * @author afatecha + */ +public class WalletAddAction extends AppAction> { + + // ::: vars + // + private WalletEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, PocketErrors.wallet_notfound); + + // relations + + // fields + V.ifEmpty(model.getExternalId(), PocketErrors.wallet_externalid_empty); + V.ifEmpty(model.getEntityKey(), PocketErrors.wallet_entitykey_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + + + + + + + // model + var model = makeModel(); + + // add + entity = saveEntity(model); + + // add others + addSlots(getArgument().getSlots()); + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private WalletEntity makeModel() { + + var argModel = getArgument().getEntity(); + var model = new WalletEntity(); + + // relations + + + // fields + model.setExternalId(argModel.getExternalId()); + model.setEntityKey(argModel.getEntityKey()); + model.setActive(true); + + + + return model; + } + + // ::: save + // + private WalletEntity saveEntity(WalletEntity model) { + + var store = AppModules.pocket.getController().getWalletStore(); + + var saved = store.add(getContext(), model); + getContext().attach(saved.getId(), saved); + return saved; + } + + // ::: add slots + // + private void addSlots(List list) { + if(list != null) { + list.forEach(i->{ + i.getEntity().wallet(entity); + Actions.perform(getContext(), new WalletSlotAddAction(), i); + }); + } + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletAddArgument.java b/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletAddArgument.java new file mode 100644 index 0000000..540b450 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletAddArgument.java @@ -0,0 +1,41 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.wallet; + +// java +import java.util.List; +// app +import io.kumare.iqr.mod.pocket.store.wallet.WalletEntity; +import io.kumare.iqr.mod.pocket.action.walletslot.WalletSlotAddArgument; + +/** + * + * @author afatecha + */ +public class WalletAddArgument extends WalletActionArgument { + + // ::: vars + // + private List slots; + + // ::: constructors + // + public WalletAddArgument() { + } + + public WalletAddArgument(WalletEntity entity) { + super(entity); + } + + // ::: fields + // + public List getSlots() { + return slots; + } + + public void setSlots(List list) { + this.slots = list; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletDeleteAction.java b/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletDeleteAction.java new file mode 100644 index 0000000..be78a74 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletDeleteAction.java @@ -0,0 +1,59 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.wallet; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.pocket.PocketErrors; +// entity +import io.kumare.iqr.mod.pocket.store.wallet.WalletEntity; + +/** + * + * @author afatecha + */ +public class WalletDeleteAction extends AppAction> { + + // ::: vars + // + private WalletEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), PocketErrors.wallet_notfound); + V.ifNull(getArgument().getEntity().getId(), PocketErrors.wallet_notfound); + } + + @Override + protected void doAction() { + + var argModel = getArgument().getEntity(); + + deleteEntity(argModel); + } + + @Override + protected void setResultOnly() { + } + + // ::: delete + // + private void deleteEntity(WalletEntity model) { + + var store = AppModules.pocket.getController().getWalletStore(); + + store.deleteById(getContext(), model.getId()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletEditAction.java b/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletEditAction.java new file mode 100644 index 0000000..6d9b7ea --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletEditAction.java @@ -0,0 +1,95 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.wallet; + +// lib +import io.kumare.lib.v.V; +// app +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.pocket.PocketErrors; +// entity +import io.kumare.iqr.mod.pocket.store.wallet.WalletEntity; + +/** + * + * @author afatecha + */ +public class WalletEditAction extends AppAction> { + + // ::: vars + // + private WalletEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, PocketErrors.wallet_notfound); + + // fields + V.ifEmpty(model.getExternalId(), PocketErrors.wallet_externalid_empty); + V.ifEmpty(model.getEntityKey(), PocketErrors.wallet_entitykey_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + + var pocket = AppModules.pocket.getController(); + var walletStore = pocket.getWalletStore(); + + // edit + entity = walletStore.ensure(getContext(), argModel, PocketErrors.wallet_notfound); + + editEntity(); + + entity = saveEntity(); + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private void editEntity() { + + var model = getArgument().getEntity(); + + // fields + entity.setExternalId(V.firstNotEmpty(model.getExternalId(), entity.getExternalId())); + entity.setEntityKey(V.firstNotEmpty(model.getEntityKey(), entity.getEntityKey())); + + + } + + // ::: save + // + private WalletEntity saveEntity() { + + var store = AppModules.pocket.getController().getWalletStore(); + + var saved = store.edit(getContext(), entity); + getContext().attach(saved.getId(), saved); + return saved; + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletEditArgument.java b/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletEditArgument.java new file mode 100644 index 0000000..f75fef3 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletEditArgument.java @@ -0,0 +1,32 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.wallet; + +// app +import io.kumare.iqr.mod.pocket.store.wallet.WalletEntity; + +/** + * + * @author afatecha + */ +public class WalletEditArgument extends WalletActionArgument { + + // ::: vars + // + + + // ::: constructors + // + public WalletEditArgument() { + } + + public WalletEditArgument(WalletEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletEnableAction.java b/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletEnableAction.java new file mode 100644 index 0000000..62087fa --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletEnableAction.java @@ -0,0 +1,60 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.wallet; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.pocket.PocketErrors; +// entity +import io.kumare.iqr.mod.pocket.store.wallet.WalletEntity; + + +/** + * + * @author afatecha + */ +public class WalletEnableAction extends AppAction { + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), PocketErrors.wallet_notfound); + V.ifNull(getArgument().getEntity().getId(), PocketErrors.wallet_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + + enableEntity(model); + } + + @Override + protected void setResultOnly() { + } + + // ::: enable + // + private void enableEntity(WalletEntity model) { + + var store = AppModules.pocket.getController().getWalletStore(); + + if (getArgument().getEntity().isActive()) { + store.enableById(getContext(), model.getId()); + } else { + store.disableById(getContext(), model.getId()); + } + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletFindAction.java b/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletFindAction.java new file mode 100644 index 0000000..264dde1 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletFindAction.java @@ -0,0 +1,64 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.wallet; + +// java +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.pocket.PocketErrors; +// entity +import io.kumare.iqr.mod.pocket.store.wallet.WalletEntity; + + +/** + * + * @author afatecha + */ +public class WalletFindAction extends AppAction { + + // ::: vars + // + private WalletEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), PocketErrors.wallet_notfound); + V.ifNull(getArgument().getEntity().getId(), PocketErrors.wallet_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + entity = findEntity(model); + } + + @Override + protected void setResultOnly() { + var result = new HashMap(); + result.put("entity", entity); + setResult(result); + } + + // ::: find + // + private WalletEntity findEntity(WalletEntity model) { + + var store = AppModules.pocket.getController().getWalletStore(); + return store.findById(getContext(), model.getId()); + } + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletListAction.java b/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletListAction.java new file mode 100644 index 0000000..951d32f --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletListAction.java @@ -0,0 +1,148 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.wallet; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.LinkedList; +import java.util.Map; +// spring +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// entity +import io.kumare.iqr.mod.pocket.store.wallet.WalletEntity; +import io.kumare.iqr.mod.pocket.store.wallet.WalletMapBuilder; + + +/** + * + * @author afatecha + */ +public class WalletListAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private final List entities = new LinkedList<>(); + + // ::: public api + // + public List getEntities() { + return entities; + } + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + } + + @Override + protected void doAction() { + + result.put("pageable", getArgument().isPageable()); + result.put("wrapped", getArgument().isWrapped()); + + if (getArgument().isPageable()) { + + var page = makePage(); + entities.addAll(page.toList()); + + if (getArgument().isWrapped()) { + result.put("page", makeWrappedPage(page)); + } else { + result.put("page", page); + } + + } else { + + var list = makeList(); + entities.addAll(list); + + if (getArgument().isWrapped()) { + result.put("list", makeWrappedList()); + } else { + result.put("list", list); + } + } + + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: page + // + private Page makePage() { + + var page = getArgument().getPageNumber(); + var size = getArgument().getPageSize(); + //var sort = getArgument().getSort(); + + var pageable = PageRequest.of(page, size); + + var store = AppModules.pocket.getController().getWalletStore(); + return store.getRepository().findAll(pageable); + } + + // ::: wrapped page + // + private Map makeWrappedPage(Page found) { + + var page = new HashMap(); + var content = new LinkedList(); + + wrapList(entities, content); + + page.put("size", found.getSize()); + page.put("number", found.getNumber()); + page.put("totalElements", found.getTotalElements()); + page.put("totalPages", found.getTotalPages()); + page.put("content", content); + + return page; + } + + + // ::: list + // + + private List makeList() { + + var store = AppModules.pocket.getController().getWalletStore(); + + return store.listAll(getContext()); + } + + // ::: wrapped list + private List makeWrappedList() { + var list = new LinkedList(); + + wrapList(entities, list); + + return list; + } + + // ::: wrapper + // + private void wrapList(List found, List output) { + + var builder = new WalletMapBuilder().addListGroup(); + + + output.addAll(builder.build(getContext(), found)); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletListArgument.java b/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletListArgument.java new file mode 100644 index 0000000..7108a56 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletListArgument.java @@ -0,0 +1,33 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.wallet; + +// app +import io.kumare.iqr.app.action.AppListActionArgument; +// store +import io.kumare.iqr.mod.pocket.store.wallet.WalletEntity; + +/** + * + * @author afatecha + */ +public class WalletListArgument extends AppListActionArgument { + + // ::: vars + // + + // ::: constructors + // + public WalletListArgument() { + } + + public WalletListArgument(WalletEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletPreloadAction.java b/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletPreloadAction.java new file mode 100644 index 0000000..2147d43 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletPreloadAction.java @@ -0,0 +1,101 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.wallet; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.pocket.PocketErrors; +// entity +import io.kumare.iqr.mod.pocket.store.wallet.WalletEntity; +// relations + + +/** + * + * @author afatecha + */ +public class WalletPreloadAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private Map params = new HashMap<>(); + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifEmpty(getArgument().getAction(), PocketErrors.wallet_preload_empty); + } + + @Override + protected void doAction() { + if(getArgument().getParams() != null) { + params = getArgument().getParams(); + } + + switch (getArgument().getAction()) { + case "find" -> + prepareFind(); + case "list" -> + prepareList(); + case "add" -> + prepareAdd(); + case "edit" -> + prepareEdit(); + } + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: preload + // + private void prepareAdd() { + + } + + private void prepareEdit() { + var entity = findEntity(); + result.put("entity", entity); + + } + + private void prepareList() { + } + + private void prepareFind() { + var entity = findEntity(); + result.put("entity", entity); + + } + + // ::: queries + // + private WalletEntity findEntity() { + var store = AppModules.pocket.getController().getWalletStore(); + + var id = (String) params.get("id"); + if(id == null && getArgument().getEntity() != null) { + id = getArgument().getEntity().getId(); + } + return store.findById(getContext(), id); + } + + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletPreloadArgument.java b/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletPreloadArgument.java new file mode 100644 index 0000000..aa38679 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/wallet/WalletPreloadArgument.java @@ -0,0 +1,26 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.wallet; + +/** + * + * @author afatecha + */ +public class WalletPreloadArgument extends WalletActionArgument { + + // ::: vars + // + private String action; + + // ::: fields + // + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementActionArgument.java b/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementActionArgument.java new file mode 100644 index 0000000..847376f --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementActionArgument.java @@ -0,0 +1,29 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.walletmovement; + +// base +import io.kumare.iqr.app.action.AppEntityActionArgument; +// entity +import io.kumare.iqr.mod.pocket.store.walletmovement.WalletMovementEntity; + +/** + * + * @author afatecha + */ +public class WalletMovementActionArgument extends AppEntityActionArgument { + + // ::: constructors + // + public WalletMovementActionArgument() { + } + + public WalletMovementActionArgument(WalletMovementEntity entity) { + super(entity); + } + + // ::: api + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementAddAction.java b/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementAddAction.java new file mode 100644 index 0000000..7fd1304 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementAddAction.java @@ -0,0 +1,137 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.walletmovement; + + +// lib +import io.kumare.lib.base.server.spring.action.Actions; +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.pocket.PocketErrors; +// entity +import io.kumare.iqr.mod.pocket.store.walletmovement.WalletMovementEntity; +import io.kumare.iqr.mod.pocket.store.wallet.WalletEntity; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; +import io.kumare.iqr.mod.pocket.store.walletslot.WalletSlotEntity; + + +/** + * + * @author afatecha + */ +public class WalletMovementAddAction extends AppAction> { + + // ::: vars + // + private WalletMovementEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, PocketErrors.walletmovement_notfound); + + // relations + V.ifNull(model.getWallet(), PocketErrors.walletmovement_wallet_notfound); + V.ifNull(model.getWalletSlot(), PocketErrors.walletmovement_walletslot_notfound); + V.ifNull(model.getType(), PocketErrors.walletmovement_type_notfound); + V.ifNull(model.getState(), PocketErrors.walletmovement_state_notfound); + + // fields + V.ifEmpty(model.getExternalId(), PocketErrors.walletmovement_externalid_empty); + V.ifEmpty(model.getTypeValue(), PocketErrors.walletmovement_typevalue_empty); + V.ifEmpty(model.getStateValue(), PocketErrors.walletmovement_statevalue_empty); + V.ifEmpty(model.getDoneDate(), PocketErrors.walletmovement_donedate_empty); + V.ifEmpty(model.getValue(), PocketErrors.walletmovement_value_empty); + V.ifEmpty(model.getUnsignedValue(), PocketErrors.walletmovement_unsignedvalue_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + var taxonomy = AppModules.taxonomy.getController(); + var pocket = AppModules.pocket.getController(); + + var walletStore = pocket.getWalletStore(); + var taxonStore = taxonomy.getTaxonStore(); + var walletSlotStore = pocket.getWalletSlotStore(); + + var wallet = walletStore.ensure(getContext(), argModel.getWallet(), PocketErrors.walletmovement_wallet_notfound); + var walletSlot = walletSlotStore.ensure(getContext(), argModel.getWalletSlot(), PocketErrors.walletmovement_walletslot_notfound); + var type = taxonStore.ensure(getContext(), argModel.getType(), PocketErrors.walletmovement_type_notfound); + var state = taxonStore.ensure(getContext(), argModel.getState(), PocketErrors.walletmovement_state_notfound); + + // model + var model = makeModel(wallet, walletSlot, type, state); + + // add + entity = saveEntity(model); + + // add others + + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private WalletMovementEntity makeModel(WalletEntity wallet, WalletSlotEntity walletSlot, TaxonEntity type, TaxonEntity state) { + + var argModel = getArgument().getEntity(); + var model = new WalletMovementEntity(); + + // relations + model.setWallet(wallet); + model.setWalletSlot(walletSlot); + model.setType(type); + model.setState(state); + + // fields + model.setExternalId(argModel.getExternalId()); + model.setTypeValue(argModel.getTypeValue()); + model.setStateValue(argModel.getStateValue()); + model.setDoneDate(argModel.getDoneDate()); + model.setValue(argModel.getValue()); + model.setUnsignedValue(argModel.getUnsignedValue()); + model.setActive(true); + + + + return model; + } + + // ::: save + // + private WalletMovementEntity saveEntity(WalletMovementEntity model) { + + var store = AppModules.pocket.getController().getWalletMovementStore(); + + var saved = store.add(getContext(), model); + getContext().attach(saved.getId(), saved); + return saved; + } + + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementAddArgument.java b/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementAddArgument.java new file mode 100644 index 0000000..102889c --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementAddArgument.java @@ -0,0 +1,34 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.walletmovement; + + +// app +import io.kumare.iqr.mod.pocket.store.walletmovement.WalletMovementEntity; + + +/** + * + * @author afatecha + */ +public class WalletMovementAddArgument extends WalletMovementActionArgument { + + // ::: vars + // + + + // ::: constructors + // + public WalletMovementAddArgument() { + } + + public WalletMovementAddArgument(WalletMovementEntity entity) { + super(entity); + } + + // ::: fields + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementDeleteAction.java b/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementDeleteAction.java new file mode 100644 index 0000000..2069b37 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementDeleteAction.java @@ -0,0 +1,59 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.walletmovement; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.pocket.PocketErrors; +// entity +import io.kumare.iqr.mod.pocket.store.walletmovement.WalletMovementEntity; + +/** + * + * @author afatecha + */ +public class WalletMovementDeleteAction extends AppAction> { + + // ::: vars + // + private WalletMovementEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), PocketErrors.walletmovement_notfound); + V.ifNull(getArgument().getEntity().getId(), PocketErrors.walletmovement_notfound); + } + + @Override + protected void doAction() { + + var argModel = getArgument().getEntity(); + + deleteEntity(argModel); + } + + @Override + protected void setResultOnly() { + } + + // ::: delete + // + private void deleteEntity(WalletMovementEntity model) { + + var store = AppModules.pocket.getController().getWalletMovementStore(); + + store.deleteById(getContext(), model.getId()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementEditAction.java b/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementEditAction.java new file mode 100644 index 0000000..f329b3b --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementEditAction.java @@ -0,0 +1,103 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.walletmovement; + +// lib +import io.kumare.lib.v.V; +// app +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.pocket.PocketErrors; +// entity +import io.kumare.iqr.mod.pocket.store.walletmovement.WalletMovementEntity; + +/** + * + * @author afatecha + */ +public class WalletMovementEditAction extends AppAction> { + + // ::: vars + // + private WalletMovementEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, PocketErrors.walletmovement_notfound); + + // fields + V.ifEmpty(model.getExternalId(), PocketErrors.walletmovement_externalid_empty); + V.ifEmpty(model.getTypeValue(), PocketErrors.walletmovement_typevalue_empty); + V.ifEmpty(model.getStateValue(), PocketErrors.walletmovement_statevalue_empty); + V.ifEmpty(model.getDoneDate(), PocketErrors.walletmovement_donedate_empty); + V.ifEmpty(model.getValue(), PocketErrors.walletmovement_value_empty); + V.ifEmpty(model.getUnsignedValue(), PocketErrors.walletmovement_unsignedvalue_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + + var pocket = AppModules.pocket.getController(); + var walletMovementStore = pocket.getWalletMovementStore(); + + // edit + entity = walletMovementStore.ensure(getContext(), argModel, PocketErrors.walletmovement_notfound); + + editEntity(); + + entity = saveEntity(); + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private void editEntity() { + + var model = getArgument().getEntity(); + + // fields + entity.setExternalId(V.firstNotEmpty(model.getExternalId(), entity.getExternalId())); + entity.setTypeValue(V.firstNotEmpty(model.getTypeValue(), entity.getTypeValue())); + entity.setStateValue(V.firstNotEmpty(model.getStateValue(), entity.getStateValue())); + entity.setDoneDate(V.firstNotEmpty(model.getDoneDate(), entity.getDoneDate())); + entity.setValue(V.firstNotEmpty(model.getValue(), entity.getValue())); + entity.setUnsignedValue(V.firstNotEmpty(model.getUnsignedValue(), entity.getUnsignedValue())); + + + } + + // ::: save + // + private WalletMovementEntity saveEntity() { + + var store = AppModules.pocket.getController().getWalletMovementStore(); + + var saved = store.edit(getContext(), entity); + getContext().attach(saved.getId(), saved); + return saved; + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementEditArgument.java b/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementEditArgument.java new file mode 100644 index 0000000..0b47580 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementEditArgument.java @@ -0,0 +1,32 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.walletmovement; + +// app +import io.kumare.iqr.mod.pocket.store.walletmovement.WalletMovementEntity; + +/** + * + * @author afatecha + */ +public class WalletMovementEditArgument extends WalletMovementActionArgument { + + // ::: vars + // + + + // ::: constructors + // + public WalletMovementEditArgument() { + } + + public WalletMovementEditArgument(WalletMovementEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementEnableAction.java b/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementEnableAction.java new file mode 100644 index 0000000..87e4bd3 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementEnableAction.java @@ -0,0 +1,60 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.walletmovement; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.pocket.PocketErrors; +// entity +import io.kumare.iqr.mod.pocket.store.walletmovement.WalletMovementEntity; + + +/** + * + * @author afatecha + */ +public class WalletMovementEnableAction extends AppAction { + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), PocketErrors.walletmovement_notfound); + V.ifNull(getArgument().getEntity().getId(), PocketErrors.walletmovement_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + + enableEntity(model); + } + + @Override + protected void setResultOnly() { + } + + // ::: enable + // + private void enableEntity(WalletMovementEntity model) { + + var store = AppModules.pocket.getController().getWalletMovementStore(); + + if (getArgument().getEntity().isActive()) { + store.enableById(getContext(), model.getId()); + } else { + store.disableById(getContext(), model.getId()); + } + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementFindAction.java b/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementFindAction.java new file mode 100644 index 0000000..7f2aa77 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementFindAction.java @@ -0,0 +1,64 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.walletmovement; + +// java +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.pocket.PocketErrors; +// entity +import io.kumare.iqr.mod.pocket.store.walletmovement.WalletMovementEntity; + + +/** + * + * @author afatecha + */ +public class WalletMovementFindAction extends AppAction { + + // ::: vars + // + private WalletMovementEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), PocketErrors.walletmovement_notfound); + V.ifNull(getArgument().getEntity().getId(), PocketErrors.walletmovement_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + entity = findEntity(model); + } + + @Override + protected void setResultOnly() { + var result = new HashMap(); + result.put("entity", entity); + setResult(result); + } + + // ::: find + // + private WalletMovementEntity findEntity(WalletMovementEntity model) { + + var store = AppModules.pocket.getController().getWalletMovementStore(); + return store.findById(getContext(), model.getId()); + } + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementListAction.java b/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementListAction.java new file mode 100644 index 0000000..86cf0fc --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementListAction.java @@ -0,0 +1,151 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.walletmovement; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.LinkedList; +import java.util.Map; +// spring +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// entity +import io.kumare.iqr.mod.pocket.store.walletmovement.WalletMovementEntity; +import io.kumare.iqr.mod.pocket.store.walletmovement.WalletMovementMapBuilder; + + +/** + * + * @author afatecha + */ +public class WalletMovementListAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private final List entities = new LinkedList<>(); + + // ::: public api + // + public List getEntities() { + return entities; + } + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + } + + @Override + protected void doAction() { + + result.put("pageable", getArgument().isPageable()); + result.put("wrapped", getArgument().isWrapped()); + + if (getArgument().isPageable()) { + + var page = makePage(); + entities.addAll(page.toList()); + + if (getArgument().isWrapped()) { + result.put("page", makeWrappedPage(page)); + } else { + result.put("page", page); + } + + } else { + + var list = makeList(); + entities.addAll(list); + + if (getArgument().isWrapped()) { + result.put("list", makeWrappedList()); + } else { + result.put("list", list); + } + } + + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: page + // + private Page makePage() { + + var page = getArgument().getPageNumber(); + var size = getArgument().getPageSize(); + //var sort = getArgument().getSort(); + + var pageable = PageRequest.of(page, size); + + var store = AppModules.pocket.getController().getWalletMovementStore(); + return store.getRepository().findAll(pageable); + } + + // ::: wrapped page + // + private Map makeWrappedPage(Page found) { + + var page = new HashMap(); + var content = new LinkedList(); + + wrapList(entities, content); + + page.put("size", found.getSize()); + page.put("number", found.getNumber()); + page.put("totalElements", found.getTotalElements()); + page.put("totalPages", found.getTotalPages()); + page.put("content", content); + + return page; + } + + + // ::: list + // + + private List makeList() { + + var store = AppModules.pocket.getController().getWalletMovementStore(); + + return store.listAll(getContext()); + } + + // ::: wrapped list + private List makeWrappedList() { + var list = new LinkedList(); + + wrapList(entities, list); + + return list; + } + + // ::: wrapper + // + private void wrapList(List found, List output) { + + var builder = new WalletMovementMapBuilder().addListGroup(); + builder.getWalletBuilder().addMainGroup(); + builder.getWalletSlotBuilder().addMainGroup(); + builder.getTypeBuilder().addMainGroup(); + builder.getStateBuilder().addMainGroup(); + + output.addAll(builder.build(getContext(), found)); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementListArgument.java b/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementListArgument.java new file mode 100644 index 0000000..f2ae491 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementListArgument.java @@ -0,0 +1,33 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.walletmovement; + +// app +import io.kumare.iqr.app.action.AppListActionArgument; +// store +import io.kumare.iqr.mod.pocket.store.walletmovement.WalletMovementEntity; + +/** + * + * @author afatecha + */ +public class WalletMovementListArgument extends AppListActionArgument { + + // ::: vars + // + + // ::: constructors + // + public WalletMovementListArgument() { + } + + public WalletMovementListArgument(WalletMovementEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementPreloadAction.java b/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementPreloadAction.java new file mode 100644 index 0000000..b551328 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementPreloadAction.java @@ -0,0 +1,125 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.walletmovement; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.pocket.PocketErrors; +// entity +import io.kumare.iqr.mod.pocket.store.walletmovement.WalletMovementEntity; +// relations +import io.kumare.iqr.mod.pocket.store.wallet.WalletEntity; +import io.kumare.iqr.mod.pocket.store.walletslot.WalletSlotEntity; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; + +/** + * + * @author afatecha + */ +public class WalletMovementPreloadAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private Map params = new HashMap<>(); + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifEmpty(getArgument().getAction(), PocketErrors.walletmovement_preload_empty); + } + + @Override + protected void doAction() { + if(getArgument().getParams() != null) { + params = getArgument().getParams(); + } + + switch (getArgument().getAction()) { + case "find" -> + prepareFind(); + case "list" -> + prepareList(); + case "add" -> + prepareAdd(); + case "edit" -> + prepareEdit(); + } + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: preload + // + private void prepareAdd() { + result.put("taxons", listTaxons()); + result.put("walletSlots", listWalletSlots()); + result.put("wallets", listWallets()); + } + + private void prepareEdit() { + var entity = findEntity(); + result.put("entity", entity); + result.put("wallet", entity.getWallet()); + result.put("walletSlot", entity.getWalletSlot()); + result.put("type", entity.getType()); + result.put("state", entity.getState()); + } + + private void prepareList() { + } + + private void prepareFind() { + var entity = findEntity(); + result.put("entity", entity); + result.put("wallet", entity.getWallet()); + result.put("walletSlot", entity.getWalletSlot()); + result.put("type", entity.getType()); + result.put("state", entity.getState()); + } + + // ::: queries + // + private WalletMovementEntity findEntity() { + var store = AppModules.pocket.getController().getWalletMovementStore(); + + var id = (String) params.get("id"); + if(id == null && getArgument().getEntity() != null) { + id = getArgument().getEntity().getId(); + } + return store.findById(getContext(), id); + } + + public List listWalletSlots() { + var store = AppModules.pocket.getController().getWalletSlotStore(); + + return store.listAll(getContext()); + } + public List listTaxons() { + var store = AppModules.taxonomy.getController().getTaxonStore(); + + return store.listAll(getContext()); + } + public List listWallets() { + var store = AppModules.pocket.getController().getWalletStore(); + + return store.listAll(getContext()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementPreloadArgument.java b/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementPreloadArgument.java new file mode 100644 index 0000000..6920c02 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/walletmovement/WalletMovementPreloadArgument.java @@ -0,0 +1,26 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.walletmovement; + +/** + * + * @author afatecha + */ +public class WalletMovementPreloadArgument extends WalletMovementActionArgument { + + // ::: vars + // + private String action; + + // ::: fields + // + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotActionArgument.java b/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotActionArgument.java new file mode 100644 index 0000000..dbccfb3 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotActionArgument.java @@ -0,0 +1,29 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.walletslot; + +// base +import io.kumare.iqr.app.action.AppEntityActionArgument; +// entity +import io.kumare.iqr.mod.pocket.store.walletslot.WalletSlotEntity; + +/** + * + * @author afatecha + */ +public class WalletSlotActionArgument extends AppEntityActionArgument { + + // ::: constructors + // + public WalletSlotActionArgument() { + } + + public WalletSlotActionArgument(WalletSlotEntity entity) { + super(entity); + } + + // ::: api + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotAddAction.java b/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotAddAction.java new file mode 100644 index 0000000..56a09c4 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotAddAction.java @@ -0,0 +1,117 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.walletslot; + + +// lib +import io.kumare.lib.base.server.spring.action.Actions; +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.pocket.PocketErrors; +// entity +import io.kumare.iqr.mod.pocket.store.walletslot.WalletSlotEntity; +import io.kumare.iqr.mod.pocket.store.wallet.WalletEntity; + + +/** + * + * @author afatecha + */ +public class WalletSlotAddAction extends AppAction> { + + // ::: vars + // + private WalletSlotEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, PocketErrors.walletslot_notfound); + + // relations + V.ifNull(model.getWallet(), PocketErrors.walletslot_wallet_notfound); + + // fields + V.ifEmpty(model.getEntityKey(), PocketErrors.walletslot_entitykey_empty); + V.ifEmpty(model.getConceptKey(), PocketErrors.walletslot_conceptkey_empty); + V.ifEmpty(model.getPoints(), PocketErrors.walletslot_points_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + var pocket = AppModules.pocket.getController(); + + var walletStore = pocket.getWalletStore(); + + var wallet = walletStore.ensure(getContext(), argModel.getWallet(), PocketErrors.walletslot_wallet_notfound); + + // model + var model = makeModel(wallet); + + // add + entity = saveEntity(model); + + // add others + + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private WalletSlotEntity makeModel(WalletEntity wallet) { + + var argModel = getArgument().getEntity(); + var model = new WalletSlotEntity(); + + // relations + model.setWallet(wallet); + + // fields + model.setEntityKey(argModel.getEntityKey()); + model.setConceptKey(argModel.getConceptKey()); + model.setPoints(argModel.getPoints()); + model.setActive(true); + + + + return model; + } + + // ::: save + // + private WalletSlotEntity saveEntity(WalletSlotEntity model) { + + var store = AppModules.pocket.getController().getWalletSlotStore(); + + var saved = store.add(getContext(), model); + getContext().attach(saved.getId(), saved); + return saved; + } + + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotAddArgument.java b/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotAddArgument.java new file mode 100644 index 0000000..119ab79 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotAddArgument.java @@ -0,0 +1,34 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.walletslot; + + +// app +import io.kumare.iqr.mod.pocket.store.walletslot.WalletSlotEntity; + + +/** + * + * @author afatecha + */ +public class WalletSlotAddArgument extends WalletSlotActionArgument { + + // ::: vars + // + + + // ::: constructors + // + public WalletSlotAddArgument() { + } + + public WalletSlotAddArgument(WalletSlotEntity entity) { + super(entity); + } + + // ::: fields + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotDeleteAction.java b/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotDeleteAction.java new file mode 100644 index 0000000..49a78cb --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotDeleteAction.java @@ -0,0 +1,59 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.walletslot; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.pocket.PocketErrors; +// entity +import io.kumare.iqr.mod.pocket.store.walletslot.WalletSlotEntity; + +/** + * + * @author afatecha + */ +public class WalletSlotDeleteAction extends AppAction> { + + // ::: vars + // + private WalletSlotEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), PocketErrors.walletslot_notfound); + V.ifNull(getArgument().getEntity().getId(), PocketErrors.walletslot_notfound); + } + + @Override + protected void doAction() { + + var argModel = getArgument().getEntity(); + + deleteEntity(argModel); + } + + @Override + protected void setResultOnly() { + } + + // ::: delete + // + private void deleteEntity(WalletSlotEntity model) { + + var store = AppModules.pocket.getController().getWalletSlotStore(); + + store.deleteById(getContext(), model.getId()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotEditAction.java b/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotEditAction.java new file mode 100644 index 0000000..ee60638 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotEditAction.java @@ -0,0 +1,97 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.walletslot; + +// lib +import io.kumare.lib.v.V; +// app +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.pocket.PocketErrors; +// entity +import io.kumare.iqr.mod.pocket.store.walletslot.WalletSlotEntity; + +/** + * + * @author afatecha + */ +public class WalletSlotEditAction extends AppAction> { + + // ::: vars + // + private WalletSlotEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, PocketErrors.walletslot_notfound); + + // fields + V.ifEmpty(model.getEntityKey(), PocketErrors.walletslot_entitykey_empty); + V.ifEmpty(model.getConceptKey(), PocketErrors.walletslot_conceptkey_empty); + V.ifEmpty(model.getPoints(), PocketErrors.walletslot_points_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + + var pocket = AppModules.pocket.getController(); + var walletSlotStore = pocket.getWalletSlotStore(); + + // edit + entity = walletSlotStore.ensure(getContext(), argModel, PocketErrors.walletslot_notfound); + + editEntity(); + + entity = saveEntity(); + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private void editEntity() { + + var model = getArgument().getEntity(); + + // fields + entity.setEntityKey(V.firstNotEmpty(model.getEntityKey(), entity.getEntityKey())); + entity.setConceptKey(V.firstNotEmpty(model.getConceptKey(), entity.getConceptKey())); + entity.setPoints(V.firstNotEmpty(model.getPoints(), entity.getPoints())); + + + } + + // ::: save + // + private WalletSlotEntity saveEntity() { + + var store = AppModules.pocket.getController().getWalletSlotStore(); + + var saved = store.edit(getContext(), entity); + getContext().attach(saved.getId(), saved); + return saved; + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotEditArgument.java b/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotEditArgument.java new file mode 100644 index 0000000..ea3aeba --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotEditArgument.java @@ -0,0 +1,32 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.walletslot; + +// app +import io.kumare.iqr.mod.pocket.store.walletslot.WalletSlotEntity; + +/** + * + * @author afatecha + */ +public class WalletSlotEditArgument extends WalletSlotActionArgument { + + // ::: vars + // + + + // ::: constructors + // + public WalletSlotEditArgument() { + } + + public WalletSlotEditArgument(WalletSlotEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotEnableAction.java b/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotEnableAction.java new file mode 100644 index 0000000..8e054c9 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotEnableAction.java @@ -0,0 +1,60 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.walletslot; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.pocket.PocketErrors; +// entity +import io.kumare.iqr.mod.pocket.store.walletslot.WalletSlotEntity; + + +/** + * + * @author afatecha + */ +public class WalletSlotEnableAction extends AppAction { + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), PocketErrors.walletslot_notfound); + V.ifNull(getArgument().getEntity().getId(), PocketErrors.walletslot_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + + enableEntity(model); + } + + @Override + protected void setResultOnly() { + } + + // ::: enable + // + private void enableEntity(WalletSlotEntity model) { + + var store = AppModules.pocket.getController().getWalletSlotStore(); + + if (getArgument().getEntity().isActive()) { + store.enableById(getContext(), model.getId()); + } else { + store.disableById(getContext(), model.getId()); + } + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotFindAction.java b/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotFindAction.java new file mode 100644 index 0000000..0828f5a --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotFindAction.java @@ -0,0 +1,64 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.walletslot; + +// java +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.pocket.PocketErrors; +// entity +import io.kumare.iqr.mod.pocket.store.walletslot.WalletSlotEntity; + + +/** + * + * @author afatecha + */ +public class WalletSlotFindAction extends AppAction { + + // ::: vars + // + private WalletSlotEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), PocketErrors.walletslot_notfound); + V.ifNull(getArgument().getEntity().getId(), PocketErrors.walletslot_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + entity = findEntity(model); + } + + @Override + protected void setResultOnly() { + var result = new HashMap(); + result.put("entity", entity); + setResult(result); + } + + // ::: find + // + private WalletSlotEntity findEntity(WalletSlotEntity model) { + + var store = AppModules.pocket.getController().getWalletSlotStore(); + return store.findById(getContext(), model.getId()); + } + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotListAction.java b/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotListAction.java new file mode 100644 index 0000000..5fdef01 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotListAction.java @@ -0,0 +1,148 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.walletslot; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.LinkedList; +import java.util.Map; +// spring +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// entity +import io.kumare.iqr.mod.pocket.store.walletslot.WalletSlotEntity; +import io.kumare.iqr.mod.pocket.store.walletslot.WalletSlotMapBuilder; + + +/** + * + * @author afatecha + */ +public class WalletSlotListAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private final List entities = new LinkedList<>(); + + // ::: public api + // + public List getEntities() { + return entities; + } + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + } + + @Override + protected void doAction() { + + result.put("pageable", getArgument().isPageable()); + result.put("wrapped", getArgument().isWrapped()); + + if (getArgument().isPageable()) { + + var page = makePage(); + entities.addAll(page.toList()); + + if (getArgument().isWrapped()) { + result.put("page", makeWrappedPage(page)); + } else { + result.put("page", page); + } + + } else { + + var list = makeList(); + entities.addAll(list); + + if (getArgument().isWrapped()) { + result.put("list", makeWrappedList()); + } else { + result.put("list", list); + } + } + + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: page + // + private Page makePage() { + + var page = getArgument().getPageNumber(); + var size = getArgument().getPageSize(); + //var sort = getArgument().getSort(); + + var pageable = PageRequest.of(page, size); + + var store = AppModules.pocket.getController().getWalletSlotStore(); + return store.getRepository().findAll(pageable); + } + + // ::: wrapped page + // + private Map makeWrappedPage(Page found) { + + var page = new HashMap(); + var content = new LinkedList(); + + wrapList(entities, content); + + page.put("size", found.getSize()); + page.put("number", found.getNumber()); + page.put("totalElements", found.getTotalElements()); + page.put("totalPages", found.getTotalPages()); + page.put("content", content); + + return page; + } + + + // ::: list + // + + private List makeList() { + + var store = AppModules.pocket.getController().getWalletSlotStore(); + + return store.listAll(getContext()); + } + + // ::: wrapped list + private List makeWrappedList() { + var list = new LinkedList(); + + wrapList(entities, list); + + return list; + } + + // ::: wrapper + // + private void wrapList(List found, List output) { + + var builder = new WalletSlotMapBuilder().addListGroup(); + builder.getWalletBuilder().addMainGroup(); + + output.addAll(builder.build(getContext(), found)); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotListArgument.java b/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotListArgument.java new file mode 100644 index 0000000..712e5cb --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotListArgument.java @@ -0,0 +1,33 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.walletslot; + +// app +import io.kumare.iqr.app.action.AppListActionArgument; +// store +import io.kumare.iqr.mod.pocket.store.walletslot.WalletSlotEntity; + +/** + * + * @author afatecha + */ +public class WalletSlotListArgument extends AppListActionArgument { + + // ::: vars + // + + // ::: constructors + // + public WalletSlotListArgument() { + } + + public WalletSlotListArgument(WalletSlotEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotPreloadAction.java b/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotPreloadAction.java new file mode 100644 index 0000000..6b2b77d --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotPreloadAction.java @@ -0,0 +1,105 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.walletslot; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.pocket.PocketErrors; +// entity +import io.kumare.iqr.mod.pocket.store.walletslot.WalletSlotEntity; +// relations +import io.kumare.iqr.mod.pocket.store.wallet.WalletEntity; + +/** + * + * @author afatecha + */ +public class WalletSlotPreloadAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private Map params = new HashMap<>(); + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifEmpty(getArgument().getAction(), PocketErrors.walletslot_preload_empty); + } + + @Override + protected void doAction() { + if(getArgument().getParams() != null) { + params = getArgument().getParams(); + } + + switch (getArgument().getAction()) { + case "find" -> + prepareFind(); + case "list" -> + prepareList(); + case "add" -> + prepareAdd(); + case "edit" -> + prepareEdit(); + } + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: preload + // + private void prepareAdd() { + result.put("wallets", listWallets()); + } + + private void prepareEdit() { + var entity = findEntity(); + result.put("entity", entity); + result.put("wallet", entity.getWallet()); + } + + private void prepareList() { + } + + private void prepareFind() { + var entity = findEntity(); + result.put("entity", entity); + result.put("wallet", entity.getWallet()); + } + + // ::: queries + // + private WalletSlotEntity findEntity() { + var store = AppModules.pocket.getController().getWalletSlotStore(); + + var id = (String) params.get("id"); + if(id == null && getArgument().getEntity() != null) { + id = getArgument().getEntity().getId(); + } + return store.findById(getContext(), id); + } + + public List listWallets() { + var store = AppModules.pocket.getController().getWalletStore(); + + return store.listAll(getContext()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotPreloadArgument.java b/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotPreloadArgument.java new file mode 100644 index 0000000..e4c2bd0 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/action/walletslot/WalletSlotPreloadArgument.java @@ -0,0 +1,26 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.action.walletslot; + +/** + * + * @author afatecha + */ +public class WalletSlotPreloadArgument extends WalletSlotActionArgument { + + // ::: vars + // + private String action; + + // ::: fields + // + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/endpoint/rest/AbstractWalletMovementRest.java b/src/main/java/io/kumare/iqr/mod/pocket/endpoint/rest/AbstractWalletMovementRest.java new file mode 100644 index 0000000..2543a7a --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/endpoint/rest/AbstractWalletMovementRest.java @@ -0,0 +1,214 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.endpoint.rest; + +// java +import java.util.Map; +// openapi +import io.swagger.v3.oas.annotations.*; +import io.swagger.v3.oas.annotations.media.*; +import io.swagger.v3.oas.annotations.responses.*; +// spring +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +// base +import io.kumare.lib.app.api.operation.TransactionType; +import io.kumare.lib.app.api.security.PermissionReference; +// app +import io.kumare.iqr.app.endpoint.rest.AppEndpointRest; +import io.kumare.iqr.app.action.*; +// module +import io.kumare.iqr.mod.pocket.PocketPermissions; +import io.kumare.iqr.mod.pocket.store.walletmovement.WalletMovementEntity; +import io.kumare.iqr.mod.pocket.action.walletmovement.*; + +/** +* +* @author afatecha +*/ +public abstract class AbstractWalletMovementRest extends AppEndpointRest { + + // ::: DEFAULT PERMISSIONS + // + protected PermissionReference getPermission(String action, String ref, Object extra) { + switch (action) { + case null -> { + return null; + } + case "add" -> { + return PocketPermissions.wallet_movement_worker.toReference(ref); + } + case "edit" -> { + return PocketPermissions.wallet_movement_worker.toReference(ref); + } + case "enable" -> { + return PocketPermissions.wallet_movement_manager.toReference(ref); + } + case "disable" -> { + return PocketPermissions.wallet_movement_manager.toReference(ref); + } + case "delete" -> { + return PocketPermissions.wallet_movement_manager.toReference(ref); + } + case "find" -> { + return PocketPermissions.wallet_movement_viewer.toReference(ref); + } + case "list" -> { + return PocketPermissions.wallet_movement_viewer.toReference(ref); + } + default -> { + return null; + } + } + } + + + // ::: ADD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "wallet movement add operation", description = "") + // + @PostMapping + public ResponseEntity add(@RequestBody WalletMovementAddArgument arg) { + + var permission = getPermission("add", null, arg); + return handle(new WalletMovementAddAction(), arg, permission, TransactionType.service); + } + + // ::: EDIT + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "wallet movement edit operation", description = "") + // + @PutMapping("/{id}") + public ResponseEntity edit(@PathVariable("id") String id, + @RequestBody WalletMovementEditArgument arg) { + + arg.getEntity().id(id); + + var permission = getPermission("edit", id, arg); + return handle(new WalletMovementEditAction(), arg, permission, TransactionType.service); + } + + // ::: FIND + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "wallet movement find operation", description = "") + // + @GetMapping("/{id}") + public ResponseEntity find(@PathVariable("id") String id, + @ModelAttribute WalletMovementActionArgument arg) { + + + arg = arg == null ? new WalletMovementActionArgument() : arg; + + arg.entity(new WalletMovementEntity(id)); + + var permission = getPermission("find", id, arg); + return handle(new WalletMovementFindAction(), arg, permission); + } + + // ::: ENABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "wallet movement enable operation", description = "") + // + @PutMapping("/{id}/enable") + public ResponseEntity enable(@PathVariable("id") String id) { + + var arg = new WalletMovementActionArgument(); + arg.setEntity(new WalletMovementEntity(id)); + arg.getEntity().setActive(true); + + var permission = getPermission("disable", id, arg); + return handle(new WalletMovementEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: DISABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "wallet movement disable operation", description = "") + // + @PutMapping("/{id}/disable") + public ResponseEntity disable(@PathVariable("id") String id) { + + var arg = new WalletMovementActionArgument(); + arg.setEntity(new WalletMovementEntity(id)); + arg.getEntity().setActive(false); + + var permission = getPermission("disable", id, arg); + return handle(new WalletMovementEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: LIST + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "wallet movement list operation", description = "") + // + @GetMapping + public ResponseEntity list(@ModelAttribute WalletMovementListArgument arg) { + + arg = arg == null ? new WalletMovementListArgument() : arg; + + var permission = getPermission("list", null, arg); + return handle(new WalletMovementListAction(), arg, permission); + } + + // ::: DELETE + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "wallet movement delete operation", description = "") + // + @DeleteMapping("/{id}") + public ResponseEntity delete(@PathVariable("id") String id) { + + var arg = new WalletMovementActionArgument(); + + arg.setEntity(new WalletMovementEntity(id)); + + var permission = getPermission("delete", id, arg); + return handle(new WalletMovementDeleteAction(), arg, permission, TransactionType.service); + } + + // ::: PRELOAD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "wallet movement preload operation", description = "") + // + @PostMapping("/preload") + public ResponseEntity preload(@RequestBody WalletMovementPreloadArgument arg) { + + var permission = getPermission(arg.getAction(), null, arg); + return handle(new WalletMovementPreloadAction(), arg, permission); + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/endpoint/rest/AbstractWalletRest.java b/src/main/java/io/kumare/iqr/mod/pocket/endpoint/rest/AbstractWalletRest.java new file mode 100644 index 0000000..bf3c623 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/endpoint/rest/AbstractWalletRest.java @@ -0,0 +1,214 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.endpoint.rest; + +// java +import java.util.Map; +// openapi +import io.swagger.v3.oas.annotations.*; +import io.swagger.v3.oas.annotations.media.*; +import io.swagger.v3.oas.annotations.responses.*; +// spring +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +// base +import io.kumare.lib.app.api.operation.TransactionType; +import io.kumare.lib.app.api.security.PermissionReference; +// app +import io.kumare.iqr.app.endpoint.rest.AppEndpointRest; +import io.kumare.iqr.app.action.*; +// module +import io.kumare.iqr.mod.pocket.PocketPermissions; +import io.kumare.iqr.mod.pocket.store.wallet.WalletEntity; +import io.kumare.iqr.mod.pocket.action.wallet.*; + +/** +* +* @author afatecha +*/ +public abstract class AbstractWalletRest extends AppEndpointRest { + + // ::: DEFAULT PERMISSIONS + // + protected PermissionReference getPermission(String action, String ref, Object extra) { + switch (action) { + case null -> { + return null; + } + case "add" -> { + return PocketPermissions.wallet_worker.toReference(ref); + } + case "edit" -> { + return PocketPermissions.wallet_worker.toReference(ref); + } + case "enable" -> { + return PocketPermissions.wallet_manager.toReference(ref); + } + case "disable" -> { + return PocketPermissions.wallet_manager.toReference(ref); + } + case "delete" -> { + return PocketPermissions.wallet_manager.toReference(ref); + } + case "find" -> { + return PocketPermissions.wallet_viewer.toReference(ref); + } + case "list" -> { + return PocketPermissions.wallet_viewer.toReference(ref); + } + default -> { + return null; + } + } + } + + + // ::: ADD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "wallet add operation", description = "") + // + @PostMapping + public ResponseEntity add(@RequestBody WalletAddArgument arg) { + + var permission = getPermission("add", null, arg); + return handle(new WalletAddAction(), arg, permission, TransactionType.service); + } + + // ::: EDIT + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "wallet edit operation", description = "") + // + @PutMapping("/{id}") + public ResponseEntity edit(@PathVariable("id") String id, + @RequestBody WalletEditArgument arg) { + + arg.getEntity().id(id); + + var permission = getPermission("edit", id, arg); + return handle(new WalletEditAction(), arg, permission, TransactionType.service); + } + + // ::: FIND + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "wallet find operation", description = "") + // + @GetMapping("/{id}") + public ResponseEntity find(@PathVariable("id") String id, + @ModelAttribute WalletActionArgument arg) { + + + arg = arg == null ? new WalletActionArgument() : arg; + + arg.entity(new WalletEntity(id)); + + var permission = getPermission("find", id, arg); + return handle(new WalletFindAction(), arg, permission); + } + + // ::: ENABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "wallet enable operation", description = "") + // + @PutMapping("/{id}/enable") + public ResponseEntity enable(@PathVariable("id") String id) { + + var arg = new WalletActionArgument(); + arg.setEntity(new WalletEntity(id)); + arg.getEntity().setActive(true); + + var permission = getPermission("disable", id, arg); + return handle(new WalletEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: DISABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "wallet disable operation", description = "") + // + @PutMapping("/{id}/disable") + public ResponseEntity disable(@PathVariable("id") String id) { + + var arg = new WalletActionArgument(); + arg.setEntity(new WalletEntity(id)); + arg.getEntity().setActive(false); + + var permission = getPermission("disable", id, arg); + return handle(new WalletEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: LIST + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "wallet list operation", description = "") + // + @GetMapping + public ResponseEntity list(@ModelAttribute WalletListArgument arg) { + + arg = arg == null ? new WalletListArgument() : arg; + + var permission = getPermission("list", null, arg); + return handle(new WalletListAction(), arg, permission); + } + + // ::: DELETE + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "wallet delete operation", description = "") + // + @DeleteMapping("/{id}") + public ResponseEntity delete(@PathVariable("id") String id) { + + var arg = new WalletActionArgument(); + + arg.setEntity(new WalletEntity(id)); + + var permission = getPermission("delete", id, arg); + return handle(new WalletDeleteAction(), arg, permission, TransactionType.service); + } + + // ::: PRELOAD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "wallet preload operation", description = "") + // + @PostMapping("/preload") + public ResponseEntity preload(@RequestBody WalletPreloadArgument arg) { + + var permission = getPermission(arg.getAction(), null, arg); + return handle(new WalletPreloadAction(), arg, permission); + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/endpoint/rest/AbstractWalletSlotRest.java b/src/main/java/io/kumare/iqr/mod/pocket/endpoint/rest/AbstractWalletSlotRest.java new file mode 100644 index 0000000..e0b2aa6 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/endpoint/rest/AbstractWalletSlotRest.java @@ -0,0 +1,214 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.endpoint.rest; + +// java +import java.util.Map; +// openapi +import io.swagger.v3.oas.annotations.*; +import io.swagger.v3.oas.annotations.media.*; +import io.swagger.v3.oas.annotations.responses.*; +// spring +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +// base +import io.kumare.lib.app.api.operation.TransactionType; +import io.kumare.lib.app.api.security.PermissionReference; +// app +import io.kumare.iqr.app.endpoint.rest.AppEndpointRest; +import io.kumare.iqr.app.action.*; +// module +import io.kumare.iqr.mod.pocket.PocketPermissions; +import io.kumare.iqr.mod.pocket.store.walletslot.WalletSlotEntity; +import io.kumare.iqr.mod.pocket.action.walletslot.*; + +/** +* +* @author afatecha +*/ +public abstract class AbstractWalletSlotRest extends AppEndpointRest { + + // ::: DEFAULT PERMISSIONS + // + protected PermissionReference getPermission(String action, String ref, Object extra) { + switch (action) { + case null -> { + return null; + } + case "add" -> { + return PocketPermissions.wallet_slot_worker.toReference(ref); + } + case "edit" -> { + return PocketPermissions.wallet_slot_worker.toReference(ref); + } + case "enable" -> { + return PocketPermissions.wallet_slot_manager.toReference(ref); + } + case "disable" -> { + return PocketPermissions.wallet_slot_manager.toReference(ref); + } + case "delete" -> { + return PocketPermissions.wallet_slot_manager.toReference(ref); + } + case "find" -> { + return PocketPermissions.wallet_slot_viewer.toReference(ref); + } + case "list" -> { + return PocketPermissions.wallet_slot_viewer.toReference(ref); + } + default -> { + return null; + } + } + } + + + // ::: ADD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "wallet slot add operation", description = "") + // + @PostMapping + public ResponseEntity add(@RequestBody WalletSlotAddArgument arg) { + + var permission = getPermission("add", null, arg); + return handle(new WalletSlotAddAction(), arg, permission, TransactionType.service); + } + + // ::: EDIT + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "wallet slot edit operation", description = "") + // + @PutMapping("/{id}") + public ResponseEntity edit(@PathVariable("id") String id, + @RequestBody WalletSlotEditArgument arg) { + + arg.getEntity().id(id); + + var permission = getPermission("edit", id, arg); + return handle(new WalletSlotEditAction(), arg, permission, TransactionType.service); + } + + // ::: FIND + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "wallet slot find operation", description = "") + // + @GetMapping("/{id}") + public ResponseEntity find(@PathVariable("id") String id, + @ModelAttribute WalletSlotActionArgument arg) { + + + arg = arg == null ? new WalletSlotActionArgument() : arg; + + arg.entity(new WalletSlotEntity(id)); + + var permission = getPermission("find", id, arg); + return handle(new WalletSlotFindAction(), arg, permission); + } + + // ::: ENABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "wallet slot enable operation", description = "") + // + @PutMapping("/{id}/enable") + public ResponseEntity enable(@PathVariable("id") String id) { + + var arg = new WalletSlotActionArgument(); + arg.setEntity(new WalletSlotEntity(id)); + arg.getEntity().setActive(true); + + var permission = getPermission("disable", id, arg); + return handle(new WalletSlotEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: DISABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "wallet slot disable operation", description = "") + // + @PutMapping("/{id}/disable") + public ResponseEntity disable(@PathVariable("id") String id) { + + var arg = new WalletSlotActionArgument(); + arg.setEntity(new WalletSlotEntity(id)); + arg.getEntity().setActive(false); + + var permission = getPermission("disable", id, arg); + return handle(new WalletSlotEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: LIST + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "wallet slot list operation", description = "") + // + @GetMapping + public ResponseEntity list(@ModelAttribute WalletSlotListArgument arg) { + + arg = arg == null ? new WalletSlotListArgument() : arg; + + var permission = getPermission("list", null, arg); + return handle(new WalletSlotListAction(), arg, permission); + } + + // ::: DELETE + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "wallet slot delete operation", description = "") + // + @DeleteMapping("/{id}") + public ResponseEntity delete(@PathVariable("id") String id) { + + var arg = new WalletSlotActionArgument(); + + arg.setEntity(new WalletSlotEntity(id)); + + var permission = getPermission("delete", id, arg); + return handle(new WalletSlotDeleteAction(), arg, permission, TransactionType.service); + } + + // ::: PRELOAD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "wallet slot preload operation", description = "") + // + @PostMapping("/preload") + public ResponseEntity preload(@RequestBody WalletSlotPreloadArgument arg) { + + var permission = getPermission(arg.getAction(), null, arg); + return handle(new WalletSlotPreloadAction(), arg, permission); + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/endpoint/rest/PocketTaxonomyRest.java b/src/main/java/io/kumare/iqr/mod/pocket/endpoint/rest/PocketTaxonomyRest.java new file mode 100644 index 0000000..cf43ccf --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/endpoint/rest/PocketTaxonomyRest.java @@ -0,0 +1,25 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.endpoint.rest; + +// java +import io.kumare.iqr.mod.taxonomy.endpoint.rest.AbstractTaxonRest; +import io.swagger.v3.oas.annotations.tags.*; +// spring +import org.springframework.web.bind.annotation.*; + +/** +* +* @author afatecha +*/ + +// openapi +@Tag(name = "workforce taxonomy rest endpoint") +// +@RestController +@RequestMapping("/pocket/{taxaKey}-taxons") +public class PocketTaxonomyRest extends AbstractTaxonRest { + + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/endpoint/rest/WalletMovementRest.java b/src/main/java/io/kumare/iqr/mod/pocket/endpoint/rest/WalletMovementRest.java new file mode 100644 index 0000000..3addffb --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/endpoint/rest/WalletMovementRest.java @@ -0,0 +1,24 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.endpoint.rest; + +// java +import io.swagger.v3.oas.annotations.tags.*; +// spring +import org.springframework.web.bind.annotation.*; + +/** +* +* @author afatecha +*/ + +// openapi +//@Tag(name = "wallet movement rest endpoint") +// +//@RestController +//@RequestMapping("/pocket/wallet-movements") +public class WalletMovementRest extends AbstractWalletMovementRest { + + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/endpoint/rest/WalletRest.java b/src/main/java/io/kumare/iqr/mod/pocket/endpoint/rest/WalletRest.java new file mode 100644 index 0000000..2a6f4bc --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/endpoint/rest/WalletRest.java @@ -0,0 +1,24 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.endpoint.rest; + +// java +import io.swagger.v3.oas.annotations.tags.*; +// spring +import org.springframework.web.bind.annotation.*; + +/** +* +* @author afatecha +*/ + +// openapi +//@Tag(name = "wallet rest endpoint") +// +//@RestController +//@RequestMapping("/pocket/wallets") +public class WalletRest extends AbstractWalletRest { + + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/endpoint/rest/WalletSlotRest.java b/src/main/java/io/kumare/iqr/mod/pocket/endpoint/rest/WalletSlotRest.java new file mode 100644 index 0000000..8e36510 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/endpoint/rest/WalletSlotRest.java @@ -0,0 +1,24 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.endpoint.rest; + +// java +import io.swagger.v3.oas.annotations.tags.*; +// spring +import org.springframework.web.bind.annotation.*; + +/** +* +* @author afatecha +*/ + +// openapi +//@Tag(name = "wallet slot rest endpoint") +// +//@RestController +//@RequestMapping("/pocket/wallet-slots") +public class WalletSlotRest extends AbstractWalletSlotRest { + + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/store/PocketEntities.java b/src/main/java/io/kumare/iqr/mod/pocket/store/PocketEntities.java new file mode 100644 index 0000000..4ccfd1a --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/store/PocketEntities.java @@ -0,0 +1,105 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.store; + +// base +// base +import io.kumare.lib.app.api.module.ServiceModule; +import io.kumare.lib.app.api.store.EntityStore; +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app +import io.kumare.iqr.app.AppEngine; +import io.kumare.iqr.app.module.AppModules; +import io.kumare.iqr.mod.pocket.store.wallet.WalletEntity; +import io.kumare.iqr.mod.pocket.store.wallet.WalletStore; +import io.kumare.iqr.mod.pocket.store.walletslot.WalletSlotEntity; +import io.kumare.iqr.mod.pocket.store.walletslot.WalletSlotStore; +import io.kumare.iqr.mod.pocket.store.walletmovement.WalletMovementEntity; +import io.kumare.iqr.mod.pocket.store.walletmovement.WalletMovementStore; + + +/** + * + * @author afatecha + */ +public enum PocketEntities implements EntityDescriptor { + + wallet(WalletEntity.class, WalletStore.class), + walletSlot(WalletSlotEntity.class, WalletSlotStore.class), + walletMovement(WalletMovementEntity.class, WalletMovementStore.class); + + // ::: vars + // + private final Class entityClass; + private final Class storeClass; + + // ::: constructor + // + PocketEntities(Class entityClass, Class storeClass) { + this.entityClass = entityClass; + this.storeClass = storeClass; + } + + // ::: entity descriptor api + // + @Override + public String getName() { + return name(); + } + + @Override + public ServiceModule getModule() { + return AppModules.pocket; + } + + @Override + public Class getEntityClass() { + return entityClass; + } + + @Override + public Class getStoreClass() { + return storeClass; + } + + @Override + public EntityStore getStore() { + return (EntityStore) AppEngine.getEngine().getInnerContext().getBean(storeClass); + } + + // ::: statics + // + public static boolean hasDescriptor(String name) { + try { + var value = valueOf(name); + return value != null; + + } catch (Throwable t) { + return false; + } + } + + public static EntityDescriptor descriptorOf(String name) { + try { + return valueOf(name); + + } catch (Throwable t) { + return null; + } + } + + public static EntityDescriptor descriptorOf(Class entityClass) { + try { + for (var i : values()) { + if (i.entityClass == entityClass) { + return i; + } + } + + } catch (Throwable t) { + } + + return null; + } +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/store/PocketTaxonomies.java b/src/main/java/io/kumare/iqr/mod/pocket/store/PocketTaxonomies.java new file mode 100644 index 0000000..394c195 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/store/PocketTaxonomies.java @@ -0,0 +1,115 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.store; + +// base +import io.kumare.lib.app.api.Context; +import io.kumare.lib.v.ExceptionPrototype; +// app +import io.kumare.iqr.app.module.AppModules; +import io.kumare.iqr.mod.pocket.PocketErrors; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; +import java.util.List; + +/** + * + * @author administrador + */ +public enum PocketTaxonomies { + + walletMovementType("wallet-movement-type", PocketErrors.walletmovement_type_notfound), + walletMovementState("wallet-movement-state", PocketErrors.walletmovement_state_notfound); + + // ::: + // + private final String taxaKey; + private final ExceptionPrototype proto; + + // ::: constructor + // + PocketTaxonomies(String taxaKey, ExceptionPrototype proto) { + this.taxaKey = taxaKey; + this.proto = proto; + } + + public String getKey() { + return taxaKey; + } + + // ::: ensure + // + public TaxonEntity ensure(Context context, TaxonEntity taxon) { + return AppModules.taxonomy.getController().getTaxonStore() + .ensure(context, taxaKey, taxon, proto); + } + + public TaxonEntity ensureById(Context context, String taxonId) { + return AppModules.taxonomy.getController().getTaxonStore() + .ensureById(context, taxaKey, taxonId, proto); + } + + public TaxonEntity ensureByKey(Context context, String key) { + return AppModules.taxonomy.getController().getTaxonStore() + .ensureByKey(context, taxaKey, key, proto); + } + + public TaxonEntity ensureByValue(Context context, String value) { + return AppModules.taxonomy.getController().getTaxonStore() + .ensureByValue(context, taxaKey, value, proto); + } + + // ::: find + // + public TaxonEntity findById(Context context, String taxonId) { + return AppModules.taxonomy.getController() + .getTaxonStore() + .findById(context, taxaKey, taxonId); + } + + public TaxonEntity findByKey(Context context, String key) { + return AppModules.taxonomy.getController() + .getTaxonStore() + .findByKey(context, taxaKey, key); + } + + public TaxonEntity findByValue(Context context, String value) { + return AppModules.taxonomy.getController() + .getTaxonStore() + .findByValue(context, taxaKey, value); + } + + // ::: list + // + public List list(Context context) { + return AppModules.taxonomy.getController() + .getTaxonStore() + .listByTaxaKey(context, taxaKey); + } + + // ::: default + // + public TaxonEntity ensureDefault(Context context) { + return AppModules.taxonomy.getController() + .getTaxonStore() + .ensureDefault(context, taxaKey, proto); + } + + public TaxonEntity findDefault(Context context) { + return AppModules.taxonomy.getController() + .getTaxonStore() + .findDefault(context, taxaKey); + } + + // ::: statics + // + public static boolean hasTaxaKey(String taxaKey) { + for (var i : values()) { + if (i.getKey().equals(taxaKey)) { + return true; + } + } + + return false; + } +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/store/wallet/WalletData.java b/src/main/java/io/kumare/iqr/mod/pocket/store/wallet/WalletData.java new file mode 100644 index 0000000..63f76e6 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/store/wallet/WalletData.java @@ -0,0 +1,25 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.store.wallet; + +// base +import io.kumare.iqr.app.store.AppExtendedEntityData; +// imports + + +public class WalletData extends AppExtendedEntityData { + + // ::: vars + // + + + // ::: fields + // + + + // ::: fluent + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/store/wallet/WalletEntity.java b/src/main/java/io/kumare/iqr/mod/pocket/store/wallet/WalletEntity.java new file mode 100644 index 0000000..1fa35c7 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/store/wallet/WalletEntity.java @@ -0,0 +1,83 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.store.wallet; + +// jakarta +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.Index; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +// base +import io.kumare.lib.app.api.store.*; +import io.kumare.iqr.app.store.*; +// imports + +// relations + + +// annotations +@Entity +@Table( + name = "wallet", + indexes = { + @Index(name = "idx_wallet_external_id", columnList = "externalId"), + @Index(name = "idx_wallet_entity_key", columnList = "entityKey") + } +) +public class WalletEntity extends AppEntity implements SupportedEntityKey { + + // ::: vars + // + private String externalId; + private String entityKey; + // relations + + + // ::: constructors + // + public WalletEntity() { + } + + public WalletEntity(String id) { + super(id); + } + + // ::: fields + // + public String getExternalId() { + return externalId; + } + + public void setExternalId(String externalId) { + this.externalId = externalId; + } + + public String getEntityKey() { + return entityKey; + } + + public void setEntityKey(String entityKey) { + this.entityKey = entityKey; + } + + // relations + + + // ::: fluent + // + public WalletEntity externalId(String externalId) { + setExternalId(externalId); + return this; + } + + public WalletEntity entityKey(String entityKey) { + setEntityKey(entityKey); + return this; + } + + // relations + + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/store/wallet/WalletFields.java b/src/main/java/io/kumare/iqr/mod/pocket/store/wallet/WalletFields.java new file mode 100644 index 0000000..f26b999 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/store/wallet/WalletFields.java @@ -0,0 +1,135 @@ +/* + */ +package io.kumare.iqr.mod.pocket.store.wallet; + +// java +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +// base +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app + + +/** + * + * @author afatecha + */ +public enum WalletFields implements EntityFieldDescriptor { + + id(MAIN, FIND, LIST), + externalId(MAIN, FIND, LIST), + entityKey(MAIN, FIND, LIST), + active(MAIN, FIND, LIST), + inserted(AUDIT, FIND, LIST), + inserter(AUDIT, FIND, LIST), + modified(AUDIT, FIND), + modifier(AUDIT, FIND), + deleted(AUDIT), + removed(AUDIT), + remover(AUDIT); + + // ::: vars + // + private final boolean relation; + private final EntityDescriptor entityDescriptor; + private final Class enumClass; + private final List groups; + + // ::: constructors + // + WalletFields(String... groups) { + this(false, null, null, groups); + } + + WalletFields(EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this(true, entityDescriptor, enumClass, groups); + } + + WalletFields(boolean relation, EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this.relation = relation; + this.entityDescriptor = entityDescriptor; + this.enumClass = enumClass; + this.groups = groups == null ? Collections.EMPTY_LIST : Arrays.asList(groups); + } + + // ::: api + // + @Override + public String getName() { + return name(); + } + + @Override + public boolean isRelation() { + return relation; + } + + @Override + public Class getRelationEnumClass() { + return enumClass; + } + + @Override + public List getGroups() { + return groups; + } + + @Override + public EntityDescriptor getEntityDescriptor() { + return entityDescriptor; + } + + @Override + public Object fetchValue(WalletEntity entity) { + if (entity == null) { + return null; + } + + switch (this) { + case null -> { + return null; + } + case id -> { + return entity.getId(); + } + case externalId ->{ + return entity.getExternalId(); + } + case entityKey ->{ + return entity.getEntityKey(); + } + case active -> { + return entity.isActive(); + } + case inserted -> { + return entity.getInserted(); + } + case inserter -> { + return entity.getInserter(); + } + case modified -> { + return entity.getModified(); + } + case modifier -> { + return entity.getModifier(); + } + case deleted -> { + return entity.isDeleted(); + } + case removed -> { + return entity.getRemoved(); + } + case remover -> { + return entity.getRemover(); + } + + default -> { + return null; + } + } + + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/store/wallet/WalletMapBuilder.java b/src/main/java/io/kumare/iqr/mod/pocket/store/wallet/WalletMapBuilder.java new file mode 100644 index 0000000..6651056 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/store/wallet/WalletMapBuilder.java @@ -0,0 +1,93 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.store.wallet; + +// java +import java.util.List; +import java.util.Map; +// base +import io.kumare.lib.app.api.Context; +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.BaseEntityMapBuilder; +// app + + +/** + * + * @author afatecha + */ +public class WalletMapBuilder extends BaseEntityMapBuilder { + + // ::: vars + // + + + + // ::: fields + // + @Override + public WalletMapBuilder addGroup(String name, boolean cascade) { + includes.addAll(EntityFieldDescriptor.group(WalletFields.values(), name)); + + return this; + } + + @Override + public WalletMapBuilder add(String fieldName) { + includes.add(WalletFields.valueOf(fieldName)); + return this; + } + + @Override + public WalletMapBuilder addAll(String... names) { + for (var i : names) { + includes.add(WalletFields.valueOf(i)); + } + return this; + } + + @Override + public WalletMapBuilder remove(String fieldName) { + excludes.add(WalletFields.valueOf(fieldName)); + return this; + } + + @Override + public WalletMapBuilder removeAll(String... names) { + for (var i : names) { + excludes.add(WalletFields.valueOf(i)); + } + return this; + } + + // ::: relations + // + @Override + public WalletMapBuilder addPlains(boolean cascade) { + includes.addAll(EntityFieldDescriptor.plains(WalletFields.values())); + + return this; + } + + @Override + public WalletMapBuilder addRelations(boolean cascade) { + includes.addAll(EntityFieldDescriptor.relations(WalletFields.values())); + + return this; + } + + + + // ::: internals + // + @Override + protected void internalAttachRelations(Context context, + WalletEntity entity, + List fields, + Map resultMap) { + + + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/store/wallet/WalletRepository.java b/src/main/java/io/kumare/iqr/mod/pocket/store/wallet/WalletRepository.java new file mode 100644 index 0000000..410b791 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/store/wallet/WalletRepository.java @@ -0,0 +1,18 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.store.wallet; + +// spring +import org.springframework.stereotype.Repository; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Repository +public interface WalletRepository extends AppKeyEntityRepository{ + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/store/wallet/WalletStore.java b/src/main/java/io/kumare/iqr/mod/pocket/store/wallet/WalletStore.java new file mode 100644 index 0000000..cbd7e76 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/store/wallet/WalletStore.java @@ -0,0 +1,35 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.store.wallet; + +// spring +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Service +public class WalletStore extends AppKeyEntityStore { + + // ::: vars + // + @Autowired + private WalletRepository repository; + + // ::: override + // + @Override + public WalletRepository getRepository() { + return repository; + } + + // ::: api + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/store/walletmovement/WalletMovementData.java b/src/main/java/io/kumare/iqr/mod/pocket/store/walletmovement/WalletMovementData.java new file mode 100644 index 0000000..2c24509 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/store/walletmovement/WalletMovementData.java @@ -0,0 +1,25 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.store.walletmovement; + +// base +import io.kumare.iqr.app.store.AppExtendedEntityData; +// imports + + +public class WalletMovementData extends AppExtendedEntityData { + + // ::: vars + // + + + // ::: fields + // + + + // ::: fluent + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/store/walletmovement/WalletMovementEntity.java b/src/main/java/io/kumare/iqr/mod/pocket/store/walletmovement/WalletMovementEntity.java new file mode 100644 index 0000000..72a9a9d --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/store/walletmovement/WalletMovementEntity.java @@ -0,0 +1,200 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.store.walletmovement; + +// jakarta +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.Index; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +// base +import io.kumare.lib.app.api.store.*; +import io.kumare.iqr.app.store.*; +// imports +import java.util.Date; +// relations +import io.kumare.iqr.mod.pocket.store.wallet.WalletEntity; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; +import io.kumare.iqr.mod.pocket.store.walletslot.WalletSlotEntity; + +// annotations +@Entity +@Table( + name = "wallet_movement", + indexes = { + @Index(name = "idx_wallet_movement_external_id", columnList = "externalId"), + @Index(name = "idx_wallet_movement_type_value", columnList = "typeValue"), + @Index(name = "idx_wallet_movement_state_value", columnList = "stateValue"), + @Index(name = "idx_wallet_movement_done_date", columnList = "doneDate"), + @Index(name = "idx_wallet_movement_value", columnList = "value"), + @Index(name = "idx_wallet_movement_unsigned_value", columnList = "unsignedValue") + } +) +public class WalletMovementEntity extends AppEntity { + + // ::: vars + // + private String externalId; + private String typeValue; + private String stateValue; + private Date doneDate; + private int value; + private int unsignedValue; + // relations + @ManyToOne(fetch = FetchType.LAZY) + private WalletEntity wallet; + @ManyToOne(fetch = FetchType.LAZY) + private WalletSlotEntity walletSlot; + @ManyToOne(fetch = FetchType.LAZY) + private TaxonEntity type; + @ManyToOne(fetch = FetchType.LAZY) + private TaxonEntity state; + + // ::: constructors + // + public WalletMovementEntity() { + } + + public WalletMovementEntity(String id) { + super(id); + } + + // ::: fields + // + public String getExternalId() { + return externalId; + } + + public void setExternalId(String externalId) { + this.externalId = externalId; + } + + public String getTypeValue() { + return typeValue; + } + + public void setTypeValue(String typeValue) { + this.typeValue = typeValue; + } + + public String getStateValue() { + return stateValue; + } + + public void setStateValue(String stateValue) { + this.stateValue = stateValue; + } + + public Date getDoneDate() { + return doneDate; + } + + public void setDoneDate(Date doneDate) { + this.doneDate = doneDate; + } + + public int getValue() { + return value; + } + + public void setValue(int value) { + this.value = value; + } + + public int getUnsignedValue() { + return unsignedValue; + } + + public void setUnsignedValue(int unsignedValue) { + this.unsignedValue = unsignedValue; + } + + // relations + public WalletEntity getWallet() { + return wallet; + } + + public void setWallet(WalletEntity wallet) { + this.wallet = wallet; + } + + public WalletSlotEntity getWalletSlot() { + return walletSlot; + } + + public void setWalletSlot(WalletSlotEntity walletSlot) { + this.walletSlot = walletSlot; + } + + public TaxonEntity getType() { + return type; + } + + public void setType(TaxonEntity type) { + this.type = type; + } + + public TaxonEntity getState() { + return state; + } + + public void setState(TaxonEntity state) { + this.state = state; + } + + // ::: fluent + // + public WalletMovementEntity externalId(String externalId) { + setExternalId(externalId); + return this; + } + + public WalletMovementEntity typeValue(String typeValue) { + setTypeValue(typeValue); + return this; + } + + public WalletMovementEntity stateValue(String stateValue) { + setStateValue(stateValue); + return this; + } + + public WalletMovementEntity doneDate(Date doneDate) { + setDoneDate(doneDate); + return this; + } + + public WalletMovementEntity value(int value) { + setValue(value); + return this; + } + + public WalletMovementEntity unsignedValue(int unsignedValue) { + setUnsignedValue(unsignedValue); + return this; + } + + // relations + public WalletMovementEntity wallet(WalletEntity wallet) { + setWallet(wallet); + return this; + } + + public WalletMovementEntity walletSlot(WalletSlotEntity walletSlot) { + setWalletSlot(walletSlot); + return this; + } + + public WalletMovementEntity type(TaxonEntity type) { + setType(type); + return this; + } + + public WalletMovementEntity state(TaxonEntity state) { + setState(state); + return this; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/store/walletmovement/WalletMovementFields.java b/src/main/java/io/kumare/iqr/mod/pocket/store/walletmovement/WalletMovementFields.java new file mode 100644 index 0000000..e096eca --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/store/walletmovement/WalletMovementFields.java @@ -0,0 +1,173 @@ +/* + */ +package io.kumare.iqr.mod.pocket.store.walletmovement; + +// java +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +// base +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app +import io.kumare.iqr.mod.pocket.store.PocketEntities; +import io.kumare.iqr.mod.pocket.store.wallet.WalletFields; +import io.kumare.iqr.mod.pocket.store.PocketEntities; +import io.kumare.iqr.mod.pocket.store.walletslot.WalletSlotFields; +import io.kumare.iqr.mod.taxonomy.store.TaxonomyEntities; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonFields; +import io.kumare.iqr.mod.taxonomy.store.TaxonomyEntities; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonFields; + +/** + * + * @author afatecha + */ +public enum WalletMovementFields implements EntityFieldDescriptor { + + id(MAIN, FIND, LIST), + externalId(MAIN, FIND, LIST), + typeValue(MAIN, FIND, LIST), + stateValue(MAIN, FIND, LIST), + doneDate(MAIN, FIND, LIST), + value(MAIN, FIND, LIST), + unsignedValue(MAIN, FIND, LIST), + active(MAIN, FIND, LIST), + inserted(AUDIT, FIND, LIST), + inserter(AUDIT, FIND, LIST), + modified(AUDIT, FIND), + modifier(AUDIT, FIND), + deleted(AUDIT), + removed(AUDIT), + remover(AUDIT), + wallet(PocketEntities.wallet, WalletFields.class, FIND, LIST), + walletSlot(PocketEntities.walletSlot, WalletSlotFields.class, FIND, LIST), + type(TaxonomyEntities.taxon, TaxonFields.class, FIND, LIST), + state(TaxonomyEntities.taxon, TaxonFields.class, FIND, LIST); + + // ::: vars + // + private final boolean relation; + private final EntityDescriptor entityDescriptor; + private final Class enumClass; + private final List groups; + + // ::: constructors + // + WalletMovementFields(String... groups) { + this(false, null, null, groups); + } + + WalletMovementFields(EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this(true, entityDescriptor, enumClass, groups); + } + + WalletMovementFields(boolean relation, EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this.relation = relation; + this.entityDescriptor = entityDescriptor; + this.enumClass = enumClass; + this.groups = groups == null ? Collections.EMPTY_LIST : Arrays.asList(groups); + } + + // ::: api + // + @Override + public String getName() { + return name(); + } + + @Override + public boolean isRelation() { + return relation; + } + + @Override + public Class getRelationEnumClass() { + return enumClass; + } + + @Override + public List getGroups() { + return groups; + } + + @Override + public EntityDescriptor getEntityDescriptor() { + return entityDescriptor; + } + + @Override + public Object fetchValue(WalletMovementEntity entity) { + if (entity == null) { + return null; + } + + switch (this) { + case null -> { + return null; + } + case id -> { + return entity.getId(); + } + case externalId ->{ + return entity.getExternalId(); + } + case typeValue ->{ + return entity.getTypeValue(); + } + case stateValue ->{ + return entity.getStateValue(); + } + case doneDate ->{ + return entity.getDoneDate(); + } + case value ->{ + return entity.getValue(); + } + case unsignedValue ->{ + return entity.getUnsignedValue(); + } + case active -> { + return entity.isActive(); + } + case inserted -> { + return entity.getInserted(); + } + case inserter -> { + return entity.getInserter(); + } + case modified -> { + return entity.getModified(); + } + case modifier -> { + return entity.getModifier(); + } + case deleted -> { + return entity.isDeleted(); + } + case removed -> { + return entity.getRemoved(); + } + case remover -> { + return entity.getRemover(); + } + case wallet ->{ + return entity.getWallet(); + } + case walletSlot ->{ + return entity.getWalletSlot(); + } + case type ->{ + return entity.getType(); + } + case state ->{ + return entity.getState(); + } + default -> { + return null; + } + } + + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/store/walletmovement/WalletMovementMapBuilder.java b/src/main/java/io/kumare/iqr/mod/pocket/store/walletmovement/WalletMovementMapBuilder.java new file mode 100644 index 0000000..1f09eb5 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/store/walletmovement/WalletMovementMapBuilder.java @@ -0,0 +1,276 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.store.walletmovement; + +// java +import java.util.List; +import java.util.Map; +// base +import io.kumare.lib.app.api.Context; +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.BaseEntityMapBuilder; +// app +import io.kumare.iqr.mod.pocket.store.wallet.WalletMapBuilder; +import io.kumare.iqr.mod.pocket.store.walletslot.WalletSlotMapBuilder; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonMapBuilder; + +/** + * + * @author afatecha + */ +public class WalletMovementMapBuilder extends BaseEntityMapBuilder { + + // ::: vars + // + private WalletMapBuilder walletBuilder; + private WalletSlotMapBuilder walletSlotBuilder; + private TaxonMapBuilder typeBuilder; + private TaxonMapBuilder stateBuilder; + + + // ::: fields + // + @Override + public WalletMovementMapBuilder addGroup(String name, boolean cascade) { + includes.addAll(EntityFieldDescriptor.group(WalletMovementFields.values(), name)); + + if(cascade) { + if (includes.contains(WalletMovementFields.wallet)) { + getWalletBuilder().addGroup(name); + } + if (includes.contains(WalletMovementFields.walletSlot)) { + getWalletSlotBuilder().addGroup(name); + } + if (includes.contains(WalletMovementFields.type)) { + getTypeBuilder().addGroup(name); + } + if (includes.contains(WalletMovementFields.state)) { + getStateBuilder().addGroup(name); + } + } + return this; + } + + @Override + public WalletMovementMapBuilder add(String fieldName) { + includes.add(WalletMovementFields.valueOf(fieldName)); + return this; + } + + @Override + public WalletMovementMapBuilder addAll(String... names) { + for (var i : names) { + includes.add(WalletMovementFields.valueOf(i)); + } + return this; + } + + @Override + public WalletMovementMapBuilder remove(String fieldName) { + excludes.add(WalletMovementFields.valueOf(fieldName)); + return this; + } + + @Override + public WalletMovementMapBuilder removeAll(String... names) { + for (var i : names) { + excludes.add(WalletMovementFields.valueOf(i)); + } + return this; + } + + // ::: relations + // + @Override + public WalletMovementMapBuilder addPlains(boolean cascade) { + includes.addAll(EntityFieldDescriptor.plains(WalletMovementFields.values())); + + if(cascade) { + if (includes.contains(WalletMovementFields.wallet)) { + getWalletBuilder().addPlains(); + } + if (includes.contains(WalletMovementFields.walletSlot)) { + getWalletSlotBuilder().addPlains(); + } + if (includes.contains(WalletMovementFields.type)) { + getTypeBuilder().addPlains(); + } + if (includes.contains(WalletMovementFields.state)) { + getStateBuilder().addPlains(); + } + } + return this; + } + + @Override + public WalletMovementMapBuilder addRelations(boolean cascade) { + includes.addAll(EntityFieldDescriptor.relations(WalletMovementFields.values())); + + if(cascade) { + if (includes.contains(WalletMovementFields.wallet)) { + getWalletBuilder().addRelations(); + } + if (includes.contains(WalletMovementFields.walletSlot)) { + getWalletSlotBuilder().addRelations(); + } + if (includes.contains(WalletMovementFields.type)) { + getTypeBuilder().addRelations(); + } + if (includes.contains(WalletMovementFields.state)) { + getStateBuilder().addRelations(); + } + } + return this; + } + + // ::: wallet + // + public WalletMovementMapBuilder addWallet() { + return addWallet(null); + } + + public WalletMovementMapBuilder addWallet(String group) { + return addWallet(group, false); + } + + public WalletMovementMapBuilder addWallet(String group, boolean cascade) { + includes.add(WalletMovementFields.wallet); + + if (group != null) { + getWalletBuilder().addGroup(group); + } + + return this; + } + + public WalletMapBuilder getWalletBuilder() { + if(walletBuilder == null) { + walletBuilder = new WalletMapBuilder(); + } + return walletBuilder; + } + + + // ::: wallet slot + // + public WalletMovementMapBuilder addWalletSlot() { + return addWalletSlot(null); + } + + public WalletMovementMapBuilder addWalletSlot(String group) { + return addWalletSlot(group, false); + } + + public WalletMovementMapBuilder addWalletSlot(String group, boolean cascade) { + includes.add(WalletMovementFields.walletSlot); + + if (group != null) { + getWalletSlotBuilder().addGroup(group); + } + + return this; + } + + public WalletSlotMapBuilder getWalletSlotBuilder() { + if(walletSlotBuilder == null) { + walletSlotBuilder = new WalletSlotMapBuilder(); + } + return walletSlotBuilder; + } + + + // ::: type + // + public WalletMovementMapBuilder addType() { + return addType(null); + } + + public WalletMovementMapBuilder addType(String group) { + return addType(group, false); + } + + public WalletMovementMapBuilder addType(String group, boolean cascade) { + includes.add(WalletMovementFields.type); + + if (group != null) { + getTypeBuilder().addGroup(group); + } + + return this; + } + + public TaxonMapBuilder getTypeBuilder() { + if(typeBuilder == null) { + typeBuilder = new TaxonMapBuilder(); + } + return typeBuilder; + } + + + // ::: state + // + public WalletMovementMapBuilder addState() { + return addState(null); + } + + public WalletMovementMapBuilder addState(String group) { + return addState(group, false); + } + + public WalletMovementMapBuilder addState(String group, boolean cascade) { + includes.add(WalletMovementFields.state); + + if (group != null) { + getStateBuilder().addGroup(group); + } + + return this; + } + + public TaxonMapBuilder getStateBuilder() { + if(stateBuilder == null) { + stateBuilder = new TaxonMapBuilder(); + } + return stateBuilder; + } + + // ::: internals + // + @Override + protected void internalAttachRelations(Context context, + WalletMovementEntity entity, + List fields, + Map resultMap) { + + if (fields.contains(WalletMovementFields.wallet)) { + attachRelation(context, + entity, + WalletMovementFields.wallet, + getWalletBuilder(), + resultMap); + } + if (fields.contains(WalletMovementFields.walletSlot)) { + attachRelation(context, + entity, + WalletMovementFields.walletSlot, + getWalletSlotBuilder(), + resultMap); + } + if (fields.contains(WalletMovementFields.type)) { + attachRelation(context, + entity, + WalletMovementFields.type, + getTypeBuilder(), + resultMap); + } + if (fields.contains(WalletMovementFields.state)) { + attachRelation(context, + entity, + WalletMovementFields.state, + getStateBuilder(), + resultMap); + } + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/store/walletmovement/WalletMovementRepository.java b/src/main/java/io/kumare/iqr/mod/pocket/store/walletmovement/WalletMovementRepository.java new file mode 100644 index 0000000..1d5b4ac --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/store/walletmovement/WalletMovementRepository.java @@ -0,0 +1,18 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.store.walletmovement; + +// spring +import org.springframework.stereotype.Repository; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Repository +public interface WalletMovementRepository extends AppEntityRepository{ + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/store/walletmovement/WalletMovementStore.java b/src/main/java/io/kumare/iqr/mod/pocket/store/walletmovement/WalletMovementStore.java new file mode 100644 index 0000000..c2c4fb2 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/store/walletmovement/WalletMovementStore.java @@ -0,0 +1,35 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.store.walletmovement; + +// spring +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Service +public class WalletMovementStore extends AppEntityStore { + + // ::: vars + // + @Autowired + private WalletMovementRepository repository; + + // ::: override + // + @Override + public WalletMovementRepository getRepository() { + return repository; + } + + // ::: api + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/store/walletslot/WalletSlotData.java b/src/main/java/io/kumare/iqr/mod/pocket/store/walletslot/WalletSlotData.java new file mode 100644 index 0000000..768045b --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/store/walletslot/WalletSlotData.java @@ -0,0 +1,25 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.store.walletslot; + +// base +import io.kumare.iqr.app.store.AppExtendedEntityData; +// imports + + +public class WalletSlotData extends AppExtendedEntityData { + + // ::: vars + // + + + // ::: fields + // + + + // ::: fluent + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/store/walletslot/WalletSlotEntity.java b/src/main/java/io/kumare/iqr/mod/pocket/store/walletslot/WalletSlotEntity.java new file mode 100644 index 0000000..0980a73 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/store/walletslot/WalletSlotEntity.java @@ -0,0 +1,108 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.store.walletslot; + +// jakarta +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.Index; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +// base +import io.kumare.lib.app.api.store.*; +import io.kumare.iqr.app.store.*; +// imports + +// relations +import io.kumare.iqr.mod.pocket.store.wallet.WalletEntity; + +// annotations +@Entity +@Table( + name = "wallet_slot", + indexes = { + @Index(name = "idx_wallet_slot_entity_key", columnList = "entityKey"), + @Index(name = "idx_wallet_slot_concept_key", columnList = "conceptKey"), + @Index(name = "idx_wallet_slot_points", columnList = "points") + } +) +public class WalletSlotEntity extends AppEntity implements SupportedEntityKey { + + // ::: vars + // + private String entityKey; + private String conceptKey; + private int points; + // relations + @ManyToOne(fetch = FetchType.LAZY) + private WalletEntity wallet; + + // ::: constructors + // + public WalletSlotEntity() { + } + + public WalletSlotEntity(String id) { + super(id); + } + + // ::: fields + // + public String getEntityKey() { + return entityKey; + } + + public void setEntityKey(String entityKey) { + this.entityKey = entityKey; + } + + public String getConceptKey() { + return conceptKey; + } + + public void setConceptKey(String conceptKey) { + this.conceptKey = conceptKey; + } + + public int getPoints() { + return points; + } + + public void setPoints(int points) { + this.points = points; + } + + // relations + public WalletEntity getWallet() { + return wallet; + } + + public void setWallet(WalletEntity wallet) { + this.wallet = wallet; + } + + // ::: fluent + // + public WalletSlotEntity entityKey(String entityKey) { + setEntityKey(entityKey); + return this; + } + + public WalletSlotEntity conceptKey(String conceptKey) { + setConceptKey(conceptKey); + return this; + } + + public WalletSlotEntity points(int points) { + setPoints(points); + return this; + } + + // relations + public WalletSlotEntity wallet(WalletEntity wallet) { + setWallet(wallet); + return this; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/store/walletslot/WalletSlotFields.java b/src/main/java/io/kumare/iqr/mod/pocket/store/walletslot/WalletSlotFields.java new file mode 100644 index 0000000..ac3ecc8 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/store/walletslot/WalletSlotFields.java @@ -0,0 +1,143 @@ +/* + */ +package io.kumare.iqr.mod.pocket.store.walletslot; + +// java +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +// base +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app +import io.kumare.iqr.mod.pocket.store.PocketEntities; +import io.kumare.iqr.mod.pocket.store.wallet.WalletFields; + +/** + * + * @author afatecha + */ +public enum WalletSlotFields implements EntityFieldDescriptor { + + id(MAIN, FIND, LIST), + entityKey(MAIN, FIND, LIST), + conceptKey(MAIN, FIND, LIST), + points(MAIN, FIND, LIST), + active(MAIN, FIND, LIST), + inserted(AUDIT, FIND, LIST), + inserter(AUDIT, FIND, LIST), + modified(AUDIT, FIND), + modifier(AUDIT, FIND), + deleted(AUDIT), + removed(AUDIT), + remover(AUDIT), + wallet(PocketEntities.wallet, WalletFields.class, FIND, LIST); + + // ::: vars + // + private final boolean relation; + private final EntityDescriptor entityDescriptor; + private final Class enumClass; + private final List groups; + + // ::: constructors + // + WalletSlotFields(String... groups) { + this(false, null, null, groups); + } + + WalletSlotFields(EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this(true, entityDescriptor, enumClass, groups); + } + + WalletSlotFields(boolean relation, EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this.relation = relation; + this.entityDescriptor = entityDescriptor; + this.enumClass = enumClass; + this.groups = groups == null ? Collections.EMPTY_LIST : Arrays.asList(groups); + } + + // ::: api + // + @Override + public String getName() { + return name(); + } + + @Override + public boolean isRelation() { + return relation; + } + + @Override + public Class getRelationEnumClass() { + return enumClass; + } + + @Override + public List getGroups() { + return groups; + } + + @Override + public EntityDescriptor getEntityDescriptor() { + return entityDescriptor; + } + + @Override + public Object fetchValue(WalletSlotEntity entity) { + if (entity == null) { + return null; + } + + switch (this) { + case null -> { + return null; + } + case id -> { + return entity.getId(); + } + case entityKey ->{ + return entity.getEntityKey(); + } + case conceptKey ->{ + return entity.getConceptKey(); + } + case points ->{ + return entity.getPoints(); + } + case active -> { + return entity.isActive(); + } + case inserted -> { + return entity.getInserted(); + } + case inserter -> { + return entity.getInserter(); + } + case modified -> { + return entity.getModified(); + } + case modifier -> { + return entity.getModifier(); + } + case deleted -> { + return entity.isDeleted(); + } + case removed -> { + return entity.getRemoved(); + } + case remover -> { + return entity.getRemover(); + } + case wallet ->{ + return entity.getWallet(); + } + default -> { + return null; + } + } + + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/store/walletslot/WalletSlotMapBuilder.java b/src/main/java/io/kumare/iqr/mod/pocket/store/walletslot/WalletSlotMapBuilder.java new file mode 100644 index 0000000..076c97a --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/store/walletslot/WalletSlotMapBuilder.java @@ -0,0 +1,139 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.store.walletslot; + +// java +import java.util.List; +import java.util.Map; +// base +import io.kumare.lib.app.api.Context; +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.BaseEntityMapBuilder; +// app +import io.kumare.iqr.mod.pocket.store.wallet.WalletMapBuilder; + +/** + * + * @author afatecha + */ +public class WalletSlotMapBuilder extends BaseEntityMapBuilder { + + // ::: vars + // + private WalletMapBuilder walletBuilder; + + + // ::: fields + // + @Override + public WalletSlotMapBuilder addGroup(String name, boolean cascade) { + includes.addAll(EntityFieldDescriptor.group(WalletSlotFields.values(), name)); + + if(cascade) { + if (includes.contains(WalletSlotFields.wallet)) { + getWalletBuilder().addGroup(name); + } + } + return this; + } + + @Override + public WalletSlotMapBuilder add(String fieldName) { + includes.add(WalletSlotFields.valueOf(fieldName)); + return this; + } + + @Override + public WalletSlotMapBuilder addAll(String... names) { + for (var i : names) { + includes.add(WalletSlotFields.valueOf(i)); + } + return this; + } + + @Override + public WalletSlotMapBuilder remove(String fieldName) { + excludes.add(WalletSlotFields.valueOf(fieldName)); + return this; + } + + @Override + public WalletSlotMapBuilder removeAll(String... names) { + for (var i : names) { + excludes.add(WalletSlotFields.valueOf(i)); + } + return this; + } + + // ::: relations + // + @Override + public WalletSlotMapBuilder addPlains(boolean cascade) { + includes.addAll(EntityFieldDescriptor.plains(WalletSlotFields.values())); + + if(cascade) { + if (includes.contains(WalletSlotFields.wallet)) { + getWalletBuilder().addPlains(); + } + } + return this; + } + + @Override + public WalletSlotMapBuilder addRelations(boolean cascade) { + includes.addAll(EntityFieldDescriptor.relations(WalletSlotFields.values())); + + if(cascade) { + if (includes.contains(WalletSlotFields.wallet)) { + getWalletBuilder().addRelations(); + } + } + return this; + } + + // ::: wallet + // + public WalletSlotMapBuilder addWallet() { + return addWallet(null); + } + + public WalletSlotMapBuilder addWallet(String group) { + return addWallet(group, false); + } + + public WalletSlotMapBuilder addWallet(String group, boolean cascade) { + includes.add(WalletSlotFields.wallet); + + if (group != null) { + getWalletBuilder().addGroup(group); + } + + return this; + } + + public WalletMapBuilder getWalletBuilder() { + if(walletBuilder == null) { + walletBuilder = new WalletMapBuilder(); + } + return walletBuilder; + } + + // ::: internals + // + @Override + protected void internalAttachRelations(Context context, + WalletSlotEntity entity, + List fields, + Map resultMap) { + + if (fields.contains(WalletSlotFields.wallet)) { + attachRelation(context, + entity, + WalletSlotFields.wallet, + getWalletBuilder(), + resultMap); + } + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/store/walletslot/WalletSlotRepository.java b/src/main/java/io/kumare/iqr/mod/pocket/store/walletslot/WalletSlotRepository.java new file mode 100644 index 0000000..58f5331 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/store/walletslot/WalletSlotRepository.java @@ -0,0 +1,18 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.store.walletslot; + +// spring +import org.springframework.stereotype.Repository; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Repository +public interface WalletSlotRepository extends AppKeyEntityRepository{ + +} diff --git a/src/main/java/io/kumare/iqr/mod/pocket/store/walletslot/WalletSlotStore.java b/src/main/java/io/kumare/iqr/mod/pocket/store/walletslot/WalletSlotStore.java new file mode 100644 index 0000000..6cd20a3 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/pocket/store/walletslot/WalletSlotStore.java @@ -0,0 +1,35 @@ +/* + * + */ +package io.kumare.iqr.mod.pocket.store.walletslot; + +// spring +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Service +public class WalletSlotStore extends AppKeyEntityStore { + + // ::: vars + // + @Autowired + private WalletSlotRepository repository; + + // ::: override + // + @Override + public WalletSlotRepository getRepository() { + return repository; + } + + // ::: api + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/TaxonomyConstants.java b/src/main/java/io/kumare/iqr/mod/taxonomy/TaxonomyConstants.java new file mode 100644 index 0000000..83ad385 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/TaxonomyConstants.java @@ -0,0 +1,20 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy; + +// base +import io.kumare.iqr.app.AppConstants; + +/** + * + * @author afatecha + */ +public class TaxonomyConstants { + + // ::: codes + // + public static final int CODE = AppConstants.TAXONOMY_CODE; + public static final String NAME = "taxonomy"; + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/TaxonomyController.java b/src/main/java/io/kumare/iqr/mod/taxonomy/TaxonomyController.java new file mode 100644 index 0000000..fedfd17 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/TaxonomyController.java @@ -0,0 +1,62 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy; + +// java +import io.kumare.iqr.mod.taxonomy.store.TaxonomyEntities; +import java.util.Arrays; +import java.util.List; +// base +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app +import io.kumare.iqr.app.module.AppModuleController; +// module +import io.kumare.iqr.mod.taxonomy.store.taxa.TaxaStore; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonStore; +import io.kumare.iqr.mod.taxonomy.store.taxonrelation.TaxonRelationStore; + +/** + * + * @author afatecha + */ +public class TaxonomyController extends AppModuleController { + + // ::: api + // + @Override + public boolean hasStore(String name) { + return TaxonomyEntities.hasDescriptor(name); + } + + @Override + public EntityDescriptor getEntityDescriptor(Class entityClass) { + return TaxonomyEntities.descriptorOf(entityClass); + } + + @Override + public EntityDescriptor getEntityDescriptor(String name) { + return TaxonomyEntities.descriptorOf(name); + } + + @Override + public List getEntityDescriptors() { + return Arrays.asList(TaxonomyEntities.values()); + } + + // ::: stores + // + public TaxaStore getTaxaStore() { + return getService(TaxaStore.class); + } + + public TaxonStore getTaxonStore() { + return getService(TaxonStore.class); + } + + public TaxonRelationStore getTaxonRelationStore() { + return getService(TaxonRelationStore.class); + } + + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/TaxonomyErrors.java b/src/main/java/io/kumare/iqr/mod/taxonomy/TaxonomyErrors.java new file mode 100644 index 0000000..80be7b1 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/TaxonomyErrors.java @@ -0,0 +1,118 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy; + +// java +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.transport.TransportCode; +import static io.kumare.lib.transport.Transports.code; +import io.kumare.lib.v.ExceptionPrototype; +// app +import io.kumare.iqr.app.AppException; +import io.kumare.iqr.app.endpoint.AppTransports; + + +/** + * + * @author afatecha + */ +public enum TaxonomyErrors implements ExceptionPrototype { + + + // taxa + taxa_notfound(1, code(AppTransports.http, 400)), + taxa_data_notfound(1, code(AppTransports.http, 400)), + taxa_preload_empty(1, code(AppTransports.http, 400)), + taxa_data_schema_empty(1, code(AppTransports.http, 400)), + taxa_data_attributes_empty(1, code(AppTransports.http, 400)), + taxa_externalid_empty(1, code(AppTransports.http, 400)), + taxa_entitykey_empty(1, code(AppTransports.http, 400)), + taxa_space_empty(1, code(AppTransports.http, 400)), + taxa_modeltype_empty(1, code(AppTransports.http, 400)), + taxa_custom_empty(1, code(AppTransports.http, 400)), + taxa_name_empty(1, code(AppTransports.http, 400)), + taxa_description_empty(1, code(AppTransports.http, 400)), + + // taxon + taxon_notfound(1, code(AppTransports.http, 400)), + taxon_data_notfound(1, code(AppTransports.http, 400)), + taxon_preload_empty(1, code(AppTransports.http, 400)), + taxon_data_attributes_empty(1, code(AppTransports.http, 400)), + taxon_externalid_empty(1, code(AppTransports.http, 400)), + taxon_entitykey_empty(1, code(AppTransports.http, 400)), + taxon_space_empty(1, code(AppTransports.http, 400)), + taxon_taxakey_empty(1, code(AppTransports.http, 400)), + taxon_typekey_empty(1, code(AppTransports.http, 400)), + taxon_typevalue_empty(1, code(AppTransports.http, 400)), + taxon_parentkey_empty(1, code(AppTransports.http, 400)), + taxon_parentvalue_empty(1, code(AppTransports.http, 400)), + taxon_level_empty(1, code(AppTransports.http, 400)), + taxon_ordinal_empty(1, code(AppTransports.http, 400)), + taxon_value_empty(1, code(AppTransports.http, 400)), + taxon_name_empty(1, code(AppTransports.http, 400)), + taxon_main_empty(1, code(AppTransports.http, 400)), + taxon_description_empty(1, code(AppTransports.http, 400)), + taxon_taxa_notfound(1, code(AppTransports.http, 400)), + taxon_type_notfound(1, code(AppTransports.http, 400)), + taxon_parent_notfound(1, code(AppTransports.http, 400)), + + // taxon relation + taxonrelation_notfound(1, code(AppTransports.http, 400)), + taxonrelation_data_notfound(1, code(AppTransports.http, 400)), + taxonrelation_preload_empty(1, code(AppTransports.http, 400)), + taxonrelation_data_note_empty(1, code(AppTransports.http, 400)), + taxonrelation_data_attributes_empty(1, code(AppTransports.http, 400)), + taxonrelation_externalid_empty(1, code(AppTransports.http, 400)), + taxonrelation_space_empty(1, code(AppTransports.http, 400)), + taxonrelation_literal_empty(1, code(AppTransports.http, 400)), + taxonrelation_subject_notfound(1, code(AppTransports.http, 400)), + taxonrelation_predicate_notfound(1, code(AppTransports.http, 400)), + taxonrelation_object_notfound(1, code(AppTransports.http, 400)); + + // ::: vars + // + private final Map transportCodes = new HashMap(); + private final int code; + + // ::: constructors + // + private TaxonomyErrors(int code, TransportCode... codes) { + this.code = code; + if (codes != null) { + for (var i : codes) { + if (i != null) { + transportCodes.put(i.getId(), i.getCode()); + } + } + } + } + + // ::: prototype api + // + @Override + public int getCode() { + return code; + } + + @Override + public String getName() { + return name(); + } + + @Override + public Map getTransportCodes() { + return transportCodes; + } + + @Override + public RuntimeException newInstance(String msg, Throwable cause, Map extra) { + var ex = new AppException(this, msg, cause); + ex.setExtra(extra); + return ex; + } + + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/TaxonomyModule.java b/src/main/java/io/kumare/iqr/mod/taxonomy/TaxonomyModule.java new file mode 100644 index 0000000..452f433 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/TaxonomyModule.java @@ -0,0 +1,37 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy; + +// java +import io.kumare.lib.base.server.spring.module.BaseModule; + + +/** + * + * @author afatecha + */ +public class TaxonomyModule extends BaseModule { + + // ::: + // + public static final TaxonomyController controller = new TaxonomyController(); + + // ::: api + // + @Override + public int getId() { + return TaxonomyConstants.CODE; + } + + @Override + public String getName() { + return TaxonomyConstants.NAME; + } + + @Override + public TaxonomyController getController() { + return controller; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/TaxonomyPermissions.java b/src/main/java/io/kumare/iqr/mod/taxonomy/TaxonomyPermissions.java new file mode 100644 index 0000000..fef97de --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/TaxonomyPermissions.java @@ -0,0 +1,103 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy; + +// base +import io.kumare.iqr.mod.taxonomy.store.TaxonomyEntities; +import io.kumare.lib.app.api.security.PermissionReference; +// app +import io.kumare.iqr.app.AppErrors; + +/** + * + * @author afatecha + */ +public enum TaxonomyPermissions { + + // taxa + //taxa_add(TaxonomyEntities.taxa), + //taxa_edit(TaxonomyEntities.taxa), + //taxa_find(TaxonomyEntities.taxa), + //taxa_enable(TaxonomyEntities.taxa), + //taxa_disable(TaxonomyEntities.taxa), + //taxa_list(TaxonomyEntities.taxa), + //taxa_delete(TaxonomyEntities.taxa), + //taxa_preload(TaxonomyEntities.taxa), + // + taxa_viewer(TaxonomyEntities.taxa), + //taxa_guest(TaxonomyEntities.taxa), + //taxa_collab(TaxonomyEntities.taxa), + taxa_worker(TaxonomyEntities.taxa), + //taxa_control(TaxonomyEntities.taxa), + taxa_manager(TaxonomyEntities.taxa), + taxa_admin(null), + taxa_system(null), + + // taxon + //taxon_add(TaxonomyEntities.taxon), + //taxon_edit(TaxonomyEntities.taxon), + //taxon_find(TaxonomyEntities.taxon), + //taxon_enable(TaxonomyEntities.taxon), + //taxon_disable(TaxonomyEntities.taxon), + //taxon_list(TaxonomyEntities.taxon), + //taxon_delete(TaxonomyEntities.taxon), + //taxon_preload(TaxonomyEntities.taxon), + // + taxon_viewer(TaxonomyEntities.taxon), + //taxon_guest(TaxonomyEntities.taxon), + //taxon_collab(TaxonomyEntities.taxon), + taxon_worker(TaxonomyEntities.taxon), + //taxon_control(TaxonomyEntities.taxon), + taxon_manager(TaxonomyEntities.taxon), + taxon_admin(null), + taxon_system(null), + + // taxon relation + //taxon_relation_add(TaxonomyEntities.taxonRelation), + //taxon_relation_edit(TaxonomyEntities.taxonRelation), + //taxon_relation_find(TaxonomyEntities.taxonRelation), + //taxon_relation_enable(TaxonomyEntities.taxonRelation), + //taxon_relation_disable(TaxonomyEntities.taxonRelation), + //taxon_relation_list(TaxonomyEntities.taxonRelation), + //taxon_relation_delete(TaxonomyEntities.taxonRelation), + //taxon_relation_preload(TaxonomyEntities.taxonRelation), + // + taxon_relation_viewer(TaxonomyEntities.taxonRelation), + //taxon_relation_guest(TaxonomyEntities.taxonRelation), + //taxon_relation_collab(TaxonomyEntities.taxonRelation), + taxon_relation_worker(TaxonomyEntities.taxonRelation), + //taxon_relation_control(TaxonomyEntities.taxonRelation), + taxon_relation_manager(TaxonomyEntities.taxonRelation), + taxon_relation_admin(null), + taxon_relation_system(null); + + + // ::: + // + private final TaxonomyEntities resourceType; + + TaxonomyPermissions(TaxonomyEntities entityRef) { + this.resourceType = entityRef; + } + + // + public PermissionReference toReference() { + return toReference(null); + } + + public PermissionReference toReference(String resourceKey) { + var ref = new PermissionReference() + .module(TaxonomyConstants.NAME) + .permission(name()) + .error(AppErrors.action_unauthorized); + + if (resourceType != null && resourceKey != null) { + ref.resourceType(resourceType.name()) + .resourceKey(resourceKey); + } + + return ref; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaActionArgument.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaActionArgument.java new file mode 100644 index 0000000..20efe16 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaActionArgument.java @@ -0,0 +1,29 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxa; + +// base +import io.kumare.iqr.app.action.AppEntityActionArgument; +// entity +import io.kumare.iqr.mod.taxonomy.store.taxa.TaxaEntity; + +/** + * + * @author afatecha + */ +public class TaxaActionArgument extends AppEntityActionArgument { + + // ::: constructors + // + public TaxaActionArgument() { + } + + public TaxaActionArgument(TaxaEntity entity) { + super(entity); + } + + // ::: api + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaAddAction.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaAddAction.java new file mode 100644 index 0000000..98731df --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaAddAction.java @@ -0,0 +1,128 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxa; + +// java +import java.util.List; +// lib +import io.kumare.lib.base.server.spring.action.Actions; +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.taxonomy.TaxonomyErrors; +// entity +import io.kumare.iqr.mod.taxonomy.store.taxa.TaxaEntity; + +import io.kumare.iqr.mod.taxonomy.action.taxon.TaxonAddAction; +import io.kumare.iqr.mod.taxonomy.action.taxon.TaxonAddArgument; + +/** + * + * @author afatecha + */ +public class TaxaAddAction extends AppAction> { + + // ::: vars + // + private TaxaEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, TaxonomyErrors.taxa_notfound); + + // relations + + // fields + //V.ifEmpty(model.getExternalId(), TaxonomyErrors.taxa_externalid_empty); + V.ifEmpty(model.getEntityKey(), TaxonomyErrors.taxa_entitykey_empty); + //V.ifEmpty(model.getSpace(), TaxonomyErrors.taxa_space_empty); + V.ifEmpty(model.getModelType(), TaxonomyErrors.taxa_modeltype_empty); + //V.ifEmpty(model.isCustom(), TaxonomyErrors.taxa_custom_empty); + V.ifEmpty(model.getName(), TaxonomyErrors.taxa_name_empty); + //V.ifEmpty(model.getDescription(), TaxonomyErrors.taxa_description_empty); + // data + //V.ifNull(model.getData(), TaxonomyErrors.taxa_data_notfound); + //V.ifEmpty(model.getData().getSchema(), TaxonomyErrors.taxa_data_schema_empty); + //V.ifEmpty(model.getData().getAttributes(), TaxonomyErrors.taxa_data_attributes_empty); + } + + @Override + protected void doAction() { + + // model + var model = makeModel(); + + // add + entity = saveEntity(model); + + // add others + addTaxons(getArgument().getTaxons()); + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private TaxaEntity makeModel() { + + var argModel = getArgument().getEntity(); + var model = new TaxaEntity(); + + // fields + model.setExternalId(argModel.getExternalId()); + model.setEntityKey(argModel.getEntityKey()); + model.setSpace(argModel.getSpace()); + model.setModelType(argModel.getModelType()); + model.setCustom(argModel.isCustom()); + model.setName(argModel.getName()); + model.setDescription(argModel.getDescription()); + model.setActive(true); + + // data + model.setData(argModel.getData()); + + return model; + } + + // ::: save + // + private TaxaEntity saveEntity(TaxaEntity model) { + + var store = AppModules.taxonomy.getController().getTaxaStore(); + + var saved = store.add(getContext(), model); + getContext().attach(saved.getId(), saved); + return saved; + } + + // ::: add taxons + // + private void addTaxons(List list) { + if(list != null) { + list.forEach(i->{ + i.getEntity().taxa(entity); + Actions.perform(getContext(), new TaxonAddAction(), i); + }); + } + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaAddArgument.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaAddArgument.java new file mode 100644 index 0000000..e67fe9c --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaAddArgument.java @@ -0,0 +1,48 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxa; + +// java +import java.util.List; +// app +import io.kumare.iqr.mod.taxonomy.store.taxa.TaxaEntity; +import io.kumare.iqr.mod.taxonomy.action.taxon.TaxonAddArgument; + +/** + * + * @author afatecha + */ +public class TaxaAddArgument extends TaxaActionArgument { + + // ::: vars + // + private List taxons; + + // ::: constructors + // + public TaxaAddArgument() { + } + + public TaxaAddArgument(TaxaEntity entity) { + super(entity); + } + + // ::: fields + // + public List getTaxons() { + return taxons; + } + + public void setTaxons(List list) { + this.taxons = list; + } + + // ::: fluent api + // + public TaxaAddArgument taxons(List taxons) { + setTaxons(taxons); + return this; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaDeleteAction.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaDeleteAction.java new file mode 100644 index 0000000..f936776 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaDeleteAction.java @@ -0,0 +1,59 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxa; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.taxonomy.TaxonomyErrors; +// entity +import io.kumare.iqr.mod.taxonomy.store.taxa.TaxaEntity; + +/** + * + * @author afatecha + */ +public class TaxaDeleteAction extends AppAction> { + + // ::: vars + // + private TaxaEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), TaxonomyErrors.taxa_notfound); + V.ifNull(getArgument().getEntity().getId(), TaxonomyErrors.taxa_notfound); + } + + @Override + protected void doAction() { + + var argModel = getArgument().getEntity(); + + deleteEntity(argModel); + } + + @Override + protected void setResultOnly() { + } + + // ::: delete + // + private void deleteEntity(TaxaEntity model) { + + var store = AppModules.taxonomy.getController().getTaxaStore(); + + store.deleteById(getContext(), model.getId()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaEditAction.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaEditAction.java new file mode 100644 index 0000000..2e58226 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaEditAction.java @@ -0,0 +1,111 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxa; + +// lib +import io.kumare.lib.v.V; +// app +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.taxonomy.TaxonomyErrors; +// entity +import io.kumare.iqr.mod.taxonomy.store.taxa.TaxaEntity; + +/** + * + * @author afatecha + */ +public class TaxaEditAction extends AppAction> { + + // ::: vars + // + private TaxaEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, TaxonomyErrors.taxa_notfound); + + // fields + //V.ifEmpty(model.getExternalId(), TaxonomyErrors.taxa_externalid_empty); + //V.ifEmpty(model.getEntityKey(), TaxonomyErrors.taxa_entitykey_empty); + //V.ifEmpty(model.getSpace(), TaxonomyErrors.taxa_space_empty); + //V.ifEmpty(model.getModelType(), TaxonomyErrors.taxa_modeltype_empty); + //V.ifEmpty(model.isCustom(), TaxonomyErrors.taxa_custom_empty); + //V.ifEmpty(model.getName(), TaxonomyErrors.taxa_name_empty); + //V.ifEmpty(model.getDescription(), TaxonomyErrors.taxa_description_empty); + // data + //V.ifNull(model.getData(), TaxonomyErrors.taxa_data_notfound); + //V.ifEmpty(model.getData().getSchema(), TaxonomyErrors.taxa_data_schema_empty); + //V.ifEmpty(model.getData().getAttributes(), TaxonomyErrors.taxa_data_attributes_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + var taxonomy = AppModules.taxonomy.getController(); + var taxaStore = taxonomy.getTaxaStore(); + + // edit + entity = taxaStore.ensure(getContext(), argModel, TaxonomyErrors.taxa_notfound); + + editEntity(); + + entity = saveEntity(); + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private void editEntity() { + + var model = getArgument().getEntity(); + + // fields + entity.setExternalId(V.firstNotEmpty(model.getExternalId(), entity.getExternalId())); + entity.setEntityKey(V.firstNotEmpty(model.getEntityKey(), entity.getEntityKey())); + entity.setSpace(V.firstNotEmpty(model.getSpace(), entity.getSpace())); + //entity.setModelType(V.firstNotEmpty(model.getModelType(), entity.getModelType())); + //entity.setCustom(V.firstNotEmpty(model.isCustom(), entity.isCustom())); + entity.setName(V.firstNotEmpty(model.getName(), entity.getName())); + entity.setDescription(V.firstNotEmpty(model.getDescription(), entity.getDescription())); + + // data + if (model.getData() != null) { + entity.setData(model.getData()); + } + + } + + // ::: save + // + private TaxaEntity saveEntity() { + + var store = AppModules.taxonomy.getController().getTaxaStore(); + + var saved = store.edit(getContext(), entity); + getContext().attach(saved.getId(), saved); + return saved; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaEditArgument.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaEditArgument.java new file mode 100644 index 0000000..b2e5625 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaEditArgument.java @@ -0,0 +1,32 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxa; + +// app +import io.kumare.iqr.mod.taxonomy.store.taxa.TaxaEntity; + +/** + * + * @author afatecha + */ +public class TaxaEditArgument extends TaxaActionArgument { + + // ::: vars + // + + + // ::: constructors + // + public TaxaEditArgument() { + } + + public TaxaEditArgument(TaxaEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaEnableAction.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaEnableAction.java new file mode 100644 index 0000000..e51acdb --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaEnableAction.java @@ -0,0 +1,60 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxa; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.taxonomy.TaxonomyErrors; +// entity +import io.kumare.iqr.mod.taxonomy.store.taxa.TaxaEntity; + + +/** + * + * @author afatecha + */ +public class TaxaEnableAction extends AppAction { + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), TaxonomyErrors.taxa_notfound); + V.ifNull(getArgument().getEntity().getId(), TaxonomyErrors.taxa_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + + enableEntity(model); + } + + @Override + protected void setResultOnly() { + } + + // ::: enable + // + private void enableEntity(TaxaEntity model) { + + var store = AppModules.taxonomy.getController().getTaxaStore(); + + if (getArgument().getEntity().isActive()) { + store.enableById(getContext(), model.getId()); + } else { + store.disableById(getContext(), model.getId()); + } + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaExportAction.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaExportAction.java new file mode 100644 index 0000000..c887902 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaExportAction.java @@ -0,0 +1,85 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxa; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.LinkedList; +import java.util.Map; +// spring +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// entity +import io.kumare.iqr.mod.taxonomy.store.taxa.TaxaEntity; +import io.kumare.iqr.mod.taxonomy.store.taxa.TaxaMapBuilder; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonMapBuilder; +import static io.kumare.lib.app.api.store.EntityFieldDescriptor.MAIN; + +/** + * + * @author afatecha + */ +public class TaxaExportAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + } + + @Override + protected void doAction() { + exportTaxas(); + exportTaxons(); + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: taxas + // + private void exportTaxas() { + + var output = new LinkedList(); + + var store = AppModules.taxonomy.getController().getTaxaStore(); + var found = store.listAll(getContext()); + + var builder = new TaxaMapBuilder().addMainGroup(); + output.addAll(builder.build(getContext(), found)); + + result.put("taxas", output); + } + + private void exportTaxons() { + + var output = new LinkedList(); + + var store = AppModules.taxonomy.getController().getTaxonStore(); + var found = store.listAll(getContext()); + + var builder = new TaxonMapBuilder() + .addMainGroup() + .add("taxa").add("parent").add("type"); + + output.addAll(builder.build(getContext(), found)); + + result.put("taxons", output); + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaFindAction.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaFindAction.java new file mode 100644 index 0000000..94821b5 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaFindAction.java @@ -0,0 +1,64 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxa; + +// java +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.taxonomy.TaxonomyErrors; +// entity +import io.kumare.iqr.mod.taxonomy.store.taxa.TaxaEntity; + + +/** + * + * @author afatecha + */ +public class TaxaFindAction extends AppAction { + + // ::: vars + // + private TaxaEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), TaxonomyErrors.taxa_notfound); + V.ifNull(getArgument().getEntity().getId(), TaxonomyErrors.taxa_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + entity = findEntity(model); + } + + @Override + protected void setResultOnly() { + var result = new HashMap(); + result.put("entity", entity); + setResult(result); + } + + // ::: find + // + private TaxaEntity findEntity(TaxaEntity model) { + + var store = AppModules.taxonomy.getController().getTaxaStore(); + return store.findById(getContext(), model.getId()); + } + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaImportAction.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaImportAction.java new file mode 100644 index 0000000..ef4bbc9 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaImportAction.java @@ -0,0 +1,100 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxa; + +// java +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +// lib +import io.kumare.lib.base.server.spring.action.Actions; +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +// entity +import io.kumare.iqr.mod.taxonomy.store.taxa.TaxaEntity; +import io.kumare.iqr.mod.taxonomy.action.taxon.TaxonAddArgument; + +/** + * + * @author afatecha + */ +public class TaxaImportAction extends AppAction> { + + // ::: vars + // + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifEmpty(getArgument().getTaxas(), AppErrors.action_arg_notfound); + } + + @Override + protected void doAction() { + var arguments = readInput(); + V.ifEmpty(arguments, AppErrors.action_arg_notfound); + + clearAll(); + + addTaxas(arguments); + } + + @Override + protected void setResultOnly() { + } + + // ::: model + // + private List readInput() { + + var list = new LinkedList(); + var taxonMap = makeTaxonMapByTaxaKey(); + + getArgument().getTaxas().forEach(i -> { + var taxons = taxonMap.get(i.getEntity().getEntityKey()); + list.add(i.taxons(taxons)); + }); + + return list; + } + + private Map> makeTaxonMapByTaxaKey() { + var map = new HashMap>(); + + getArgument().getTaxons().forEach(i->{ + var key = i.getEntity().getTaxaKey(); + map.putIfAbsent(key, new LinkedList<>()); + map.get(key).add(i); + }); + + return map; + } + + // ::: clear + // + private void clearAll() { + var controller = AppModules.taxonomy.getController(); + controller.getTaxonStore().getRepository().deleteAll(); + controller.getTaxaStore().getRepository().deleteAll(); + } + + // ::: add taxas + // + private void addTaxas(List list) { + if (list != null) { + list.forEach(i -> { + Actions.perform(getContext(), new TaxaAddAction(), i); + }); + } + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaImportArgument.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaImportArgument.java new file mode 100644 index 0000000..8fb6c86 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaImportArgument.java @@ -0,0 +1,45 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxa; + +// base +import io.kumare.iqr.app.action.AppActionArgument; +import io.kumare.iqr.mod.taxonomy.action.taxon.TaxonAddArgument; +import java.util.List; + +/** + * + * @author afatecha + */ +public class TaxaImportArgument extends AppActionArgument { + + // ::: vars + // + private List taxas; + private List taxons; + + // ::: constructors + // + public TaxaImportArgument() { + } + + // ::: api + // + public List getTaxas() { + return taxas; + } + + public void setTaxas(List taxas) { + this.taxas = taxas; + } + + public List getTaxons() { + return taxons; + } + + public void setTaxons(List taxons) { + this.taxons = taxons; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaListAction.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaListAction.java new file mode 100644 index 0000000..645a4f6 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaListAction.java @@ -0,0 +1,148 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxa; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.LinkedList; +import java.util.Map; +// spring +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// entity +import io.kumare.iqr.mod.taxonomy.store.taxa.TaxaEntity; +import io.kumare.iqr.mod.taxonomy.store.taxa.TaxaMapBuilder; + + +/** + * + * @author afatecha + */ +public class TaxaListAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private final List entities = new LinkedList<>(); + + // ::: public api + // + public List getEntities() { + return entities; + } + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + } + + @Override + protected void doAction() { + + result.put("pageable", getArgument().isPageable()); + result.put("wrapped", getArgument().isWrapped()); + + if (getArgument().isPageable()) { + + var page = makePage(); + entities.addAll(page.toList()); + + if (getArgument().isWrapped()) { + result.put("page", makeWrappedPage(page)); + } else { + result.put("page", page); + } + + } else { + + var list = makeList(); + entities.addAll(list); + + if (getArgument().isWrapped()) { + result.put("list", makeWrappedList()); + } else { + result.put("list", list); + } + } + + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: page + // + private Page makePage() { + + var page = getArgument().getPageNumber(); + var size = getArgument().getPageSize(); + //var sort = getArgument().getSort(); + + var pageable = PageRequest.of(page, size); + + var store = AppModules.taxonomy.getController().getTaxaStore(); + return store.getRepository().findAll(pageable); + } + + // ::: wrapped page + // + private Map makeWrappedPage(Page found) { + + var page = new HashMap(); + var content = new LinkedList(); + + wrapList(entities, content); + + page.put("size", found.getSize()); + page.put("number", found.getNumber()); + page.put("totalElements", found.getTotalElements()); + page.put("totalPages", found.getTotalPages()); + page.put("content", content); + + return page; + } + + + // ::: list + // + + private List makeList() { + + var store = AppModules.taxonomy.getController().getTaxaStore(); + + return store.listAll(getContext()); + } + + // ::: wrapped list + private List makeWrappedList() { + var list = new LinkedList(); + + wrapList(entities, list); + + return list; + } + + // ::: wrapper + // + private void wrapList(List found, List output) { + + var builder = new TaxaMapBuilder().addListGroup(); + + + output.addAll(builder.build(getContext(), found)); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaListArgument.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaListArgument.java new file mode 100644 index 0000000..ad652a8 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaListArgument.java @@ -0,0 +1,33 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxa; + +// app +import io.kumare.iqr.app.action.AppListActionArgument; +// store +import io.kumare.iqr.mod.taxonomy.store.taxa.TaxaEntity; + +/** + * + * @author afatecha + */ +public class TaxaListArgument extends AppListActionArgument { + + // ::: vars + // + + // ::: constructors + // + public TaxaListArgument() { + } + + public TaxaListArgument(TaxaEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaPreloadAction.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaPreloadAction.java new file mode 100644 index 0000000..e4fdf8c --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaPreloadAction.java @@ -0,0 +1,101 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxa; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.taxonomy.TaxonomyErrors; +// entity +import io.kumare.iqr.mod.taxonomy.store.taxa.TaxaEntity; +// relations + + +/** + * + * @author afatecha + */ +public class TaxaPreloadAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private Map params = new HashMap<>(); + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifEmpty(getArgument().getAction(), TaxonomyErrors.taxa_preload_empty); + } + + @Override + protected void doAction() { + if(getArgument().getParams() != null) { + params = getArgument().getParams(); + } + + switch (getArgument().getAction()) { + case "find" -> + prepareFind(); + case "list" -> + prepareList(); + case "add" -> + prepareAdd(); + case "edit" -> + prepareEdit(); + } + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: preload + // + private void prepareAdd() { + + } + + private void prepareEdit() { + var entity = findEntity(); + result.put("entity", entity); + + } + + private void prepareList() { + } + + private void prepareFind() { + var entity = findEntity(); + result.put("entity", entity); + + } + + // ::: queries + // + private TaxaEntity findEntity() { + var store = AppModules.taxonomy.getController().getTaxaStore(); + + var id = (String) params.get("id"); + if(id == null && getArgument().getEntity() != null) { + id = getArgument().getEntity().getId(); + } + return store.findById(getContext(), id); + } + + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaPreloadArgument.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaPreloadArgument.java new file mode 100644 index 0000000..122e405 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxa/TaxaPreloadArgument.java @@ -0,0 +1,26 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxa; + +/** + * + * @author afatecha + */ +public class TaxaPreloadArgument extends TaxaActionArgument { + + // ::: vars + // + private String action; + + // ::: fields + // + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonActionArgument.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonActionArgument.java new file mode 100644 index 0000000..a893462 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonActionArgument.java @@ -0,0 +1,29 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxon; + +// base +import io.kumare.iqr.app.action.AppEntityActionArgument; +// entity +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; + +/** + * + * @author afatecha + */ +public class TaxonActionArgument extends AppEntityActionArgument { + + // ::: constructors + // + public TaxonActionArgument() { + } + + public TaxonActionArgument(TaxonEntity entity) { + super(entity); + } + + // ::: api + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonActionUtils.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonActionUtils.java new file mode 100644 index 0000000..4ed5069 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonActionUtils.java @@ -0,0 +1,65 @@ +/* + */ +package io.kumare.iqr.mod.taxonomy.action.taxon; + +// base +import io.kumare.lib.javax.maps.SmartMap; +import io.kumare.lib.javax.types.Types; +import io.kumare.lib.v.ExceptionPrototype; +import io.kumare.lib.v.V; +// app +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonFieldSchema; + +/** + * + * @author afatecha + */ +public class TaxonActionUtils { + + public static T value(SmartMap schema, + String fieldName, + T fieldValue, + ExceptionPrototype proto) { + return value(schema, fieldName, fieldValue, null, proto); + } + + public static T value(SmartMap schema, + String fieldName, + T fieldValue, + T previousValue, + ExceptionPrototype proto) { + if (schema == null || !schema.exists(fieldName)) { + return fieldValue; + } + + var fieldSchema = schema.toSmartMap(fieldName); + var enabled = fieldSchema.getBoolean(TaxonFieldSchema.enabled.name(), true); + var required = fieldSchema.getBoolean(TaxonFieldSchema.required.name()); + + if(enabled && required && fieldValue == null && previousValue != null) { + return previousValue; + } + + var defval = fieldSchema.find(TaxonFieldSchema.value.name()); + if (enabled && required && defval != null && V.isEmpty(fieldValue)) { + return (T) defval; + } + + if (enabled && required) { + V.ifEmpty(fieldValue, proto); + } + + var options = fieldSchema.toSmartMapList(TaxonFieldSchema.options.name()); + if (!options.isEmpty()) { + var s = Types.toString(fieldValue); + for (var i : options) { + if (s.equals(i.getString(TaxonFieldSchema.value.name()))) { + return fieldValue; + } + } + } + + return fieldValue; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonAddAction.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonAddAction.java new file mode 100644 index 0000000..d01b11f --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonAddAction.java @@ -0,0 +1,204 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxon; + +// java +import java.util.List; +// lib +import io.kumare.lib.base.server.spring.action.Actions; +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// app +import io.kumare.iqr.mod.taxonomy.TaxonomyErrors; +import static io.kumare.iqr.mod.taxonomy.action.taxon.TaxonActionUtils.value; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; +import io.kumare.iqr.mod.taxonomy.store.taxa.TaxaEntity; +import io.kumare.iqr.mod.taxonomy.action.taxonrelation.TaxonRelationAddAction; +import io.kumare.iqr.mod.taxonomy.action.taxonrelation.TaxonRelationAddArgument; +import io.kumare.lib.javax.maps.SmartMap; + +/** + * + * @author afatecha + */ +public class TaxonAddAction extends AppAction> { + + // ::: vars + // + private TaxonEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, TaxonomyErrors.taxon_notfound); + + // relations + //V.ifNull(model.getTaxa(), TaxonomyErrors.taxon_taxa_notfound); + //V.ifNull(model.getType(), TaxonomyErrors.taxon_type_notfound); + //V.ifNull(model.getParent(), TaxonomyErrors.taxon_parent_notfound); + // fields + //V.ifEmpty(model.getExternalId(), TaxonomyErrors.taxon_externalid_empty); + //V.ifEmpty(model.getEntityKey(), TaxonomyErrors.taxon_entitykey_empty); + //V.ifEmpty(model.getSpace(), TaxonomyErrors.taxon_space_empty); + V.ifEmpty(model.getTaxaKey(), TaxonomyErrors.taxon_taxakey_empty); + //V.ifEmpty(model.getTypeKey(), TaxonomyErrors.taxon_typekey_empty); + //V.ifEmpty(model.getTypeValue(), TaxonomyErrors.taxon_typevalue_empty); + //V.ifEmpty(model.getParentKey(), TaxonomyErrors.taxon_parentkey_empty); + //V.ifEmpty(model.getParentValue(), TaxonomyErrors.taxon_parentvalue_empty); + //V.ifEmpty(model.getLevel(), TaxonomyErrors.taxon_level_empty); + //V.ifEmpty(model.getOrdinal(), TaxonomyErrors.taxon_ordinal_empty); + //V.ifEmpty(model.getValue(), TaxonomyErrors.taxon_value_empty); + V.ifEmpty(model.getName(), TaxonomyErrors.taxon_name_empty); + //V.ifEmpty(model.isMain(), TaxonomyErrors.taxon_main_empty); + //V.ifEmpty(model.getDescription(), TaxonomyErrors.taxon_description_empty); + // data + //V.ifNull(model.getData(), TaxonomyErrors.taxon_data_notfound); + //V.ifEmpty(model.getData().getAttributes(), TaxonomyErrors.taxon_data_attributes_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + var taxonomy = AppModules.taxonomy.getController(); + + var taxaStore = taxonomy.getTaxaStore(); + var taxonStore = taxonomy.getTaxonStore(); + + var taxa = taxaStore.find(getContext(), argModel.getTaxa()); + if (taxa == null) { + taxa = taxaStore.ensureByKey(getContext(), argModel.getTaxaKey(), TaxonomyErrors.taxon_taxa_notfound); + } + + var type = taxonStore.find(getContext(), argModel.getType()); + var parent = taxonStore.find(getContext(), argModel.getParent()); + + // model + var model = makeModel(taxa, type, parent); + + // add + entity = saveEntity(model); + + // main + if (entity.isMain()) { + taxonomy.getTaxonStore().setAsDefault(getContext(), entity); + } + + // add others + addChildren(getArgument().getChildren()); + addRelations(getArgument().getRelations()); + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private TaxonEntity makeModel(TaxaEntity taxa, TaxonEntity type, TaxonEntity parent) { + // schema + var taxaSchema = taxa.getData() == null ? null : taxa.getData().getSchema(); + var schema = taxaSchema == null ? null : new SmartMap(taxaSchema); + + // model + var argModel = getArgument().getEntity(); + var model = new TaxonEntity(); + + model.setActive(true); + model.setLevel(1); + + // relations + model.setTaxa(taxa); + model.setTaxaKey(argModel.getTaxaKey()); + + if (type != null) { + model.setType(type); + model.setTypeKey(argModel.getTypeKey()); + model.setTypeValue(argModel.getTypeValue()); + } + + if (parent != null) { + model.setParent(parent); + model.setParentKey(argModel.getParentKey()); + model.setParentValue(argModel.getParentValue()); + model.setLevel(parent.getLevel() + 1); + } + + // fields + // space : temporalmente deshabilitado + + model.setExternalId(value(schema, "externalId", + argModel.getExternalId(), + TaxonomyErrors.taxon_externalid_empty)); + + model.setEntityKey(value(schema, "entityKey", + argModel.getEntityKey(), + TaxonomyErrors.taxon_entitykey_empty)); + + model.setValue(value(schema, "value", + argModel.getValue(), + TaxonomyErrors.taxon_value_empty)); + + model.setName(argModel.getName()); + + model.setMain(argModel.isMain()); + model.setDescription(argModel.getDescription()); + + // XXX FIX-IT + model.setOrdinal(argModel.getOrdinal()); + + return model; + } + + // ::: save + // + private TaxonEntity saveEntity(TaxonEntity model) { + + var store = AppModules.taxonomy.getController().getTaxonStore(); + + var saved = store.add(getContext(), model); + getContext().attach(saved.getId(), saved); + return saved; + } + + // ::: add children + // + private void addChildren(List list) { + if (list != null) { + list.forEach(i -> { + i.getEntity().parent(entity).taxa(entity.getTaxa()).taxaKey(entity.getTaxaKey()); + Actions.perform(getContext(), new TaxonAddAction(), i); + }); + } + } + + // ::: add relations + // + private void addRelations(List list) { + + if (list != null) { + list.forEach(i -> { + i.getEntity().subject(entity); + Actions.perform(getContext(), new TaxonRelationAddAction(), i); + }); + } + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonAddArgument.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonAddArgument.java new file mode 100644 index 0000000..2dca3c9 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonAddArgument.java @@ -0,0 +1,53 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxon; + +// java +import java.util.List; +// app +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; +import io.kumare.iqr.mod.taxonomy.action.taxonrelation.TaxonRelationAddArgument; + + +/** + * + * @author afatecha + */ +public class TaxonAddArgument extends TaxonActionArgument { + + // ::: vars + // + private List children; + private List relations; + + // ::: constructors + // + public TaxonAddArgument() { + } + + public TaxonAddArgument(TaxonEntity entity) { + super(entity); + } + + // ::: fields + // + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } + + public List getRelations() { + return relations; + } + + public void setRelations(List relations) { + this.relations = relations; + } + + + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonDeleteAction.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonDeleteAction.java new file mode 100644 index 0000000..407b948 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonDeleteAction.java @@ -0,0 +1,59 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxon; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.taxonomy.TaxonomyErrors; +// entity +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; + +/** + * + * @author afatecha + */ +public class TaxonDeleteAction extends AppAction> { + + // ::: vars + // + private TaxonEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), TaxonomyErrors.taxon_notfound); + V.ifNull(getArgument().getEntity().getId(), TaxonomyErrors.taxon_notfound); + } + + @Override + protected void doAction() { + + var argModel = getArgument().getEntity(); + + deleteEntity(argModel); + } + + @Override + protected void setResultOnly() { + } + + // ::: delete + // + private void deleteEntity(TaxonEntity model) { + + var store = AppModules.taxonomy.getController().getTaxonStore(); + + store.deleteById(getContext(), model.getId()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonEditAction.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonEditAction.java new file mode 100644 index 0000000..09f6f8a --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonEditAction.java @@ -0,0 +1,133 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxon; + +// lib +import io.kumare.lib.v.V; +// app +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.taxonomy.TaxonomyErrors; +import static io.kumare.iqr.mod.taxonomy.action.taxon.TaxonActionUtils.value; +// entity +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; +import io.kumare.lib.javax.maps.SmartMap; + +/** + * + * @author afatecha + */ +public class TaxonEditAction extends AppAction> { + + // ::: vars + // + private TaxonEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, TaxonomyErrors.taxon_notfound); + + // fields + //V.ifEmpty(model.getExternalId(), TaxonomyErrors.taxon_externalid_empty); + //V.ifEmpty(model.getEntityKey(), TaxonomyErrors.taxon_entitykey_empty); + //V.ifEmpty(model.getSpace(), TaxonomyErrors.taxon_space_empty); + //V.ifEmpty(model.getTaxaKey(), TaxonomyErrors.taxon_taxakey_empty); + //V.ifEmpty(model.getTypeKey(), TaxonomyErrors.taxon_typekey_empty); + //V.ifEmpty(model.getTypeValue(), TaxonomyErrors.taxon_typevalue_empty); + //V.ifEmpty(model.getParentKey(), TaxonomyErrors.taxon_parentkey_empty); + //V.ifEmpty(model.getParentValue(), TaxonomyErrors.taxon_parentvalue_empty); + //V.ifEmpty(model.getLevel(), TaxonomyErrors.taxon_level_empty); + //V.ifEmpty(model.getOrdinal(), TaxonomyErrors.taxon_ordinal_empty); + //V.ifEmpty(model.getValue(), TaxonomyErrors.taxon_value_empty); + //V.ifEmpty(model.getName(), TaxonomyErrors.taxon_name_empty); + //V.ifEmpty(model.isMain(), TaxonomyErrors.taxon_main_empty); + //V.ifEmpty(model.getDescription(), TaxonomyErrors.taxon_description_empty); + // data + //V.ifNull(model.getData(), TaxonomyErrors.taxon_data_notfound); + //V.ifEmpty(model.getData().getAttributes(), TaxonomyErrors.taxon_data_attributes_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + var taxonomy = AppModules.taxonomy.getController(); + var taxonStore = taxonomy.getTaxonStore(); + + // edit + entity = taxonStore.ensure(getContext(), argModel, TaxonomyErrors.taxon_notfound); + + var mainChanged = editEntity(); + + entity = saveEntity(); + + // watching default + if (mainChanged && entity.isMain()) { + taxonomy.getTaxonStore().setAsDefault(getContext(), entity); + } + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private boolean editEntity() { + // schema + var taxa = entity.getTaxa(); + var taxaSchema = taxa.getData() == null ? null : taxa.getData().getSchema(); + var schema = taxaSchema == null ? null : new SmartMap(taxaSchema); + + var model = getArgument().getEntity(); + var mainChanged = model.isMain() != entity.isMain(); + + // fields + // space : temporalmente deshabilitado + + entity.setExternalId(value(schema, "externalId", + model.getExternalId(), entity.getExternalId(), + TaxonomyErrors.taxon_externalid_empty)); + + if (model.getName() != null) { + entity.setName(model.getName()); + } + + entity.setValue(value(schema, "value", + model.getValue(), entity.getValue(), TaxonomyErrors.taxon_value_empty)); + + entity.setMain(model.isMain()); + entity.setDescription(model.getDescription()); + + return mainChanged; + } + + // ::: save + // + private TaxonEntity saveEntity() { + + var store = AppModules.taxonomy.getController().getTaxonStore(); + + var saved = store.edit(getContext(), entity); + getContext().attach(saved.getId(), saved); + return saved; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonEditArgument.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonEditArgument.java new file mode 100644 index 0000000..facfcc1 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonEditArgument.java @@ -0,0 +1,32 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxon; + +// app +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; + +/** + * + * @author afatecha + */ +public class TaxonEditArgument extends TaxonActionArgument { + + // ::: vars + // + + + // ::: constructors + // + public TaxonEditArgument() { + } + + public TaxonEditArgument(TaxonEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonEnableAction.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonEnableAction.java new file mode 100644 index 0000000..30456ba --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonEnableAction.java @@ -0,0 +1,60 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxon; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.taxonomy.TaxonomyErrors; +// entity +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; + + +/** + * + * @author afatecha + */ +public class TaxonEnableAction extends AppAction { + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), TaxonomyErrors.taxon_notfound); + V.ifNull(getArgument().getEntity().getId(), TaxonomyErrors.taxon_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + + enableEntity(model); + } + + @Override + protected void setResultOnly() { + } + + // ::: enable + // + private void enableEntity(TaxonEntity model) { + + var store = AppModules.taxonomy.getController().getTaxonStore(); + + if (getArgument().getEntity().isActive()) { + store.enableById(getContext(), model.getId()); + } else { + store.disableById(getContext(), model.getId()); + } + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonFindAction.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonFindAction.java new file mode 100644 index 0000000..3dbdc24 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonFindAction.java @@ -0,0 +1,70 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxon; + +// java +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.taxonomy.TaxonomyErrors; +// entity +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; + + +/** + * + * @author afatecha + */ +public class TaxonFindAction extends AppAction { + + // ::: vars + // + private TaxonEntity entity; + + // ::: public api + // + public TaxonEntity getEntity() { + return entity; + } + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), TaxonomyErrors.taxon_notfound); + V.ifNull(getArgument().getEntity().getId(), TaxonomyErrors.taxon_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + entity = findEntity(model); + } + + @Override + protected void setResultOnly() { + var result = new HashMap(); + result.put("entity", entity); + setResult(result); + } + + // ::: find + // + private TaxonEntity findEntity(TaxonEntity model) { + + var store = AppModules.taxonomy.getController().getTaxonStore(); + return store.findById(getContext(), model.getId()); + } + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonListAction.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonListAction.java new file mode 100644 index 0000000..606d871 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonListAction.java @@ -0,0 +1,157 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxon; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.LinkedList; +import java.util.Map; +// spring +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +import io.kumare.iqr.mod.taxonomy.store.taxa.TaxaEntity; +// entity +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonMapBuilder; + +/** + * + * @author afatecha + */ +public class TaxonListAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private final List entities = new LinkedList<>(); + + // ::: public api + // + public List getEntities() { + return entities; + } + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + } + + @Override + protected void doAction() { + result.put("pageable", getArgument().isPageable()); + result.put("wrapped", getArgument().isWrapped()); + + if (getArgument().isPageable()) { + + var page = makePage(); + entities.addAll(page.toList()); + + if (getArgument().isWrapped()) { + result.put("page", makeWrappedPage(page)); + } else { + result.put("page", page); + } + + } else { + + var list = makeList(); + entities.addAll(list); + + if (getArgument().isWrapped()) { + result.put("list", makeWrappedList()); + } else { + result.put("list", list); + } + } + + if (getArgument().isWithTaxa()) { + result.put("taxa", findTaxa()); + } + + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: find + // + protected TaxaEntity findTaxa() { + var store = AppModules.taxonomy.getController().getTaxaStore(); + var key = getArgument().getEntity().getTaxaKey(); + + return store.findByKey(getContext(), key); + } + + // ::: page + // + private Page makePage() { + + var page = getArgument().getPageNumber(); + var size = getArgument().getPageSize(); + //var sort = getArgument().getSort(); + + var pageable = PageRequest.of(page, size); + + var store = AppModules.taxonomy.getController().getTaxonStore(); + var taxaKey = getArgument().getEntity().getTaxaKey(); + return store.getRepository().findAllByTaxaKey(taxaKey, pageable); + } + + // ::: wrapped page + // + private Map makeWrappedPage(Page found) { + + var page = new HashMap(); + var content = new LinkedList(); + + wrapList(entities, content); + + page.put("size", found.getSize()); + page.put("number", found.getNumber()); + page.put("totalElements", found.getTotalElements()); + page.put("totalPages", found.getTotalPages()); + page.put("content", content); + + return page; + } + + private List makeList() { + + var store = AppModules.taxonomy.getController().getTaxonStore(); + + var taxaKey = getArgument().getEntity().getTaxaKey(); + return store.getRepository().findAllByTaxaKey(taxaKey); + } + + // ::: list + // + private List makeWrappedList() { + var list = new LinkedList(); + + wrapList(entities, list); + + return list; + } + + // ::: wrapper + // + private void wrapList(List found, List output) { + + var builder = new TaxonMapBuilder().addListGroup(true); + + output.addAll(builder.build(getContext(), found)); + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonListArgument.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonListArgument.java new file mode 100644 index 0000000..fe7794e --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonListArgument.java @@ -0,0 +1,40 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxon; + +// app +import io.kumare.iqr.app.action.AppListActionArgument; +// store +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; + +/** + * + * @author afatecha + */ +public class TaxonListArgument extends AppListActionArgument { + + // ::: vars + // + private boolean withTaxa = false; + + // ::: constructors + // + public TaxonListArgument() { + } + + public TaxonListArgument(TaxonEntity entity) { + super(entity); + } + + // ::: fields + // + public boolean isWithTaxa() { + return withTaxa; + } + + public void setWithTaxa(boolean withTaxa) { + this.withTaxa = withTaxa; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonPreloadAction.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonPreloadAction.java new file mode 100644 index 0000000..bb4426f --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonPreloadAction.java @@ -0,0 +1,121 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxon; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.taxonomy.TaxonomyErrors; +// entity +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; +// relations +import io.kumare.iqr.mod.taxonomy.store.taxa.TaxaEntity; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; + +/** + * + * @author afatecha + */ +public class TaxonPreloadAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private Map params = new HashMap<>(); + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifEmpty(getArgument().getAction(), TaxonomyErrors.taxon_preload_empty); + } + + @Override + protected void doAction() { + if(getArgument().getParams() != null) { + params = getArgument().getParams(); + } + + switch (getArgument().getAction()) { + case "find" -> + prepareFind(); + case "list" -> + prepareList(); + case "add" -> + prepareAdd(); + case "edit" -> + prepareEdit(); + } + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: preload + // + private void prepareAdd() { + result.put("taxa", findTaxa()); + } + + private void prepareEdit() { + var entity = findEntity(); + result.put("entity", entity); + result.put("taxa", entity.getTaxa()); + result.put("type", entity.getType()); + result.put("parent", entity.getParent()); + } + + private void prepareList() { + } + + private void prepareFind() { + var entity = findEntity(); + result.put("entity", entity); + result.put("taxa", entity.getTaxa()); + result.put("type", entity.getType()); + result.put("parent", entity.getParent()); + } + + // ::: queries + // + private TaxonEntity findEntity() { + var store = AppModules.taxonomy.getController().getTaxonStore(); + + var id = (String) params.get("id"); + if(id == null && getArgument().getEntity() != null) { + id = getArgument().getEntity().getId(); + } + return store.findById(getContext(), id); + } + + private TaxaEntity findTaxa() { + var store = AppModules.taxonomy.getController().getTaxaStore(); + var key = getArgument().getEntity().getTaxaKey(); + return store.findByKey(getContext(), key); + } + + public List listTaxas() { + var store = AppModules.taxonomy.getController().getTaxaStore(); + + return store.listAll(getContext()); + } + public List listTaxons() { + var store = AppModules.taxonomy.getController().getTaxonStore(); + + return store.listAll(getContext()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonPreloadArgument.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonPreloadArgument.java new file mode 100644 index 0000000..2da7904 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxon/TaxonPreloadArgument.java @@ -0,0 +1,26 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxon; + +/** + * + * @author afatecha + */ +public class TaxonPreloadArgument extends TaxonActionArgument { + + // ::: vars + // + private String action; + + // ::: fields + // + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationActionArgument.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationActionArgument.java new file mode 100644 index 0000000..3856494 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationActionArgument.java @@ -0,0 +1,29 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxonrelation; + +// base +import io.kumare.iqr.app.action.AppEntityActionArgument; +// entity +import io.kumare.iqr.mod.taxonomy.store.taxonrelation.TaxonRelationEntity; + +/** + * + * @author afatecha + */ +public class TaxonRelationActionArgument extends AppEntityActionArgument { + + // ::: constructors + // + public TaxonRelationActionArgument() { + } + + public TaxonRelationActionArgument(TaxonRelationEntity entity) { + super(entity); + } + + // ::: api + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationAddAction.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationAddAction.java new file mode 100644 index 0000000..50e6a27 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationAddAction.java @@ -0,0 +1,127 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxonrelation; + + +// lib +import io.kumare.lib.base.server.spring.action.Actions; +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.taxonomy.TaxonomyErrors; +// entity +import io.kumare.iqr.mod.taxonomy.store.taxonrelation.TaxonRelationEntity; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; + + +/** + * + * @author afatecha + */ +public class TaxonRelationAddAction extends AppAction> { + + // ::: vars + // + private TaxonRelationEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, TaxonomyErrors.taxonrelation_notfound); + + // relations + V.ifNull(model.getSubject(), TaxonomyErrors.taxonrelation_subject_notfound); + V.ifNull(model.getPredicate(), TaxonomyErrors.taxonrelation_predicate_notfound); + V.ifNull(model.getObject(), TaxonomyErrors.taxonrelation_object_notfound); + + // fields + V.ifEmpty(model.getExternalId(), TaxonomyErrors.taxonrelation_externalid_empty); + V.ifEmpty(model.getSpace(), TaxonomyErrors.taxonrelation_space_empty); + V.ifEmpty(model.getLiteral(), TaxonomyErrors.taxonrelation_literal_empty); + // data + //V.ifNull(model.getData(), TaxonomyErrors.taxonrelation_data_notfound); + //V.ifEmpty(model.getData().getNote(), TaxonomyErrors.taxonrelation_data_note_empty); + //V.ifEmpty(model.getData().getAttributes(), TaxonomyErrors.taxonrelation_data_attributes_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + var taxonomy = AppModules.taxonomy.getController(); + + var taxonStore = taxonomy.getTaxonStore(); + + var subject = taxonStore.ensure(getContext(), argModel.getSubject(), TaxonomyErrors.taxonrelation_subject_notfound); + var predicate = taxonStore.ensure(getContext(), argModel.getPredicate(), TaxonomyErrors.taxonrelation_predicate_notfound); + var object = taxonStore.ensure(getContext(), argModel.getObject(), TaxonomyErrors.taxonrelation_object_notfound); + + // model + var model = makeModel(subject, predicate, object); + + // add + entity = saveEntity(model); + + // add others + + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private TaxonRelationEntity makeModel(TaxonEntity subject, TaxonEntity predicate, TaxonEntity object) { + + var argModel = getArgument().getEntity(); + var model = new TaxonRelationEntity(); + + // relations + model.setSubject(subject); + model.setPredicate(predicate); + model.setObject(object); + + // fields + model.setExternalId(argModel.getExternalId()); + model.setSpace(argModel.getSpace()); + model.setLiteral(argModel.getLiteral()); + model.setActive(true); + + + + return model; + } + + // ::: save + // + private TaxonRelationEntity saveEntity(TaxonRelationEntity model) { + + var store = AppModules.taxonomy.getController().getTaxonRelationStore(); + + var saved = store.add(getContext(), model); + getContext().attach(saved.getId(), saved); + return saved; + } + + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationAddArgument.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationAddArgument.java new file mode 100644 index 0000000..e1b074b --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationAddArgument.java @@ -0,0 +1,34 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxonrelation; + + +// app +import io.kumare.iqr.mod.taxonomy.store.taxonrelation.TaxonRelationEntity; + + +/** + * + * @author afatecha + */ +public class TaxonRelationAddArgument extends TaxonRelationActionArgument { + + // ::: vars + // + + + // ::: constructors + // + public TaxonRelationAddArgument() { + } + + public TaxonRelationAddArgument(TaxonRelationEntity entity) { + super(entity); + } + + // ::: fields + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationDeleteAction.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationDeleteAction.java new file mode 100644 index 0000000..fcf105c --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationDeleteAction.java @@ -0,0 +1,59 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxonrelation; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.taxonomy.TaxonomyErrors; +// entity +import io.kumare.iqr.mod.taxonomy.store.taxonrelation.TaxonRelationEntity; + +/** + * + * @author afatecha + */ +public class TaxonRelationDeleteAction extends AppAction> { + + // ::: vars + // + private TaxonRelationEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), TaxonomyErrors.taxonrelation_notfound); + V.ifNull(getArgument().getEntity().getId(), TaxonomyErrors.taxonrelation_notfound); + } + + @Override + protected void doAction() { + + var argModel = getArgument().getEntity(); + + deleteEntity(argModel); + } + + @Override + protected void setResultOnly() { + } + + // ::: delete + // + private void deleteEntity(TaxonRelationEntity model) { + + var store = AppModules.taxonomy.getController().getTaxonRelationStore(); + + store.deleteById(getContext(), model.getId()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationEditAction.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationEditAction.java new file mode 100644 index 0000000..dd68fc6 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationEditAction.java @@ -0,0 +1,101 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxonrelation; + +// lib +import io.kumare.lib.v.V; +// app +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppEntityActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.taxonomy.TaxonomyErrors; +// entity +import io.kumare.iqr.mod.taxonomy.store.taxonrelation.TaxonRelationEntity; + +/** + * + * @author afatecha + */ +public class TaxonRelationEditAction extends AppAction> { + + // ::: vars + // + private TaxonRelationEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + + // entity + var model = getArgument().getEntity(); + V.ifNull(model, TaxonomyErrors.taxonrelation_notfound); + + // fields + V.ifEmpty(model.getExternalId(), TaxonomyErrors.taxonrelation_externalid_empty); + V.ifEmpty(model.getSpace(), TaxonomyErrors.taxonrelation_space_empty); + V.ifEmpty(model.getLiteral(), TaxonomyErrors.taxonrelation_literal_empty); + // data + //V.ifNull(model.getData(), TaxonomyErrors.taxonrelation_data_notfound); + //V.ifEmpty(model.getData().getNote(), TaxonomyErrors.taxonrelation_data_note_empty); + //V.ifEmpty(model.getData().getAttributes(), TaxonomyErrors.taxonrelation_data_attributes_empty); + } + + @Override + protected void doAction() { + // arguments + var argModel = getArgument().getEntity(); + + // controllers + + var taxonomy = AppModules.taxonomy.getController(); + var taxonRelationStore = taxonomy.getTaxonRelationStore(); + + // edit + entity = taxonRelationStore.ensure(getContext(), argModel, TaxonomyErrors.taxonrelation_notfound); + + editEntity(); + + entity = saveEntity(); + + // dispatchEvents + } + + @Override + protected void setResultOnly() { + var result = new AppEntityActionResult(); + result.setEntity(entity); + setResult(result); + } + + // ::: model + // + private void editEntity() { + + var model = getArgument().getEntity(); + + // fields + entity.setExternalId(V.firstNotEmpty(model.getExternalId(), entity.getExternalId())); + entity.setSpace(V.firstNotEmpty(model.getSpace(), entity.getSpace())); + entity.setLiteral(V.firstNotEmpty(model.getLiteral(), entity.getLiteral())); + + + } + + // ::: save + // + private TaxonRelationEntity saveEntity() { + + var store = AppModules.taxonomy.getController().getTaxonRelationStore(); + + var saved = store.edit(getContext(), entity); + getContext().attach(saved.getId(), saved); + return saved; + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationEditArgument.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationEditArgument.java new file mode 100644 index 0000000..cbc62c2 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationEditArgument.java @@ -0,0 +1,32 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxonrelation; + +// app +import io.kumare.iqr.mod.taxonomy.store.taxonrelation.TaxonRelationEntity; + +/** + * + * @author afatecha + */ +public class TaxonRelationEditArgument extends TaxonRelationActionArgument { + + // ::: vars + // + + + // ::: constructors + // + public TaxonRelationEditArgument() { + } + + public TaxonRelationEditArgument(TaxonRelationEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationEnableAction.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationEnableAction.java new file mode 100644 index 0000000..1a7a050 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationEnableAction.java @@ -0,0 +1,60 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxonrelation; + +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.action.AppActionResult; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.taxonomy.TaxonomyErrors; +// entity +import io.kumare.iqr.mod.taxonomy.store.taxonrelation.TaxonRelationEntity; + + +/** + * + * @author afatecha + */ +public class TaxonRelationEnableAction extends AppAction { + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), TaxonomyErrors.taxonrelation_notfound); + V.ifNull(getArgument().getEntity().getId(), TaxonomyErrors.taxonrelation_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + + enableEntity(model); + } + + @Override + protected void setResultOnly() { + } + + // ::: enable + // + private void enableEntity(TaxonRelationEntity model) { + + var store = AppModules.taxonomy.getController().getTaxonRelationStore(); + + if (getArgument().getEntity().isActive()) { + store.enableById(getContext(), model.getId()); + } else { + store.disableById(getContext(), model.getId()); + } + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationFindAction.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationFindAction.java new file mode 100644 index 0000000..1aa4a43 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationFindAction.java @@ -0,0 +1,64 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxonrelation; + +// java +import java.util.HashMap; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.taxonomy.TaxonomyErrors; +// entity +import io.kumare.iqr.mod.taxonomy.store.taxonrelation.TaxonRelationEntity; + + +/** + * + * @author afatecha + */ +public class TaxonRelationFindAction extends AppAction { + + // ::: vars + // + private TaxonRelationEntity entity; + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifNull(getArgument().getEntity(), TaxonomyErrors.taxonrelation_notfound); + V.ifNull(getArgument().getEntity().getId(), TaxonomyErrors.taxonrelation_notfound); + } + + @Override + protected void doAction() { + + var model = getArgument().getEntity(); + entity = findEntity(model); + } + + @Override + protected void setResultOnly() { + var result = new HashMap(); + result.put("entity", entity); + setResult(result); + } + + // ::: find + // + private TaxonRelationEntity findEntity(TaxonRelationEntity model) { + + var store = AppModules.taxonomy.getController().getTaxonRelationStore(); + return store.findById(getContext(), model.getId()); + } + + +} + diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationListAction.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationListAction.java new file mode 100644 index 0000000..e915fe9 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationListAction.java @@ -0,0 +1,150 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxonrelation; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.LinkedList; +import java.util.Map; +// spring +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// entity +import io.kumare.iqr.mod.taxonomy.store.taxonrelation.TaxonRelationEntity; +import io.kumare.iqr.mod.taxonomy.store.taxonrelation.TaxonRelationMapBuilder; + + +/** + * + * @author afatecha + */ +public class TaxonRelationListAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private final List entities = new LinkedList<>(); + + // ::: public api + // + public List getEntities() { + return entities; + } + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + } + + @Override + protected void doAction() { + + result.put("pageable", getArgument().isPageable()); + result.put("wrapped", getArgument().isWrapped()); + + if (getArgument().isPageable()) { + + var page = makePage(); + entities.addAll(page.toList()); + + if (getArgument().isWrapped()) { + result.put("page", makeWrappedPage(page)); + } else { + result.put("page", page); + } + + } else { + + var list = makeList(); + entities.addAll(list); + + if (getArgument().isWrapped()) { + result.put("list", makeWrappedList()); + } else { + result.put("list", list); + } + } + + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: page + // + private Page makePage() { + + var page = getArgument().getPageNumber(); + var size = getArgument().getPageSize(); + //var sort = getArgument().getSort(); + + var pageable = PageRequest.of(page, size); + + var store = AppModules.taxonomy.getController().getTaxonRelationStore(); + return store.getRepository().findAll(pageable); + } + + // ::: wrapped page + // + private Map makeWrappedPage(Page found) { + + var page = new HashMap(); + var content = new LinkedList(); + + wrapList(entities, content); + + page.put("size", found.getSize()); + page.put("number", found.getNumber()); + page.put("totalElements", found.getTotalElements()); + page.put("totalPages", found.getTotalPages()); + page.put("content", content); + + return page; + } + + + // ::: list + // + + private List makeList() { + + var store = AppModules.taxonomy.getController().getTaxonRelationStore(); + + return store.listAll(getContext()); + } + + // ::: wrapped list + private List makeWrappedList() { + var list = new LinkedList(); + + wrapList(entities, list); + + return list; + } + + // ::: wrapper + // + private void wrapList(List found, List output) { + + var builder = new TaxonRelationMapBuilder().addListGroup(); + builder.getSubjectBuilder().addMainGroup(); + builder.getPredicateBuilder().addMainGroup(); + builder.getObjectBuilder().addMainGroup(); + + output.addAll(builder.build(getContext(), found)); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationListArgument.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationListArgument.java new file mode 100644 index 0000000..1831829 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationListArgument.java @@ -0,0 +1,33 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxonrelation; + +// app +import io.kumare.iqr.app.action.AppListActionArgument; +// store +import io.kumare.iqr.mod.taxonomy.store.taxonrelation.TaxonRelationEntity; + +/** + * + * @author afatecha + */ +public class TaxonRelationListArgument extends AppListActionArgument { + + // ::: vars + // + + // ::: constructors + // + public TaxonRelationListArgument() { + } + + public TaxonRelationListArgument(TaxonRelationEntity entity) { + super(entity); + } + + + // ::: fields + // + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationPreloadAction.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationPreloadAction.java new file mode 100644 index 0000000..307b439 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationPreloadAction.java @@ -0,0 +1,109 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxonrelation; + +// java +import java.util.HashMap; +import java.util.List; +import java.util.Map; +// lib +import io.kumare.lib.v.V; +// base +import io.kumare.iqr.app.AppErrors; +import io.kumare.iqr.app.action.AppAction; +import io.kumare.iqr.app.module.AppModules; +// module +import io.kumare.iqr.mod.taxonomy.TaxonomyErrors; +// entity +import io.kumare.iqr.mod.taxonomy.store.taxonrelation.TaxonRelationEntity; +// relations +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; + +/** + * + * @author afatecha + */ +public class TaxonRelationPreloadAction extends AppAction { + + // ::: vars + // + private final Map result = new HashMap(); + private Map params = new HashMap<>(); + + // ::: protected api + // + @Override + protected void checkArgument() { + V.ifNull(getArgument(), AppErrors.action_arg_notfound); + V.ifEmpty(getArgument().getAction(), TaxonomyErrors.taxonrelation_preload_empty); + } + + @Override + protected void doAction() { + if(getArgument().getParams() != null) { + params = getArgument().getParams(); + } + + switch (getArgument().getAction()) { + case "find" -> + prepareFind(); + case "list" -> + prepareList(); + case "add" -> + prepareAdd(); + case "edit" -> + prepareEdit(); + } + } + + @Override + protected void setResultOnly() { + setResult(result); + } + + // ::: preload + // + private void prepareAdd() { + result.put("taxons", listTaxons()); + } + + private void prepareEdit() { + var entity = findEntity(); + result.put("entity", entity); + result.put("subject", entity.getSubject()); + result.put("predicate", entity.getPredicate()); + result.put("object", entity.getObject()); + } + + private void prepareList() { + } + + private void prepareFind() { + var entity = findEntity(); + result.put("entity", entity); + result.put("subject", entity.getSubject()); + result.put("predicate", entity.getPredicate()); + result.put("object", entity.getObject()); + } + + // ::: queries + // + private TaxonRelationEntity findEntity() { + var store = AppModules.taxonomy.getController().getTaxonRelationStore(); + + var id = (String) params.get("id"); + if(id == null && getArgument().getEntity() != null) { + id = getArgument().getEntity().getId(); + } + return store.findById(getContext(), id); + } + + public List listTaxons() { + var store = AppModules.taxonomy.getController().getTaxonStore(); + + return store.listAll(getContext()); + } + +} + diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationPreloadArgument.java b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationPreloadArgument.java new file mode 100644 index 0000000..df0a2d5 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/action/taxonrelation/TaxonRelationPreloadArgument.java @@ -0,0 +1,26 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.action.taxonrelation; + +/** + * + * @author afatecha + */ +public class TaxonRelationPreloadArgument extends TaxonRelationActionArgument { + + // ::: vars + // + private String action; + + // ::: fields + // + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/endpoint/rest/AbstractTaxaRest.java b/src/main/java/io/kumare/iqr/mod/taxonomy/endpoint/rest/AbstractTaxaRest.java new file mode 100644 index 0000000..5ded879 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/endpoint/rest/AbstractTaxaRest.java @@ -0,0 +1,262 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.endpoint.rest; + +// java +import com.google.gson.Gson; +import java.util.Map; +// openapi +import io.swagger.v3.oas.annotations.*; +import io.swagger.v3.oas.annotations.media.*; +import io.swagger.v3.oas.annotations.responses.*; +// spring +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +// base +import io.kumare.lib.app.api.operation.TransactionType; +import io.kumare.lib.app.api.security.PermissionReference; +// app +import io.kumare.iqr.app.endpoint.rest.AppEndpointRest; +import io.kumare.iqr.app.action.*; +// module +import io.kumare.iqr.mod.taxonomy.TaxonomyPermissions; +import io.kumare.iqr.mod.taxonomy.store.taxa.TaxaEntity; +import io.kumare.iqr.mod.taxonomy.action.taxa.*; +import org.springframework.web.multipart.MultipartFile; + +/** + * + * @author afatecha + */ +public abstract class AbstractTaxaRest extends AppEndpointRest { + + // ::: DEFAULT PERMISSIONS + // + protected PermissionReference getPermission(String action, String ref, Object extra) { + switch (action) { + case null -> { + return null; + } + case "add" -> { + return TaxonomyPermissions.taxa_worker.toReference(ref); + } + case "edit" -> { + return TaxonomyPermissions.taxa_worker.toReference(ref); + } + case "enable" -> { + return TaxonomyPermissions.taxa_manager.toReference(ref); + } + case "disable" -> { + return TaxonomyPermissions.taxa_manager.toReference(ref); + } + case "delete" -> { + return TaxonomyPermissions.taxa_manager.toReference(ref); + } + case "find" -> { + return TaxonomyPermissions.taxa_viewer.toReference(ref); + } + case "list" -> { + return TaxonomyPermissions.taxa_viewer.toReference(ref); + } + default -> { + return null; + } + } + } + + // ::: ADD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "taxa add operation", description = "") + // + @PostMapping + public ResponseEntity add(@RequestBody TaxaAddArgument arg) { + + var permission = getPermission("add", null, arg); + return handle(new TaxaAddAction(), arg, permission, TransactionType.service); + } + + // ::: EDIT + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "taxa edit operation", description = "") + // + @PutMapping("/{id}") + public ResponseEntity edit(@PathVariable("id") String id, + @RequestBody TaxaEditArgument arg) { + + arg.getEntity().id(id); + + var permission = getPermission("edit", id, arg); + return handle(new TaxaEditAction(), arg, permission, TransactionType.service); + } + + // ::: FIND + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "taxa find operation", description = "") + // + @GetMapping("/{id}") + public ResponseEntity find(@PathVariable("id") String id, + @ModelAttribute TaxaActionArgument arg) { + + arg = arg == null ? new TaxaActionArgument() : arg; + + arg.entity(new TaxaEntity(id)); + + var permission = getPermission("find", id, arg); + return handle(new TaxaFindAction(), arg, permission); + } + + // ::: ENABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "taxa enable operation", description = "") + // + @PutMapping("/{id}/enable") + public ResponseEntity enable(@PathVariable("id") String id) { + + var arg = new TaxaActionArgument(); + arg.setEntity(new TaxaEntity(id)); + arg.getEntity().setActive(true); + + var permission = getPermission("disable", id, arg); + return handle(new TaxaEnableAction(), arg, permission, TransactionType.service); + } + */ + // ::: DISABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "taxa disable operation", description = "") + // + @PutMapping("/{id}/disable") + public ResponseEntity disable(@PathVariable("id") String id) { + + var arg = new TaxaActionArgument(); + arg.setEntity(new TaxaEntity(id)); + arg.getEntity().setActive(false); + + var permission = getPermission("disable", id, arg); + return handle(new TaxaEnableAction(), arg, permission, TransactionType.service); + } + */ + // ::: LIST + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "taxa list operation", description = "") + // + @GetMapping + public ResponseEntity list(@ModelAttribute TaxaListArgument arg) { + + arg = arg == null ? new TaxaListArgument() : arg; + + var permission = getPermission("list", null, arg); + return handle(new TaxaListAction(), arg, permission); + } + + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "taxa export operation", description = "") + // + @GetMapping("/export") + public ResponseEntity export(@ModelAttribute TaxaListArgument arg) { + + arg = arg == null ? new TaxaListArgument() : arg; + + var permission = getPermission("list", null, arg); + return handle(new TaxaExportAction(), arg, permission); + } + + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "taxa import operation", description = "") + // + @PostMapping("/import") + public ResponseEntity loadImport(@RequestParam("message") String message, + @RequestParam("file") MultipartFile file) { + + try { + var arg = new Gson().fromJson(message, TaxaImportArgument.class); + arg.bytes(file.getBytes()); + + var permission = getPermission("manage", null, arg); + return handle(new TaxaImportAction(), arg, permission); + + } catch (Throwable t) { + return makeResponseError(t); + } + }*/ + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "taxa import operation", description = "") + // + @PostMapping("/import") + public ResponseEntity loadImport(@RequestBody TaxaImportArgument arg) { + + var permission = getPermission("manage", null, arg); + return handle(new TaxaImportAction(), arg, permission, TransactionType.service); + } + + // ::: DELETE + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "taxa delete operation", description = "") + // + @DeleteMapping("/{id}") + public ResponseEntity delete(@PathVariable("id") String id) { + + var arg = new TaxaActionArgument(); + + arg.setEntity(new TaxaEntity(id)); + + var permission = getPermission("delete", id, arg); + return handle(new TaxaDeleteAction(), arg, permission, TransactionType.service); + } + + // ::: PRELOAD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "taxa preload operation", description = "") + // + @PostMapping("/preload") + public ResponseEntity preload(@RequestBody TaxaPreloadArgument arg) { + + var permission = getPermission(arg.getAction(), null, arg); + return handle(new TaxaPreloadAction(), arg, permission); + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/endpoint/rest/AbstractTaxonRelationRest.java b/src/main/java/io/kumare/iqr/mod/taxonomy/endpoint/rest/AbstractTaxonRelationRest.java new file mode 100644 index 0000000..3c27167 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/endpoint/rest/AbstractTaxonRelationRest.java @@ -0,0 +1,214 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.endpoint.rest; + +// java +import java.util.Map; +// openapi +import io.swagger.v3.oas.annotations.*; +import io.swagger.v3.oas.annotations.media.*; +import io.swagger.v3.oas.annotations.responses.*; +// spring +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +// base +import io.kumare.lib.app.api.operation.TransactionType; +import io.kumare.lib.app.api.security.PermissionReference; +// app +import io.kumare.iqr.app.endpoint.rest.AppEndpointRest; +import io.kumare.iqr.app.action.*; +// module +import io.kumare.iqr.mod.taxonomy.TaxonomyPermissions; +import io.kumare.iqr.mod.taxonomy.store.taxonrelation.TaxonRelationEntity; +import io.kumare.iqr.mod.taxonomy.action.taxonrelation.*; + +/** +* +* @author afatecha +*/ +public abstract class AbstractTaxonRelationRest extends AppEndpointRest { + + // ::: DEFAULT PERMISSIONS + // + protected PermissionReference getPermission(String action, String ref, Object extra) { + switch (action) { + case null -> { + return null; + } + case "add" -> { + return TaxonomyPermissions.taxon_relation_worker.toReference(ref); + } + case "edit" -> { + return TaxonomyPermissions.taxon_relation_worker.toReference(ref); + } + case "enable" -> { + return TaxonomyPermissions.taxon_relation_manager.toReference(ref); + } + case "disable" -> { + return TaxonomyPermissions.taxon_relation_manager.toReference(ref); + } + case "delete" -> { + return TaxonomyPermissions.taxon_relation_manager.toReference(ref); + } + case "find" -> { + return TaxonomyPermissions.taxon_relation_viewer.toReference(ref); + } + case "list" -> { + return TaxonomyPermissions.taxon_relation_viewer.toReference(ref); + } + default -> { + return null; + } + } + } + + + // ::: ADD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "taxon relation add operation", description = "") + // + @PostMapping + public ResponseEntity add(@RequestBody TaxonRelationAddArgument arg) { + + var permission = getPermission("add", null, arg); + return handle(new TaxonRelationAddAction(), arg, permission, TransactionType.service); + } + + // ::: EDIT + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "taxon relation edit operation", description = "") + // + @PutMapping("/{id}") + public ResponseEntity edit(@PathVariable("id") String id, + @RequestBody TaxonRelationEditArgument arg) { + + arg.getEntity().id(id); + + var permission = getPermission("edit", id, arg); + return handle(new TaxonRelationEditAction(), arg, permission, TransactionType.service); + } + + // ::: FIND + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "taxon relation find operation", description = "") + // + @GetMapping("/{id}") + public ResponseEntity find(@PathVariable("id") String id, + @ModelAttribute TaxonRelationActionArgument arg) { + + + arg = arg == null ? new TaxonRelationActionArgument() : arg; + + arg.entity(new TaxonRelationEntity(id)); + + var permission = getPermission("find", id, arg); + return handle(new TaxonRelationFindAction(), arg, permission); + } + + // ::: ENABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "taxon relation enable operation", description = "") + // + @PutMapping("/{id}/enable") + public ResponseEntity enable(@PathVariable("id") String id) { + + var arg = new TaxonRelationActionArgument(); + arg.setEntity(new TaxonRelationEntity(id)); + arg.getEntity().setActive(true); + + var permission = getPermission("disable", id, arg); + return handle(new TaxonRelationEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: DISABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "taxon relation disable operation", description = "") + // + @PutMapping("/{id}/disable") + public ResponseEntity disable(@PathVariable("id") String id) { + + var arg = new TaxonRelationActionArgument(); + arg.setEntity(new TaxonRelationEntity(id)); + arg.getEntity().setActive(false); + + var permission = getPermission("disable", id, arg); + return handle(new TaxonRelationEnableAction(), arg, permission, TransactionType.service); + } + */ + + // ::: LIST + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "taxon relation list operation", description = "") + // + @GetMapping + public ResponseEntity list(@ModelAttribute TaxonRelationListArgument arg) { + + arg = arg == null ? new TaxonRelationListArgument() : arg; + + var permission = getPermission("list", null, arg); + return handle(new TaxonRelationListAction(), arg, permission); + } + + // ::: DELETE + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "taxon relation delete operation", description = "") + // + @DeleteMapping("/{id}") + public ResponseEntity delete(@PathVariable("id") String id) { + + var arg = new TaxonRelationActionArgument(); + + arg.setEntity(new TaxonRelationEntity(id)); + + var permission = getPermission("delete", id, arg); + return handle(new TaxonRelationDeleteAction(), arg, permission, TransactionType.service); + } + + // ::: PRELOAD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "taxon relation preload operation", description = "") + // + @PostMapping("/preload") + public ResponseEntity preload(@RequestBody TaxonRelationPreloadArgument arg) { + + var permission = getPermission(arg.getAction(), null, arg); + return handle(new TaxonRelationPreloadAction(), arg, permission); + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/endpoint/rest/AbstractTaxonRest.java b/src/main/java/io/kumare/iqr/mod/taxonomy/endpoint/rest/AbstractTaxonRest.java new file mode 100644 index 0000000..822e794 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/endpoint/rest/AbstractTaxonRest.java @@ -0,0 +1,251 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.endpoint.rest; + +// java +import java.util.Map; +// openapi +import io.swagger.v3.oas.annotations.*; +import io.swagger.v3.oas.annotations.media.*; +import io.swagger.v3.oas.annotations.responses.*; +// spring +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +// base +import io.kumare.lib.app.api.operation.TransactionType; +import io.kumare.lib.app.api.security.PermissionReference; +// app +import io.kumare.iqr.app.endpoint.rest.AppEndpointRest; +import io.kumare.iqr.app.action.*; +// module +import io.kumare.iqr.mod.taxonomy.TaxonomyPermissions; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; +import io.kumare.iqr.mod.taxonomy.action.taxon.*; + +/** + * + * @author afatecha + */ +public abstract class AbstractTaxonRest extends AppEndpointRest { + + // ::: DEFAULT PERMISSIONS + // + protected PermissionReference getPermission(String action, String ref, Object extra) { + switch (action) { + case null -> { + return null; + } + case "add" -> { + return TaxonomyPermissions.taxon_worker.toReference(ref); + } + case "edit" -> { + return TaxonomyPermissions.taxon_worker.toReference(ref); + } + case "set-as-default" -> { + return TaxonomyPermissions.taxon_manager.toReference(ref); + } + case "enable" -> { + return TaxonomyPermissions.taxon_manager.toReference(ref); + } + case "disable" -> { + return TaxonomyPermissions.taxon_manager.toReference(ref); + } + case "delete" -> { + return TaxonomyPermissions.taxon_manager.toReference(ref); + } + case "find" -> { + return TaxonomyPermissions.taxon_viewer.toReference(ref); + } + case "list" -> { + return TaxonomyPermissions.taxon_viewer.toReference(ref); + } + default -> { + return null; + } + } + } + + // ::: ADD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "taxon add operation", description = "") + // + @PostMapping + public ResponseEntity add(@PathVariable("taxaKey") String taxaKey, + @RequestBody TaxonAddArgument arg) { + + arg.getEntity().taxaKey(taxaKey); + + var permission = getPermission("add", taxaKey, arg); + return handle(new TaxonAddAction(), arg, permission, TransactionType.service); + } + + // ::: EDIT + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "taxon edit operation", description = "") + // + @PutMapping("/{id}") + public ResponseEntity edit(@PathVariable("taxaKey") String taxaKey, + @PathVariable("id") String id, + @RequestBody TaxonEditArgument arg) { + + arg.getEntity().taxaKey(taxaKey).id(id); + + var permission = getPermission("edit", taxaKey, arg); + return handle(new TaxonEditAction(), arg, permission, TransactionType.service); + } + + // ::: SET-AS-DEFAULT + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppEntityActionResult.class))) + }) + @Operation(summary = "taxon edit operation", description = "") + // + @PostMapping("/{id}/set-as-default") + public ResponseEntity setAsDefault(@PathVariable("taxaKey") String taxaKey, + @PathVariable("id") String id, + @RequestBody TaxonEditArgument arg) { + + arg.getEntity().taxaKey(taxaKey).id(id); + + var permission = getPermission("set-as-default", taxaKey, arg); + return handle(new TaxonSetAsDefaultAction(), arg, permission, TransactionType.service); + }*/ + + // ::: FIND + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "taxon find operation", description = "") + // + @GetMapping("/{id}") + public ResponseEntity find(@PathVariable("taxaKey") String taxaKey, + @PathVariable("id") String id, + @ModelAttribute TaxonActionArgument arg) { + + arg = arg == null ? new TaxonActionArgument() : arg; + + arg.entity(new TaxonEntity(id).taxaKey(taxaKey)); + + var permission = getPermission("find", taxaKey, arg); + return handle(new TaxonFindAction(), arg, permission); + } + + // ::: ENABLE + // + /* + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "taxon enable operation", description = "") + // + @PutMapping("/{id}/enable") + public ResponseEntity enable(@PathVariable("taxaKey") String taxaKey, + @PathVariable("id") String id) { + + var arg = new TaxonActionArgument(); + arg.setEntity(new TaxonEntity(id).taxaKey(taxaKey)); + arg.getEntity().setActive(true); + + var permission = getPermission("disable", taxaKey, arg); + return handle(new TaxonEnableAction(), arg, permission, TransactionType.service); + } + + // ::: DISABLE + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "taxon disable operation", description = "") + // + @PutMapping("/{id}/disable") + public ResponseEntity disable(@PathVariable("taxaKey") String taxaKey, + @PathVariable("id") String id) { + + var arg = new TaxonActionArgument(); + arg.setEntity(new TaxonEntity(id).taxaKey(taxaKey)); + arg.getEntity().setActive(false); + + var permission = getPermission("disable", taxaKey, arg); + return handle(new TaxonEnableAction(), arg, permission, TransactionType.service); + }*/ + + // ::: LIST + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "taxon list operation", description = "") + // + @GetMapping + public ResponseEntity list(@PathVariable("taxaKey") String taxaKey, + @ModelAttribute TaxonListArgument arg) { + + arg = arg == null ? new TaxonListArgument() : arg; + if (arg.getEntity() == null) { + arg.entity(new TaxonEntity()); + } + arg.getEntity().taxaKey(taxaKey); + + var permission = getPermission("list", taxaKey, arg); + return handle(new TaxonListAction(), arg, permission); + } + + // ::: DELETE + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AppActionResult.class))) + }) + @Operation(summary = "taxon delete operation", description = "") + // + @DeleteMapping("/{id}") + public ResponseEntity delete(@PathVariable("taxaKey") String taxaKey, + @PathVariable("id") String id) { + + var arg = new TaxonActionArgument(); + + arg.setEntity(new TaxonEntity(id).taxaKey(taxaKey)); + + var permission = getPermission("delete", taxaKey, arg); + return handle(new TaxonDeleteAction(), arg, permission, TransactionType.service); + } + + // ::: PRELOAD + // + @ApiResponses(value = { + @ApiResponse(content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Map.class))) + }) + @Operation(summary = "taxon preload operation", description = "") + // + @PostMapping("/preload") + public ResponseEntity preload(@PathVariable("taxaKey") String taxaKey, + @RequestBody TaxonPreloadArgument arg) { + + if (arg.getEntity() == null) { + arg.entity(new TaxonEntity()); + } + arg.getEntity().taxaKey(taxaKey); + + var permission = getPermission(arg.getAction(), taxaKey, arg); + return handle(new TaxonPreloadAction(), arg, permission); + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/endpoint/rest/TaxaRest.java b/src/main/java/io/kumare/iqr/mod/taxonomy/endpoint/rest/TaxaRest.java new file mode 100644 index 0000000..4037c65 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/endpoint/rest/TaxaRest.java @@ -0,0 +1,24 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.endpoint.rest; + +// java +import io.swagger.v3.oas.annotations.tags.*; +// spring +import org.springframework.web.bind.annotation.*; + +/** +* +* @author afatecha +*/ + +// openapi +@Tag(name = "taxa rest endpoint") +// +@RestController +@RequestMapping("/taxonomy/taxas") +public class TaxaRest extends AbstractTaxaRest { + + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/endpoint/rest/TaxonRelationRest.java b/src/main/java/io/kumare/iqr/mod/taxonomy/endpoint/rest/TaxonRelationRest.java new file mode 100644 index 0000000..0440348 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/endpoint/rest/TaxonRelationRest.java @@ -0,0 +1,24 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.endpoint.rest; + +// java +import io.swagger.v3.oas.annotations.tags.*; +// spring +import org.springframework.web.bind.annotation.*; + +/** +* +* @author afatecha +*/ + +// openapi +//@Tag(name = "taxon relation rest endpoint") +// +//@RestController +//@RequestMapping("/taxonomy/taxon-relations") +public class TaxonRelationRest extends AbstractTaxonRelationRest { + + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/endpoint/rest/TaxonRest.java b/src/main/java/io/kumare/iqr/mod/taxonomy/endpoint/rest/TaxonRest.java new file mode 100644 index 0000000..58a58a4 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/endpoint/rest/TaxonRest.java @@ -0,0 +1,24 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.endpoint.rest; + +// java +import io.swagger.v3.oas.annotations.tags.*; +// spring +import org.springframework.web.bind.annotation.*; + +/** +* +* @author afatecha +*/ + +// openapi +@Tag(name = "taxon rest endpoint") +// +@RestController +@RequestMapping("/taxonomy/taxas/{taxaKey}/taxons") +public class TaxonRest extends AbstractTaxonRest { + + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/store/TaxonomyEntities.java b/src/main/java/io/kumare/iqr/mod/taxonomy/store/TaxonomyEntities.java new file mode 100644 index 0000000..650e0e0 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/store/TaxonomyEntities.java @@ -0,0 +1,105 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.store; + +// base +// base +import io.kumare.lib.app.api.module.ServiceModule; +import io.kumare.lib.app.api.store.EntityStore; +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app +import io.kumare.iqr.app.AppEngine; +import io.kumare.iqr.app.module.AppModules; +import io.kumare.iqr.mod.taxonomy.store.taxa.TaxaEntity; +import io.kumare.iqr.mod.taxonomy.store.taxa.TaxaStore; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonStore; +import io.kumare.iqr.mod.taxonomy.store.taxonrelation.TaxonRelationEntity; +import io.kumare.iqr.mod.taxonomy.store.taxonrelation.TaxonRelationStore; + + +/** + * + * @author afatecha + */ +public enum TaxonomyEntities implements EntityDescriptor { + + taxa(TaxaEntity.class, TaxaStore.class), + taxon(TaxonEntity.class, TaxonStore.class), + taxonRelation(TaxonRelationEntity.class, TaxonRelationStore.class); + + // ::: vars + // + private final Class entityClass; + private final Class storeClass; + + // ::: constructor + // + TaxonomyEntities(Class entityClass, Class storeClass) { + this.entityClass = entityClass; + this.storeClass = storeClass; + } + + // ::: entity descriptor api + // + @Override + public String getName() { + return name(); + } + + @Override + public ServiceModule getModule() { + return AppModules.taxonomy; + } + + @Override + public Class getEntityClass() { + return entityClass; + } + + @Override + public Class getStoreClass() { + return storeClass; + } + + @Override + public EntityStore getStore() { + return (EntityStore) AppEngine.getEngine().getInnerContext().getBean(storeClass); + } + + // ::: statics + // + public static boolean hasDescriptor(String name) { + try { + var value = valueOf(name); + return value != null; + + } catch (Throwable t) { + return false; + } + } + + public static EntityDescriptor descriptorOf(String name) { + try { + return valueOf(name); + + } catch (Throwable t) { + return null; + } + } + + public static EntityDescriptor descriptorOf(Class entityClass) { + try { + for (var i : values()) { + if (i.entityClass == entityClass) { + return i; + } + } + + } catch (Throwable t) { + } + + return null; + } +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxa/TaxaData.java b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxa/TaxaData.java new file mode 100644 index 0000000..6354030 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxa/TaxaData.java @@ -0,0 +1,48 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.store.taxa; + +// base +import io.kumare.iqr.app.store.AppExtendedEntityData; +// imports +import java.util.Map; + +public class TaxaData extends AppExtendedEntityData { + + // ::: vars + // + private Map schema; + private Map attributes; + + // ::: fields + // + public Map getSchema() { + return schema; + } + + public void setSchema(Map schema) { + this.schema = schema; + } + + public Map getAttributes() { + return attributes; + } + + public void setAttributes(Map attributes) { + this.attributes = attributes; + } + + // ::: fluent + // + public TaxaData schema(Map schema) { + setSchema(schema); + return this; + } + + public TaxaData attributes(Map attributes) { + setAttributes(attributes); + return this; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxa/TaxaEntity.java b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxa/TaxaEntity.java new file mode 100644 index 0000000..12aa3df --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxa/TaxaEntity.java @@ -0,0 +1,158 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.store.taxa; + +// jakarta +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.Index; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +// base +import io.kumare.lib.app.api.store.*; +import io.kumare.iqr.app.store.*; +// imports + +// relations + + +// annotations +@Entity +@Table( + name = "taxa", + indexes = { + @Index(name = "idx_taxa_external_id", columnList = "externalId"), + @Index(name = "idx_taxa_entity_key", columnList = "entityKey"), + @Index(name = "idx_taxa_space", columnList = "space"), + @Index(name = "idx_taxa_model_type", columnList = "modelType"), + @Index(name = "idx_taxa_custom", columnList = "custom"), + @Index(name = "idx_taxa_name", columnList = "name"), + @Index(name = "idx_taxa_description", columnList = "description") + } +) +public class TaxaEntity extends AppExtendedEntity implements SupportedEntityKey { + + // ::: vars + // + private String externalId; + private String entityKey; + private String space; + private String modelType; + private boolean custom; + private String name; + private String description; + // relations + + + // ::: constructors + // + public TaxaEntity() { + } + + public TaxaEntity(String id) { + super(id); + } + + // ::: fields + // + public String getExternalId() { + return externalId; + } + + public void setExternalId(String externalId) { + this.externalId = externalId; + } + + public String getEntityKey() { + return entityKey; + } + + public void setEntityKey(String entityKey) { + this.entityKey = entityKey; + } + + public String getSpace() { + return space; + } + + public void setSpace(String space) { + this.space = space; + } + + public String getModelType() { + return modelType; + } + + public void setModelType(String modelType) { + this.modelType = modelType; + } + + public boolean isCustom() { + return custom; + } + + public void setCustom(boolean custom) { + this.custom = custom; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + // relations + + + // ::: fluent + // + public TaxaEntity externalId(String externalId) { + setExternalId(externalId); + return this; + } + + public TaxaEntity entityKey(String entityKey) { + setEntityKey(entityKey); + return this; + } + + public TaxaEntity space(String space) { + setSpace(space); + return this; + } + + public TaxaEntity modelType(String modelType) { + setModelType(modelType); + return this; + } + + public TaxaEntity custom(boolean custom) { + setCustom(custom); + return this; + } + + public TaxaEntity name(String name) { + setName(name); + return this; + } + + public TaxaEntity description(String description) { + setDescription(description); + return this; + } + + // relations + + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxa/TaxaFields.java b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxa/TaxaFields.java new file mode 100644 index 0000000..85a0b30 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxa/TaxaFields.java @@ -0,0 +1,159 @@ +/* + */ +package io.kumare.iqr.mod.taxonomy.store.taxa; + +// java +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +// base +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app + + +/** + * + * @author afatecha + */ +public enum TaxaFields implements EntityFieldDescriptor { + + id(MAIN, FIND, LIST), + externalId(MAIN, FIND, LIST), + entityKey(MAIN, FIND, LIST), + space(MAIN, FIND, LIST), + modelType(MAIN, FIND, LIST), + custom(MAIN, FIND, LIST), + name(MAIN, FIND, LIST), + description(MAIN, FIND, LIST), + data(MAIN, FIND, LIST), + active(MAIN, FIND, LIST), + inserted(AUDIT, FIND, LIST), + inserter(AUDIT, FIND, LIST), + modified(AUDIT, FIND), + modifier(AUDIT, FIND), + deleted(AUDIT), + removed(AUDIT), + remover(AUDIT); + + // ::: vars + // + private final boolean relation; + private final EntityDescriptor entityDescriptor; + private final Class enumClass; + private final List groups; + + // ::: constructors + // + TaxaFields(String... groups) { + this(false, null, null, groups); + } + + TaxaFields(EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this(true, entityDescriptor, enumClass, groups); + } + + TaxaFields(boolean relation, EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this.relation = relation; + this.entityDescriptor = entityDescriptor; + this.enumClass = enumClass; + this.groups = groups == null ? Collections.EMPTY_LIST : Arrays.asList(groups); + } + + // ::: api + // + @Override + public String getName() { + return name(); + } + + @Override + public boolean isRelation() { + return relation; + } + + @Override + public Class getRelationEnumClass() { + return enumClass; + } + + @Override + public List getGroups() { + return groups; + } + + @Override + public EntityDescriptor getEntityDescriptor() { + return entityDescriptor; + } + + @Override + public Object fetchValue(TaxaEntity entity) { + if (entity == null) { + return null; + } + + switch (this) { + case null -> { + return null; + } + case id -> { + return entity.getId(); + } + case externalId ->{ + return entity.getExternalId(); + } + case entityKey ->{ + return entity.getEntityKey(); + } + case space ->{ + return entity.getSpace(); + } + case modelType ->{ + return entity.getModelType(); + } + case custom ->{ + return entity.isCustom(); + } + case name ->{ + return entity.getName(); + } + case description ->{ + return entity.getDescription(); + } + case data -> { + return entity.getData(); + } + case active -> { + return entity.isActive(); + } + case inserted -> { + return entity.getInserted(); + } + case inserter -> { + return entity.getInserter(); + } + case modified -> { + return entity.getModified(); + } + case modifier -> { + return entity.getModifier(); + } + case deleted -> { + return entity.isDeleted(); + } + case removed -> { + return entity.getRemoved(); + } + case remover -> { + return entity.getRemover(); + } + + default -> { + return null; + } + } + + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxa/TaxaMapBuilder.java b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxa/TaxaMapBuilder.java new file mode 100644 index 0000000..ccab367 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxa/TaxaMapBuilder.java @@ -0,0 +1,93 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.store.taxa; + +// java +import java.util.List; +import java.util.Map; +// base +import io.kumare.lib.app.api.Context; +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.BaseEntityMapBuilder; +// app + + +/** + * + * @author afatecha + */ +public class TaxaMapBuilder extends BaseEntityMapBuilder { + + // ::: vars + // + + + + // ::: fields + // + @Override + public TaxaMapBuilder addGroup(String name, boolean cascade) { + includes.addAll(EntityFieldDescriptor.group(TaxaFields.values(), name)); + + return this; + } + + @Override + public TaxaMapBuilder add(String fieldName) { + includes.add(TaxaFields.valueOf(fieldName)); + return this; + } + + @Override + public TaxaMapBuilder addAll(String... names) { + for (var i : names) { + includes.add(TaxaFields.valueOf(i)); + } + return this; + } + + @Override + public TaxaMapBuilder remove(String fieldName) { + excludes.add(TaxaFields.valueOf(fieldName)); + return this; + } + + @Override + public TaxaMapBuilder removeAll(String... names) { + for (var i : names) { + excludes.add(TaxaFields.valueOf(i)); + } + return this; + } + + // ::: relations + // + @Override + public TaxaMapBuilder addPlains(boolean cascade) { + includes.addAll(EntityFieldDescriptor.plains(TaxaFields.values())); + + return this; + } + + @Override + public TaxaMapBuilder addRelations(boolean cascade) { + includes.addAll(EntityFieldDescriptor.relations(TaxaFields.values())); + + return this; + } + + + + // ::: internals + // + @Override + protected void internalAttachRelations(Context context, + TaxaEntity entity, + List fields, + Map resultMap) { + + + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxa/TaxaRepository.java b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxa/TaxaRepository.java new file mode 100644 index 0000000..1f15e64 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxa/TaxaRepository.java @@ -0,0 +1,18 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.store.taxa; + +// spring +import org.springframework.stereotype.Repository; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Repository +public interface TaxaRepository extends AppKeyEntityRepository{ + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxa/TaxaStore.java b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxa/TaxaStore.java new file mode 100644 index 0000000..076a3a5 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxa/TaxaStore.java @@ -0,0 +1,35 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.store.taxa; + +// spring +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Service +public class TaxaStore extends AppKeyEntityStore { + + // ::: vars + // + @Autowired + private TaxaRepository repository; + + // ::: override + // + @Override + public TaxaRepository getRepository() { + return repository; + } + + // ::: api + // + + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxon/TaxonData.java b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxon/TaxonData.java new file mode 100644 index 0000000..9fbeb4c --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxon/TaxonData.java @@ -0,0 +1,34 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.store.taxon; + +// base +import io.kumare.iqr.app.store.AppExtendedEntityData; +// imports +import java.util.Map; + +public class TaxonData extends AppExtendedEntityData { + + // ::: vars + // + private Map attributes; + + // ::: fields + // + public Map getAttributes() { + return attributes; + } + + public void setAttributes(Map attributes) { + this.attributes = attributes; + } + + // ::: fluent + // + public TaxonData attributes(Map attributes) { + setAttributes(attributes); + return this; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxon/TaxonEntity.java b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxon/TaxonEntity.java new file mode 100644 index 0000000..f89dea5 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxon/TaxonEntity.java @@ -0,0 +1,305 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.store.taxon; + +// jakarta +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.Index; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +// base +import io.kumare.lib.app.api.store.*; +import io.kumare.iqr.app.store.*; +// imports + +// relations +import io.kumare.iqr.mod.taxonomy.store.taxa.TaxaEntity; + +// annotations +@Entity +@Table( + name = "taxon", + indexes = { + @Index(name = "idx_taxon_external_id", columnList = "externalId"), + @Index(name = "idx_taxon_entity_key", columnList = "entityKey"), + @Index(name = "idx_taxon_space", columnList = "space"), + @Index(name = "idx_taxon_taxa_key", columnList = "taxaKey"), + @Index(name = "idx_taxon_type_key", columnList = "typeKey"), + @Index(name = "idx_taxon_type_value", columnList = "typeValue"), + @Index(name = "idx_taxon_parent_key", columnList = "parentKey"), + @Index(name = "idx_taxon_parent_value", columnList = "parentValue"), + @Index(name = "idx_taxon_level", columnList = "level"), + @Index(name = "idx_taxon_ordinal", columnList = "ordinal"), + @Index(name = "idx_taxon_value", columnList = "value"), + @Index(name = "idx_taxon_name", columnList = "name"), + @Index(name = "idx_taxon_main", columnList = "main"), + @Index(name = "idx_taxon_description", columnList = "description") + } +) +public class TaxonEntity extends AppExtendedEntity implements SupportedEntityKey { + + // ::: vars + // + private String externalId; + private String entityKey; + private String space; + private String taxaKey; + private String typeKey; + private String typeValue; + private String parentKey; + private String parentValue; + private int level; + private int ordinal; + private String value; + private String name; + private boolean main; + private String description; + // relations + @ManyToOne(fetch = FetchType.LAZY) + private TaxaEntity taxa; + @ManyToOne(fetch = FetchType.LAZY) + private TaxonEntity type; + @ManyToOne(fetch = FetchType.LAZY) + private TaxonEntity parent; + + // ::: constructors + // + public TaxonEntity() { + } + + public TaxonEntity(String id) { + super(id); + } + + // ::: fields + // + public String getExternalId() { + return externalId; + } + + public void setExternalId(String externalId) { + this.externalId = externalId; + } + + @Override + public String getEntityKey() { + return entityKey; + } + + @Override + public void setEntityKey(String entityKey) { + this.entityKey = entityKey; + } + + public String getSpace() { + return space; + } + + public void setSpace(String space) { + this.space = space; + } + + public String getTaxaKey() { + return taxaKey; + } + + public void setTaxaKey(String taxaKey) { + this.taxaKey = taxaKey; + } + + public String getTypeKey() { + return typeKey; + } + + public void setTypeKey(String typeKey) { + this.typeKey = typeKey; + } + + public String getTypeValue() { + return typeValue; + } + + public void setTypeValue(String typeValue) { + this.typeValue = typeValue; + } + + public String getParentKey() { + return parentKey; + } + + public void setParentKey(String parentKey) { + this.parentKey = parentKey; + } + + public String getParentValue() { + return parentValue; + } + + public void setParentValue(String parentValue) { + this.parentValue = parentValue; + } + + public int getLevel() { + return level; + } + + public void setLevel(int level) { + this.level = level; + } + + public int getOrdinal() { + return ordinal; + } + + public void setOrdinal(int ordinal) { + this.ordinal = ordinal; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public boolean isMain() { + return main; + } + + public void setMain(boolean main) { + this.main = main; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + // relations + public TaxaEntity getTaxa() { + return taxa; + } + + public void setTaxa(TaxaEntity taxa) { + this.taxa = taxa; + } + + public TaxonEntity getType() { + return type; + } + + public void setType(TaxonEntity type) { + this.type = type; + } + + public TaxonEntity getParent() { + return parent; + } + + public void setParent(TaxonEntity parent) { + this.parent = parent; + } + + // ::: fluent + // + public TaxonEntity externalId(String externalId) { + setExternalId(externalId); + return this; + } + + public TaxonEntity entityKey(String entityKey) { + setEntityKey(entityKey); + return this; + } + + public TaxonEntity space(String space) { + setSpace(space); + return this; + } + + public TaxonEntity taxaKey(String taxaKey) { + setTaxaKey(taxaKey); + return this; + } + + public TaxonEntity typeKey(String typeKey) { + setTypeKey(typeKey); + return this; + } + + public TaxonEntity typeValue(String typeValue) { + setTypeValue(typeValue); + return this; + } + + public TaxonEntity parentKey(String parentKey) { + setParentKey(parentKey); + return this; + } + + public TaxonEntity parentValue(String parentValue) { + setParentValue(parentValue); + return this; + } + + public TaxonEntity level(int level) { + setLevel(level); + return this; + } + + public TaxonEntity ordinal(int ordinal) { + setOrdinal(ordinal); + return this; + } + + public TaxonEntity value(String value) { + setValue(value); + return this; + } + + public TaxonEntity name(String name) { + setName(name); + return this; + } + + public TaxonEntity main(boolean main) { + setMain(main); + return this; + } + + public TaxonEntity description(String description) { + setDescription(description); + return this; + } + + // relations + public TaxonEntity taxa(TaxaEntity taxa) { + setTaxa(taxa); + return this; + } + + public TaxonEntity type(TaxonEntity type) { + setType(type); + return this; + } + + public TaxonEntity parent(TaxonEntity parent) { + setParent(parent); + return this; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxon/TaxonFieldSchema.java b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxon/TaxonFieldSchema.java new file mode 100644 index 0000000..fd31797 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxon/TaxonFieldSchema.java @@ -0,0 +1,18 @@ +/* + */ +package io.kumare.iqr.mod.taxonomy.store.taxon; + + +/** + * + * @author administrador + */ +public enum TaxonFieldSchema { + + enabled, + required, + label, + value, + options; + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxon/TaxonFields.java b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxon/TaxonFields.java new file mode 100644 index 0000000..c7172f3 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxon/TaxonFields.java @@ -0,0 +1,199 @@ +/* + */ +package io.kumare.iqr.mod.taxonomy.store.taxon; + +// java +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +// base +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app +import io.kumare.iqr.mod.taxonomy.store.TaxonomyEntities; +import io.kumare.iqr.mod.taxonomy.store.taxa.TaxaFields; +import io.kumare.iqr.mod.taxonomy.store.TaxonomyEntities; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonFields; +import io.kumare.iqr.mod.taxonomy.store.TaxonomyEntities; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonFields; + +/** + * + * @author afatecha + */ +public enum TaxonFields implements EntityFieldDescriptor { + + id(MAIN, FIND, LIST), + externalId(MAIN, FIND, LIST), + entityKey(MAIN, FIND, LIST), + space(MAIN, FIND, LIST), + taxaKey(MAIN, FIND, LIST), + typeKey(MAIN, FIND, LIST), + typeValue(MAIN, FIND, LIST), + parentKey(MAIN, FIND, LIST), + parentValue(MAIN, FIND, LIST), + level(MAIN, FIND, LIST), + ordinal(MAIN, FIND, LIST), + value(MAIN, FIND, LIST), + name(MAIN, FIND, LIST), + main(MAIN, FIND, LIST), + description(MAIN, FIND, LIST), + active(MAIN, FIND, LIST), + inserted(AUDIT, FIND, LIST), + inserter(AUDIT, FIND, LIST), + modified(AUDIT, FIND), + modifier(AUDIT, FIND), + deleted(AUDIT), + removed(AUDIT), + remover(AUDIT), + taxa(TaxonomyEntities.taxa, TaxaFields.class, FIND), + type(TaxonomyEntities.taxon, TaxonFields.class, FIND), + parent(TaxonomyEntities.taxon, TaxonFields.class, FIND); + + // ::: vars + // + private final boolean relation; + private final EntityDescriptor entityDescriptor; + private final Class enumClass; + private final List groups; + + // ::: constructors + // + TaxonFields(String... groups) { + this(false, null, null, groups); + } + + TaxonFields(EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this(true, entityDescriptor, enumClass, groups); + } + + TaxonFields(boolean relation, EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this.relation = relation; + this.entityDescriptor = entityDescriptor; + this.enumClass = enumClass; + this.groups = groups == null ? Collections.EMPTY_LIST : Arrays.asList(groups); + } + + // ::: api + // + @Override + public String getName() { + return name(); + } + + @Override + public boolean isRelation() { + return relation; + } + + @Override + public Class getRelationEnumClass() { + return enumClass; + } + + @Override + public List getGroups() { + return groups; + } + + @Override + public EntityDescriptor getEntityDescriptor() { + return entityDescriptor; + } + + @Override + public Object fetchValue(TaxonEntity entity) { + if (entity == null) { + return null; + } + + switch (this) { + case null -> { + return null; + } + case id -> { + return entity.getId(); + } + case externalId ->{ + return entity.getExternalId(); + } + case entityKey ->{ + return entity.getEntityKey(); + } + case space ->{ + return entity.getSpace(); + } + case taxaKey ->{ + return entity.getTaxaKey(); + } + case typeKey ->{ + return entity.getTypeKey(); + } + case typeValue ->{ + return entity.getTypeValue(); + } + case parentKey ->{ + return entity.getParentKey(); + } + case parentValue ->{ + return entity.getParentValue(); + } + case level ->{ + return entity.getLevel(); + } + case ordinal ->{ + return entity.getOrdinal(); + } + case value ->{ + return entity.getValue(); + } + case name ->{ + return entity.getName(); + } + case main ->{ + return entity.isMain(); + } + case description ->{ + return entity.getDescription(); + } + case active -> { + return entity.isActive(); + } + case inserted -> { + return entity.getInserted(); + } + case inserter -> { + return entity.getInserter(); + } + case modified -> { + return entity.getModified(); + } + case modifier -> { + return entity.getModifier(); + } + case deleted -> { + return entity.isDeleted(); + } + case removed -> { + return entity.getRemoved(); + } + case remover -> { + return entity.getRemover(); + } + case taxa ->{ + return entity.getTaxa(); + } + case type ->{ + return entity.getType(); + } + case parent ->{ + return entity.getParent(); + } + default -> { + return null; + } + } + + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxon/TaxonMapBuilder.java b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxon/TaxonMapBuilder.java new file mode 100644 index 0000000..637f3e5 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxon/TaxonMapBuilder.java @@ -0,0 +1,230 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.store.taxon; + +// java +import java.util.List; +import java.util.Map; +// base +import io.kumare.lib.app.api.Context; +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.BaseEntityMapBuilder; +// app +import io.kumare.iqr.mod.taxonomy.store.taxa.TaxaMapBuilder; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonMapBuilder; + +/** + * + * @author afatecha + */ +public class TaxonMapBuilder extends BaseEntityMapBuilder { + + // ::: vars + // + private TaxaMapBuilder taxaBuilder; + private TaxonMapBuilder typeBuilder; + private TaxonMapBuilder parentBuilder; + + + // ::: fields + // + @Override + public TaxonMapBuilder addGroup(String name, boolean cascade) { + includes.addAll(EntityFieldDescriptor.group(TaxonFields.values(), name)); + + if(cascade) { + if (includes.contains(TaxonFields.taxa)) { + getTaxaBuilder().addGroup(name); + } + if (includes.contains(TaxonFields.type)) { + getTypeBuilder().addGroup(name); + } + if (includes.contains(TaxonFields.parent)) { + getParentBuilder().addGroup(name); + } + } + return this; + } + + @Override + public TaxonMapBuilder add(String fieldName) { + includes.add(TaxonFields.valueOf(fieldName)); + return this; + } + + @Override + public TaxonMapBuilder addAll(String... names) { + for (var i : names) { + includes.add(TaxonFields.valueOf(i)); + } + return this; + } + + @Override + public TaxonMapBuilder remove(String fieldName) { + excludes.add(TaxonFields.valueOf(fieldName)); + return this; + } + + @Override + public TaxonMapBuilder removeAll(String... names) { + for (var i : names) { + excludes.add(TaxonFields.valueOf(i)); + } + return this; + } + + // ::: relations + // + @Override + public TaxonMapBuilder addPlains(boolean cascade) { + includes.addAll(EntityFieldDescriptor.plains(TaxonFields.values())); + + if(cascade) { + if (includes.contains(TaxonFields.taxa)) { + getTaxaBuilder().addPlains(); + } + if (includes.contains(TaxonFields.type)) { + getTypeBuilder().addPlains(); + } + if (includes.contains(TaxonFields.parent)) { + getParentBuilder().addPlains(); + } + } + return this; + } + + @Override + public TaxonMapBuilder addRelations(boolean cascade) { + includes.addAll(EntityFieldDescriptor.relations(TaxonFields.values())); + + if(cascade) { + if (includes.contains(TaxonFields.taxa)) { + getTaxaBuilder().addRelations(); + } + if (includes.contains(TaxonFields.type)) { + getTypeBuilder().addRelations(); + } + if (includes.contains(TaxonFields.parent)) { + getParentBuilder().addRelations(); + } + } + return this; + } + + // ::: taxa + // + public TaxonMapBuilder addTaxa() { + return addTaxa(null); + } + + public TaxonMapBuilder addTaxa(String group) { + return addTaxa(group, false); + } + + public TaxonMapBuilder addTaxa(String group, boolean cascade) { + includes.add(TaxonFields.taxa); + + if (group != null) { + getTaxaBuilder().addGroup(group); + } + + return this; + } + + public TaxaMapBuilder getTaxaBuilder() { + if(taxaBuilder == null) { + taxaBuilder = new TaxaMapBuilder(); + } + return taxaBuilder; + } + + + // ::: type + // + public TaxonMapBuilder addType() { + return addType(null); + } + + public TaxonMapBuilder addType(String group) { + return addType(group, false); + } + + public TaxonMapBuilder addType(String group, boolean cascade) { + includes.add(TaxonFields.type); + + if (group != null) { + getTypeBuilder().addGroup(group); + } + + return this; + } + + public TaxonMapBuilder getTypeBuilder() { + if(typeBuilder == null) { + typeBuilder = new TaxonMapBuilder(); + } + return typeBuilder; + } + + + // ::: parent + // + public TaxonMapBuilder addParent() { + return addParent(null); + } + + public TaxonMapBuilder addParent(String group) { + return addParent(group, false); + } + + public TaxonMapBuilder addParent(String group, boolean cascade) { + includes.add(TaxonFields.parent); + + if (group != null) { + getParentBuilder().addGroup(group); + } + + return this; + } + + public TaxonMapBuilder getParentBuilder() { + if(parentBuilder == null) { + parentBuilder = new TaxonMapBuilder(); + } + return parentBuilder; + } + + // ::: internals + // + @Override + protected void internalAttachRelations(Context context, + TaxonEntity entity, + List fields, + Map resultMap) { + + if (fields.contains(TaxonFields.taxa)) { + attachRelation(context, + entity, + TaxonFields.taxa, + getTaxaBuilder(), + resultMap); + } + if (fields.contains(TaxonFields.type)) { + attachRelation(context, + entity, + TaxonFields.type, + getTypeBuilder(), + resultMap); + } + if (fields.contains(TaxonFields.parent)) { + attachRelation(context, + entity, + TaxonFields.parent, + getParentBuilder(), + resultMap); + } + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxon/TaxonRepository.java b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxon/TaxonRepository.java new file mode 100644 index 0000000..bb8b077 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxon/TaxonRepository.java @@ -0,0 +1,54 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.store.taxon; + +// spring +import org.springframework.stereotype.Repository; +// base +import io.kumare.iqr.app.store.*; +import java.util.List; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +/** + * + * @author afatecha + */ +@Repository +public interface TaxonRepository extends AppKeyEntityRepository { + + // ::: default + // + @Modifying + @Query("UPDATE TaxonEntity e SET e.main = (e.id = :id) WHERE e.taxaKey = :taxaKey") + public void setAsDefault(@Param("taxaKey") String taxaKey, @Param("id") String id); + + @Query("SELECT e FROM TaxonEntity e WHERE e.taxaKey = :taxaKey AND e.main = true") + public TaxonEntity findDefaultByTaxaKey(String taxaKey); + + // ::: taxa key and entity key + // + @Transactional(propagation = Propagation.NOT_SUPPORTED) + public TaxonEntity findByTaxaKeyAndEntityKey(String taxaKey, String entityKey); + + @Transactional(propagation = Propagation.NOT_SUPPORTED) + public List findAllByTaxaKey(String taxaKey); + + @Transactional(propagation = Propagation.NOT_SUPPORTED) + public Page findAllByTaxaKey(String taxaKey, Pageable pageable); + + // ::: taxa key and value + // + @Transactional(propagation = Propagation.NOT_SUPPORTED) + public TaxonEntity findByTaxaKeyAndValue(String taxaKey, String value); + + @Transactional(propagation = Propagation.NOT_SUPPORTED) + public List findAllByTaxaKeyAndValue(String taxaKey, String value); + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxon/TaxonStore.java b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxon/TaxonStore.java new file mode 100644 index 0000000..6481af9 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxon/TaxonStore.java @@ -0,0 +1,133 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.store.taxon; + +// spring +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +// base +import io.kumare.lib.app.api.Context; +import io.kumare.lib.v.ExceptionPrototype; +import io.kumare.lib.v.V; +// app +import io.kumare.iqr.app.store.*; +import java.util.List; + +/** + * + * @author afatecha + */ +@Service +public class TaxonStore extends AppKeyEntityStore { + + // ::: vars + // + @Autowired + private TaxonRepository repository; + + // ::: override + // + @Override + public TaxonRepository getRepository() { + return repository; + } + + // ::: api default + // + public void setAsDefault(Context context, TaxonEntity taxon) { + getRepository().setAsDefault(taxon.getTaxaKey(), taxon.getId()); + } + + public TaxonEntity ensureDefault(Context context, String taxaKey, ExceptionPrototype proto) { + var taxon = findDefault(context, taxaKey); + V.ifNull(taxon, proto); + return taxon; + } + + public TaxonEntity findDefault(Context context, String taxaKey) { + return getRepository().findDefaultByTaxaKey(taxaKey); + } + + // ::: ensure + // + public TaxonEntity ensure(Context context, + String taxaKey, + TaxonEntity taxon, + ExceptionPrototype proto) { + var found = ensure(context, taxon, proto); + V.ifFalse(found.getTaxaKey().equals(taxaKey), proto); + return found; + } + + public TaxonEntity ensureById(Context context, + String taxaKey, + String taxonId, + ExceptionPrototype proto) { + var found = ensureById(context, taxonId, proto); + V.ifFalse(found.getTaxaKey().equals(taxaKey), proto); + return found; + } + + public TaxonEntity ensureByKey(Context context, + String taxaKey, + String taxonKey, + ExceptionPrototype proto) { + var found = findByKey(context, taxaKey, taxonKey); + V.ifNull(found, proto); + V.ifFalse(found.getTaxaKey().equals(taxaKey), proto); + return found; + } + + public TaxonEntity ensureByValue(Context context, + String taxaKey, + String value, + ExceptionPrototype proto) { + var found = findByValue(context, taxaKey, value); + V.ifNull(found, proto); + V.ifFalse(found.getTaxaKey().equals(taxaKey), proto); + return found; + } + + // ::: find + // + public TaxonEntity findById(Context context, + String taxaKey, + String taxonId) { + + var found = findById(context, taxonId); + return found.getTaxaKey().equals(taxaKey) ? found : null; + } + + public TaxonEntity findByKey(Context context, + String taxaKey, + String taxonKey) { + + var found = getRepository().findByTaxaKeyAndEntityKey(taxaKey, taxonKey); + return found.getTaxaKey().equals(taxaKey) ? found : null; + } + + public TaxonEntity findByValue(Context context, + String taxaKey, + String value) { + + var found = getRepository().findByTaxaKeyAndValue(taxaKey, value); + return found.getTaxaKey().equals(taxaKey) ? found : null; + } + + // ::: list + // + public List listByTaxaKey(Context context, + String taxaKey) { + + return getRepository().findAllByTaxaKey(taxaKey); + } + + public List listByValue(Context context, + String taxaKey, + String value) { + + return getRepository().findAllByTaxaKeyAndValue(taxaKey, value); + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxonrelation/TaxonRelationData.java b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxonrelation/TaxonRelationData.java new file mode 100644 index 0000000..760a53b --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxonrelation/TaxonRelationData.java @@ -0,0 +1,48 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.store.taxonrelation; + +// base +import io.kumare.iqr.app.store.AppExtendedEntityData; +// imports +import java.util.Map; + +public class TaxonRelationData extends AppExtendedEntityData { + + // ::: vars + // + private String note; + private Map attributes; + + // ::: fields + // + public String getNote() { + return note; + } + + public void setNote(String note) { + this.note = note; + } + + public Map getAttributes() { + return attributes; + } + + public void setAttributes(Map attributes) { + this.attributes = attributes; + } + + // ::: fluent + // + public TaxonRelationData note(String note) { + setNote(note); + return this; + } + + public TaxonRelationData attributes(Map attributes) { + setAttributes(attributes); + return this; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxonrelation/TaxonRelationEntity.java b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxonrelation/TaxonRelationEntity.java new file mode 100644 index 0000000..f8d649a --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxonrelation/TaxonRelationEntity.java @@ -0,0 +1,138 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.store.taxonrelation; + +// jakarta +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.Index; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +// base +import io.kumare.lib.app.api.store.*; +import io.kumare.iqr.app.store.*; +// imports + +// relations +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonEntity; + +// annotations +@Entity +@Table( + name = "taxon_relation", + indexes = { + @Index(name = "idx_taxon_relation_external_id", columnList = "externalId"), + @Index(name = "idx_taxon_relation_space", columnList = "space"), + @Index(name = "idx_taxon_relation_literal", columnList = "literal") + } +) +public class TaxonRelationEntity extends AppExtendedEntity { + + // ::: vars + // + private String externalId; + private String space; + private String literal; + // relations + @ManyToOne(fetch = FetchType.LAZY) + private TaxonEntity subject; + @ManyToOne(fetch = FetchType.LAZY) + private TaxonEntity predicate; + @ManyToOne(fetch = FetchType.LAZY) + private TaxonEntity object; + + // ::: constructors + // + public TaxonRelationEntity() { + } + + public TaxonRelationEntity(String id) { + super(id); + } + + // ::: fields + // + public String getExternalId() { + return externalId; + } + + public void setExternalId(String externalId) { + this.externalId = externalId; + } + + public String getSpace() { + return space; + } + + public void setSpace(String space) { + this.space = space; + } + + public String getLiteral() { + return literal; + } + + public void setLiteral(String literal) { + this.literal = literal; + } + + // relations + public TaxonEntity getSubject() { + return subject; + } + + public void setSubject(TaxonEntity subject) { + this.subject = subject; + } + + public TaxonEntity getPredicate() { + return predicate; + } + + public void setPredicate(TaxonEntity predicate) { + this.predicate = predicate; + } + + public TaxonEntity getObject() { + return object; + } + + public void setObject(TaxonEntity object) { + this.object = object; + } + + // ::: fluent + // + public TaxonRelationEntity externalId(String externalId) { + setExternalId(externalId); + return this; + } + + public TaxonRelationEntity space(String space) { + setSpace(space); + return this; + } + + public TaxonRelationEntity literal(String literal) { + setLiteral(literal); + return this; + } + + // relations + public TaxonRelationEntity subject(TaxonEntity subject) { + setSubject(subject); + return this; + } + + public TaxonRelationEntity predicate(TaxonEntity predicate) { + setPredicate(predicate); + return this; + } + + public TaxonRelationEntity object(TaxonEntity object) { + setObject(object); + return this; + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxonrelation/TaxonRelationFields.java b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxonrelation/TaxonRelationFields.java new file mode 100644 index 0000000..8902dcb --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxonrelation/TaxonRelationFields.java @@ -0,0 +1,155 @@ +/* + */ +package io.kumare.iqr.mod.taxonomy.store.taxonrelation; + +// java +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +// base +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.EntityDescriptor; +// app +import io.kumare.iqr.mod.taxonomy.store.TaxonomyEntities; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonFields; +import io.kumare.iqr.mod.taxonomy.store.TaxonomyEntities; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonFields; +import io.kumare.iqr.mod.taxonomy.store.TaxonomyEntities; +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonFields; + +/** + * + * @author afatecha + */ +public enum TaxonRelationFields implements EntityFieldDescriptor { + + id(MAIN, FIND, LIST), + externalId(MAIN, FIND, LIST), + space(MAIN, FIND, LIST), + literal(MAIN, FIND, LIST), + active(MAIN, FIND, LIST), + inserted(AUDIT, FIND, LIST), + inserter(AUDIT, FIND, LIST), + modified(AUDIT, FIND), + modifier(AUDIT, FIND), + deleted(AUDIT), + removed(AUDIT), + remover(AUDIT), + subject(TaxonomyEntities.taxon, TaxonFields.class, FIND, LIST), + predicate(TaxonomyEntities.taxon, TaxonFields.class, FIND, LIST), + object(TaxonomyEntities.taxon, TaxonFields.class, FIND, LIST); + + // ::: vars + // + private final boolean relation; + private final EntityDescriptor entityDescriptor; + private final Class enumClass; + private final List groups; + + // ::: constructors + // + TaxonRelationFields(String... groups) { + this(false, null, null, groups); + } + + TaxonRelationFields(EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this(true, entityDescriptor, enumClass, groups); + } + + TaxonRelationFields(boolean relation, EntityDescriptor entityDescriptor, Class enumClass, String... groups) { + this.relation = relation; + this.entityDescriptor = entityDescriptor; + this.enumClass = enumClass; + this.groups = groups == null ? Collections.EMPTY_LIST : Arrays.asList(groups); + } + + // ::: api + // + @Override + public String getName() { + return name(); + } + + @Override + public boolean isRelation() { + return relation; + } + + @Override + public Class getRelationEnumClass() { + return enumClass; + } + + @Override + public List getGroups() { + return groups; + } + + @Override + public EntityDescriptor getEntityDescriptor() { + return entityDescriptor; + } + + @Override + public Object fetchValue(TaxonRelationEntity entity) { + if (entity == null) { + return null; + } + + switch (this) { + case null -> { + return null; + } + case id -> { + return entity.getId(); + } + case externalId ->{ + return entity.getExternalId(); + } + case space ->{ + return entity.getSpace(); + } + case literal ->{ + return entity.getLiteral(); + } + case active -> { + return entity.isActive(); + } + case inserted -> { + return entity.getInserted(); + } + case inserter -> { + return entity.getInserter(); + } + case modified -> { + return entity.getModified(); + } + case modifier -> { + return entity.getModifier(); + } + case deleted -> { + return entity.isDeleted(); + } + case removed -> { + return entity.getRemoved(); + } + case remover -> { + return entity.getRemover(); + } + case subject ->{ + return entity.getSubject(); + } + case predicate ->{ + return entity.getPredicate(); + } + case object ->{ + return entity.getObject(); + } + default -> { + return null; + } + } + + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxonrelation/TaxonRelationMapBuilder.java b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxonrelation/TaxonRelationMapBuilder.java new file mode 100644 index 0000000..d1a7735 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxonrelation/TaxonRelationMapBuilder.java @@ -0,0 +1,229 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.store.taxonrelation; + +// java +import java.util.List; +import java.util.Map; +// base +import io.kumare.lib.app.api.Context; +import io.kumare.lib.app.api.store.EntityFieldDescriptor; +import io.kumare.lib.base.server.spring.store.jpa.BaseEntityMapBuilder; +// app +import io.kumare.iqr.mod.taxonomy.store.taxon.TaxonMapBuilder; + +/** + * + * @author afatecha + */ +public class TaxonRelationMapBuilder extends BaseEntityMapBuilder { + + // ::: vars + // + private TaxonMapBuilder subjectBuilder; + private TaxonMapBuilder predicateBuilder; + private TaxonMapBuilder objectBuilder; + + + // ::: fields + // + @Override + public TaxonRelationMapBuilder addGroup(String name, boolean cascade) { + includes.addAll(EntityFieldDescriptor.group(TaxonRelationFields.values(), name)); + + if(cascade) { + if (includes.contains(TaxonRelationFields.subject)) { + getSubjectBuilder().addGroup(name); + } + if (includes.contains(TaxonRelationFields.predicate)) { + getPredicateBuilder().addGroup(name); + } + if (includes.contains(TaxonRelationFields.object)) { + getObjectBuilder().addGroup(name); + } + } + return this; + } + + @Override + public TaxonRelationMapBuilder add(String fieldName) { + includes.add(TaxonRelationFields.valueOf(fieldName)); + return this; + } + + @Override + public TaxonRelationMapBuilder addAll(String... names) { + for (var i : names) { + includes.add(TaxonRelationFields.valueOf(i)); + } + return this; + } + + @Override + public TaxonRelationMapBuilder remove(String fieldName) { + excludes.add(TaxonRelationFields.valueOf(fieldName)); + return this; + } + + @Override + public TaxonRelationMapBuilder removeAll(String... names) { + for (var i : names) { + excludes.add(TaxonRelationFields.valueOf(i)); + } + return this; + } + + // ::: relations + // + @Override + public TaxonRelationMapBuilder addPlains(boolean cascade) { + includes.addAll(EntityFieldDescriptor.plains(TaxonRelationFields.values())); + + if(cascade) { + if (includes.contains(TaxonRelationFields.subject)) { + getSubjectBuilder().addPlains(); + } + if (includes.contains(TaxonRelationFields.predicate)) { + getPredicateBuilder().addPlains(); + } + if (includes.contains(TaxonRelationFields.object)) { + getObjectBuilder().addPlains(); + } + } + return this; + } + + @Override + public TaxonRelationMapBuilder addRelations(boolean cascade) { + includes.addAll(EntityFieldDescriptor.relations(TaxonRelationFields.values())); + + if(cascade) { + if (includes.contains(TaxonRelationFields.subject)) { + getSubjectBuilder().addRelations(); + } + if (includes.contains(TaxonRelationFields.predicate)) { + getPredicateBuilder().addRelations(); + } + if (includes.contains(TaxonRelationFields.object)) { + getObjectBuilder().addRelations(); + } + } + return this; + } + + // ::: subject + // + public TaxonRelationMapBuilder addSubject() { + return addSubject(null); + } + + public TaxonRelationMapBuilder addSubject(String group) { + return addSubject(group, false); + } + + public TaxonRelationMapBuilder addSubject(String group, boolean cascade) { + includes.add(TaxonRelationFields.subject); + + if (group != null) { + getSubjectBuilder().addGroup(group); + } + + return this; + } + + public TaxonMapBuilder getSubjectBuilder() { + if(subjectBuilder == null) { + subjectBuilder = new TaxonMapBuilder(); + } + return subjectBuilder; + } + + + // ::: predicate + // + public TaxonRelationMapBuilder addPredicate() { + return addPredicate(null); + } + + public TaxonRelationMapBuilder addPredicate(String group) { + return addPredicate(group, false); + } + + public TaxonRelationMapBuilder addPredicate(String group, boolean cascade) { + includes.add(TaxonRelationFields.predicate); + + if (group != null) { + getPredicateBuilder().addGroup(group); + } + + return this; + } + + public TaxonMapBuilder getPredicateBuilder() { + if(predicateBuilder == null) { + predicateBuilder = new TaxonMapBuilder(); + } + return predicateBuilder; + } + + + // ::: object + // + public TaxonRelationMapBuilder addObject() { + return addObject(null); + } + + public TaxonRelationMapBuilder addObject(String group) { + return addObject(group, false); + } + + public TaxonRelationMapBuilder addObject(String group, boolean cascade) { + includes.add(TaxonRelationFields.object); + + if (group != null) { + getObjectBuilder().addGroup(group); + } + + return this; + } + + public TaxonMapBuilder getObjectBuilder() { + if(objectBuilder == null) { + objectBuilder = new TaxonMapBuilder(); + } + return objectBuilder; + } + + // ::: internals + // + @Override + protected void internalAttachRelations(Context context, + TaxonRelationEntity entity, + List fields, + Map resultMap) { + + if (fields.contains(TaxonRelationFields.subject)) { + attachRelation(context, + entity, + TaxonRelationFields.subject, + getSubjectBuilder(), + resultMap); + } + if (fields.contains(TaxonRelationFields.predicate)) { + attachRelation(context, + entity, + TaxonRelationFields.predicate, + getPredicateBuilder(), + resultMap); + } + if (fields.contains(TaxonRelationFields.object)) { + attachRelation(context, + entity, + TaxonRelationFields.object, + getObjectBuilder(), + resultMap); + } + } + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxonrelation/TaxonRelationRepository.java b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxonrelation/TaxonRelationRepository.java new file mode 100644 index 0000000..1c60cb3 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxonrelation/TaxonRelationRepository.java @@ -0,0 +1,18 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.store.taxonrelation; + +// spring +import org.springframework.stereotype.Repository; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Repository +public interface TaxonRelationRepository extends AppEntityRepository{ + +} diff --git a/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxonrelation/TaxonRelationStore.java b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxonrelation/TaxonRelationStore.java new file mode 100644 index 0000000..83a1ce7 --- /dev/null +++ b/src/main/java/io/kumare/iqr/mod/taxonomy/store/taxonrelation/TaxonRelationStore.java @@ -0,0 +1,35 @@ +/* + * + */ +package io.kumare.iqr.mod.taxonomy.store.taxonrelation; + +// spring +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +// base +import io.kumare.iqr.app.store.*; + +/** + * + * @author afatecha + */ +@Service +public class TaxonRelationStore extends AppEntityStore { + + // ::: vars + // + @Autowired + private TaxonRelationRepository repository; + + // ::: override + // + @Override + public TaxonRelationRepository getRepository() { + return repository; + } + + // ::: api + // + + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..9fbdeb3 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,84 @@ + +# ======= SPRING ======== + +# Server Configuration +server.servlet.context-path=/time/api +#spring.web.resources.static-locations=classpath:/public/ + +server.port=8080 +#server.port=8300 +#server.ssl.enabled=true +#server.ssl.certificate-private-key=/home/prueba-server/qrpp-server/privkey.pem +#server.ssl.certificate=/home/prueba-server/qrpp-server/fullchain.pem + +# Database Configuration +spring.datasource.url=jdbc:postgresql://localhost:5432/iqr +spring.datasource.username=iqrdb +spring.datasource.password=Kum4Iqr +spring.datasource.driver-class-name=org.postgresql.Driver +spring.jpa.hibernate.ddl-auto=update + +# Configuraci\u00f3n del pool de conexiones +#M\u00e1ximo 10 conexiones activas +spring.datasource.hikari.maximum-pool-size=3 +# Cero conexiones ociosas +spring.datasource.hikari.minimum-idle=0 +# Conexi\u00f3n inactiva se libera despu\u00e9s de 10 segundos +spring.datasource.hikari.idle-timeout=10000 +# Esperar 30 segundos para obtener una conexi\u00f3n +spring.datasource.hikari.connection-timeout=30000 +# M\u00e1ximo 30 minutos de vida para una conexi\u00f3n +spring.datasource.hikari.max-lifetime=120000 + +# Swagger +springdoc.swagger-ui.path=/swagger.html + +# Keycloak Configuration +kc.server=${KC_SERVER:http://190.128.232.226:8200} +kc.realm=${KC_REALM:iqr} +spring.security.oauth2.resourceserver.jwt.issuer-uri=${kc.server}/realms/${kc.realm} +spring.security.oauth2.resourceserver.jwt.jwk-set-uri= ${spring.security.oauth2.resourceserver.jwt.issuer-uri}/protocol/openid-connect/certs + +jwt.auth.converter.principal_attribute=preferred_username + +kc.auth.server.url=${kc.server} +kc.client.id=${KC_CLIENT_ID:backend} +kc.client.secret=${KC_CLIENT_SECRET:P7gtn7e0tkeQzGHmRt1TfwMfdjGXYUnN} +kc.admin.username=${KC_ADMIN_USERNAME:iqr} +kc.admin.password=${KC_ADMIN_PASSWORD:123456} + +# ======= CATATREPA ======== + +# Adapter QR +#catatrepa.adapter.qr.address=${QR_ADDRESS:http://localhost:4200} +# Adapter SMS-WS +#catatrepa.adapter.smsws.endpoint.address=${CTTP_SMSWS_BASEURL:http://localhost/} +# Adapter EMAIL +#catatrepa.adapter.email.x=${CTTP_EMAIL:http://localhost/} + +# ========================== + + +# ======= HELP ======== + +# import config : file | classpath (more than one file) +#spring.config.import=file:./config/database.properties, classpath:other.properties + +# import config : optional +#spring.config.import=optional:file:./config/database.properties + +# using profiling config +#spring.profiles.active=${SPRING_PROFILES_ACTIVE:defProfileName} +#spring.profiles.include=proddb, prodmq // adding for all environments + +# visma +visma.server=${VISMA_SERVER:https://customerapi.geovictoria.com/api/v1} +visma.user=${VISMA_USER:40ffff} +visma.password=${VISMA_PASSWORD:4ddc7b47} + +# Desarrollo Interceptor +logging.level.io.kumare=DEBUG + +# Producci\u00f3n Interceptor +#logging.level.io.kumare=INFO +#logging.level.io.kumare.LoggingInterceptor=WARN \ No newline at end of file