提交 9975915f 编写于 作者: Z zhourui

erasecontent

上级 ca685121
......@@ -140,7 +140,7 @@ public class ResourceFactory {
for (Entry<String, DataServer> entry : Config.nodes().dataServers().entrySet()) {
DruidDataSourceC3P0Adapter dataSource = new DruidDataSourceC3P0Adapter();
String url = "jdbc:h2:tcp://" + entry.getKey() + ":" + entry.getValue().getTcpPort()
+ "/X;DEFAULT_LOCK_TIMEOUT=" + entry.getValue().getLockTimeout() + ";JMX="
+ "/X;LOCK_MODE=0;DEFAULT_LOCK_TIMEOUT=" + entry.getValue().getLockTimeout() + ";JMX="
+ (entry.getValue().getJmxEnable() ? "TRUE" : "FALSE") + ";CACHE_SIZE="
+ (entry.getValue().getCacheSize() * 1024);
dataSource.setJdbcUrl(url);
......@@ -170,7 +170,7 @@ public class ResourceFactory {
BasicDataSource dataSource = new BasicDataSource();
String url = "jdbc:h2:tcp://" + entry.getKey() + ":" + entry.getValue().getTcpPort()
+ "/X;DEFAULT_LOCK_TIMEOUT=" + entry.getValue().getLockTimeout() + ";JMX="
+ "/X;LOCK_MODE=0;DEFAULT_LOCK_TIMEOUT=" + entry.getValue().getLockTimeout() + ";JMX="
+ (entry.getValue().getJmxEnable() ? "TRUE" : "FALSE") + ";CACHE_SIZE="
+ (entry.getValue().getCacheSize() * 1024);
dataSource.setDriverClassName(SlicePropertiesBuilder.driver_h2);
......@@ -195,7 +195,7 @@ public class ResourceFactory {
for (Entry<String, DataServer> entry : Config.nodes().dataServers().entrySet()) {
DruidDataSource dataSource = new DruidDataSource();
String url = "jdbc:h2:tcp://" + entry.getKey() + ":" + entry.getValue().getTcpPort()
+ "/X;DEFAULT_LOCK_TIMEOUT=" + entry.getValue().getLockTimeout() + ";JMX="
+ "/X;LOCK_MODE=0;DEFAULT_LOCK_TIMEOUT=" + entry.getValue().getLockTimeout() + ";JMX="
+ (entry.getValue().getJmxEnable() ? "TRUE" : "FALSE") + ";CACHE_SIZE="
+ (entry.getValue().getCacheSize() * 1024);
dataSource.setDriverClassName(SlicePropertiesBuilder.driver_h2);
......
......@@ -61,8 +61,8 @@ public abstract class EraseContent {
protected void run() throws Exception {
new Thread(() -> {
try {
Thread.currentThread().setContextClassLoader(ClassLoaderTools.urlClassLoader(false, true, true, true,
true, Config.dir_local_temp_classes().toPath()));
Thread.currentThread().setContextClassLoader(ClassLoaderTools.urlClassLoader(false, false, false, false,
false, Config.dir_local_temp_classes().toPath()));
logger.print("erase {} content data: start at {}.", name, DateTools.format(start));
this.classNames = ListUtils.intersection(this.classNames,
(List<String>) Config.resource(Config.RESOURCE_CONTAINERENTITYNAMES));
......@@ -77,7 +77,6 @@ public abstract class EraseContent {
persistence.getName(),
PersistenceXmlHelper.properties(cls.getName(), Config.slice().getEnable()));
EntityManager em = emf.createEntityManager();
if (DataItem.class.isAssignableFrom(cls)) {
Long total = this.estimateItemCount(em, cls);
logger.print("erase {} content data:{}, total {}.", name, cls.getName(), total);
......@@ -87,6 +86,8 @@ public abstract class EraseContent {
logger.print("erase {} content data:{}, total {}.", name, cls.getName(), total);
this.erase(cls, em, storageMappings, total);
}
em.close();
emf.close();
}
Date end = new Date();
logger.print("erase {} content data: completed at {}, elapsed {} ms.", name, DateTools.format(end),
......
......@@ -305,7 +305,7 @@ public class ApplicationServerTools extends JettySeverTools {
throws Exception {
List<String> names = new ArrayList<>();
officialClassInfos.stream().map(ClassInfo::getSimpleName).forEach(names::add);
// names.addAll(customNames);
names.addAll(customNames);
for (String str : Config.dir_servers_applicationServer_work(true).list()) {
if (!names.contains(str)) {
FileUtils.forceDelete(new File(Config.dir_servers_applicationServer_work(), str));
......@@ -316,7 +316,7 @@ public class ApplicationServerTools extends JettySeverTools {
private static void modified(Path war, Path dir) throws IOException {
Path lastModified = Paths.get(dir.toString(), PathTools.WEB_INF_LASTMODIFIED);
if ((!Files.exists(lastModified)) || Files.isDirectory(lastModified)
|| (Files.getLastModifiedTime(lastModified).toMillis() != NumberUtils
|| (Files.getLastModifiedTime(war).toMillis() != NumberUtils
.toLong(FileUtils.readFileToString(lastModified.toFile(), DefaultCharset.charset_utf_8), 0))) {
logger.print("deploy war:{}.", war.getFileName().toAbsolutePath());
if (Files.exists(dir)) {
......@@ -327,7 +327,7 @@ public class ApplicationServerTools extends JettySeverTools {
Files.createDirectories(lastModified.getParent());
Files.createFile(lastModified);
}
FileUtils.writeStringToFile(lastModified.toFile(), Files.getLastModifiedTime(lastModified).toMillis() + "",
FileUtils.writeStringToFile(lastModified.toFile(), Files.getLastModifiedTime(war).toMillis() + "",
DefaultCharset.charset_utf_8, false);
}
}
......
package com.x.server.console.server.center;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.EnumSet;
import javax.servlet.DispatcherType;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.file.PathUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.eclipse.jetty.quickstart.QuickStartWebApp;
......@@ -25,14 +31,15 @@ import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.DefaultCharset;
import com.x.base.core.project.tools.JarTools;
import com.x.base.core.project.tools.PathTools;
import com.x.server.console.server.JettySeverTools;
public class CenterServerTools extends JettySeverTools {
private static Logger logger = LoggerFactory.getLogger(CenterServerTools.class);
private static int CENTERSERVER_THREAD_POOL_SIZE_MIN = 50;
private static int CENTERSERVER_THREAD_POOL_SIZE_MAX = 500;
private static final int CENTERSERVER_THREAD_POOL_SIZE_MIN = 50;
private static final int CENTERSERVER_THREAD_POOL_SIZE_MAX = 500;
public static Server start(CenterServer centerServer) throws Exception {
......@@ -40,22 +47,24 @@ public class CenterServerTools extends JettySeverTools {
HandlerList handlers = new HandlerList();
File war = new File(Config.dir_store(), x_program_center.class.getSimpleName() + ".war");
File dir = new File(Config.dir_servers_centerServer_work(true), x_program_center.class.getSimpleName());
if (war.exists()) {
Path war = Paths.get(Config.dir_store().toString(), x_program_center.class.getSimpleName() + PathTools.DOT_WAR);
Path dir = Paths.get(Config.dir_servers_centerServer_work(true).toString(),
x_program_center.class.getSimpleName());
if (Files.exists(war)) {
modified(war, dir);
QuickStartWebApp webApp = new QuickStartWebApp();
webApp.setAutoPreconfigure(false);
webApp.setDisplayName(x_program_center.class.getSimpleName());
webApp.setContextPath("/" + x_program_center.class.getSimpleName());
webApp.setResourceBase(dir.getAbsolutePath());
webApp.setDescriptor(new File(dir, "WEB-INF/web.xml").getAbsolutePath());
webApp.setResourceBase(dir.toAbsolutePath().toString());
webApp.setDescriptor(dir.resolve(Paths.get(PathTools.WEB_INF_WEB_XML)).toString());
webApp.setExtraClasspath(calculateExtraClassPath(x_program_center.class));
webApp.getInitParams().put("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false");
webApp.getInitParams().put("org.eclipse.jetty.jsp.precompiled", "true");
webApp.getInitParams().put("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
/* stat */
if (centerServer.getStatEnable()) {
webApp.getInitParams().put("org.eclipse.jetty.servlet.Default.useFileMappedBuffer",
BooleanUtils.toStringTrueFalse(false));
webApp.getInitParams().put("org.eclipse.jetty.jsp.precompiled", BooleanUtils.toStringTrueFalse(true));
webApp.getInitParams().put("org.eclipse.jetty.servlet.Default.dirAllowed",
BooleanUtils.toStringTrueFalse(false));
if (BooleanUtils.isTrue(centerServer.getStatEnable())) {
FilterHolder statFilterHolder = new FilterHolder(new WebStatFilter());
statFilterHolder.setInitParameter("exclusions", centerServer.getStatExclusions());
webApp.addFilter(statFilterHolder, "/*", EnumSet.of(DispatcherType.REQUEST));
......@@ -63,10 +72,9 @@ public class CenterServerTools extends JettySeverTools {
statServletHolder.setInitParameter("sessionStatEnable", "false");
webApp.addServlet(statServletHolder, "/druid/*");
}
/* stat end */
handlers.addHandler(webApp);
} else {
throw new Exception("centerServer war not exist.");
throw new IOException("centerServer war not exist.");
}
QueuedThreadPool threadPool = new QueuedThreadPool();
......@@ -75,7 +83,7 @@ public class CenterServerTools extends JettySeverTools {
Server server = new Server(threadPool);
server.setAttribute("maxFormContentSize", centerServer.getMaxFormContent() * 1024 * 1024);
if (centerServer.getSslEnable()) {
if (BooleanUtils.isTrue(centerServer.getSslEnable())) {
addHttpsConnector(server, centerServer.getPort());
} else {
addHttpConnector(server, centerServer.getPort());
......@@ -106,16 +114,22 @@ public class CenterServerTools extends JettySeverTools {
}
}
private static void modified(File war, File dir) throws Exception {
File lastModified = new File(dir, "WEB-INF/lastModified");
if ((!lastModified.exists()) || lastModified.isDirectory() || (war.lastModified() != NumberUtils
.toLong(FileUtils.readFileToString(lastModified, DefaultCharset.charset_utf_8), 0))) {
if (dir.exists()) {
FileUtils.forceDelete(dir);
private static void modified(Path war, Path dir) throws IOException {
Path lastModified = Paths.get(dir.toString(), PathTools.WEB_INF_LASTMODIFIED);
if ((!Files.exists(lastModified)) || Files.isDirectory(lastModified)
|| (Files.getLastModifiedTime(war).toMillis() != NumberUtils
.toLong(FileUtils.readFileToString(lastModified.toFile(), DefaultCharset.charset_utf_8), 0))) {
logger.print("deploy war:{}.", war.getFileName().toAbsolutePath());
if (Files.exists(dir)) {
PathUtils.cleanDirectory(dir);
}
JarTools.unjar(war, "", dir, true);
FileUtils.writeStringToFile(lastModified, war.lastModified() + "", DefaultCharset.charset_utf_8, false);
if (!Files.exists(lastModified)) {
Files.createDirectories(lastModified.getParent());
Files.createFile(lastModified);
}
FileUtils.writeStringToFile(lastModified.toFile(), Files.getLastModifiedTime(war).toMillis() + "",
DefaultCharset.charset_utf_8, false);
}
}
}
\ No newline at end of file
package com.x.portal.assemble.surface;
import com.x.base.core.container.EntityManagerContainer;
public abstract class AbstractFactory {
private Business business;
public AbstractFactory(Business business) throws Exception {
try {
if (null == business) {
throw new Exception("business can not be null.");
}
this.business = business;
} catch (Exception e) {
throw new Exception("can not instantiating factory.");
}
}
public EntityManagerContainer entityManagerContainer() throws Exception {
return this.business.entityManagerContainer();
}
public Business business() throws Exception {
return this.business;
}
}
package com.x.portal.assemble.surface;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import com.x.base.core.project.Context;
@WebListener
public class ApplicationServletContextListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
try {
ThisApplication.context = Context.concrete(servletContextEvent);
ThisApplication.init();
ThisApplication.context().regist();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
try {
ThisApplication.destroy();
ThisApplication.context.destrory(servletContextEvent);
} catch (Exception e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
package com.x.portal.assemble.surface;
import com.x.base.core.container.EntityManagerContainer;
import com.x.organization.core.express.Organization;
import com.x.portal.assemble.surface.factory.FileFactory;
import com.x.portal.assemble.surface.factory.PageFactory;
import com.x.portal.assemble.surface.factory.PortalFactory;
import com.x.portal.assemble.surface.factory.ScriptFactory;
import com.x.portal.assemble.surface.factory.WidgetFactory;
public class Business {
private EntityManagerContainer emc;
public Business(EntityManagerContainer emc) throws Exception {
this.emc = emc;
}
public EntityManagerContainer entityManagerContainer() {
return this.emc;
}
private Organization organization;
public Organization organization() throws Exception {
if (null == this.organization) {
this.organization = new Organization(ThisApplication.context());
}
return organization;
}
private PortalFactory portal;
public PortalFactory portal() throws Exception {
if (null == this.portal) {
this.portal = new PortalFactory(this);
}
return portal;
}
private WidgetFactory widget;
public WidgetFactory widget() throws Exception {
if (null == this.widget) {
this.widget = new WidgetFactory(this);
}
return widget;
}
private PageFactory page;
public PageFactory page() throws Exception {
if (null == this.page) {
this.page = new PageFactory(this);
}
return page;
}
private ScriptFactory script;
public ScriptFactory script() throws Exception {
if (null == this.script) {
this.script = new ScriptFactory(this);
}
return script;
}
private FileFactory file;
public FileFactory file() throws Exception {
if (null == this.file) {
this.file = new FileFactory(this);
}
return file;
}
}
\ No newline at end of file
package com.x.portal.assemble.surface;
import com.x.base.core.project.gson.GsonPropertyObject;
public class Control extends GsonPropertyObject {
/* 是否可以看到 */
private Boolean allowVisit;
/* 是否可以直接流转 */
private Boolean allowProcessing;
/* 是否可以处理待阅 */
private Boolean allowReadProcessing;
/* 是否可以保存数据 */
private Boolean allowSave;
/* 是否可以重置处理人 */
private Boolean allowReset;
/* 是否可以待阅处理人 */
private Boolean allowReadReset;
/* 是否可以召回 */
private Boolean allowRetract;
/* 是否可以调度 */
private Boolean allowReroute;
/* 是否可以删除 */
private Boolean allowDelete;
public Boolean getAllowSave() {
return allowSave;
}
public void setAllowSave(Boolean allowSave) {
this.allowSave = allowSave;
}
public Boolean getAllowReset() {
return allowReset;
}
public void setAllowReset(Boolean allowReset) {
this.allowReset = allowReset;
}
public Boolean getAllowRetract() {
return allowRetract;
}
public void setAllowRetract(Boolean allowRetract) {
this.allowRetract = allowRetract;
}
public Boolean getAllowReroute() {
return allowReroute;
}
public void setAllowReroute(Boolean allowReroute) {
this.allowReroute = allowReroute;
}
public Boolean getAllowProcessing() {
return allowProcessing;
}
public void setAllowProcessing(Boolean allowProcessing) {
this.allowProcessing = allowProcessing;
}
public Boolean getAllowDelete() {
return allowDelete;
}
public void setAllowDelete(Boolean allowDelete) {
this.allowDelete = allowDelete;
}
public Boolean getAllowVisit() {
return allowVisit;
}
public void setAllowVisit(Boolean allowVisit) {
this.allowVisit = allowVisit;
}
public Boolean getAllowReadProcessing() {
return allowReadProcessing;
}
public void setAllowReadProcessing(Boolean allowReadProcessing) {
this.allowReadProcessing = allowReadProcessing;
}
public Boolean getAllowReadReset() {
return allowReadReset;
}
public void setAllowReadReset(Boolean allowReadReset) {
this.allowReadReset = allowReadReset;
}
}
\ No newline at end of file
package com.x.portal.assemble.surface;
import com.x.base.core.project.Context;
import com.x.base.core.project.cache.CacheManager;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.logger.LoggerFactory;
public class ThisApplication {
private ThisApplication() {
// nothing
}
protected static Context context;
public static Context context() {
return context;
}
public static void init() {
try {
CacheManager.init(context.clazz().getSimpleName());
LoggerFactory.setLevel(Config.logLevel().x_portal_assemble_surface());
} catch (Exception e) {
e.printStackTrace();
}
}
public static void destroy() {
try {
CacheManager.shutdown();
} catch (Exception e) {
e.printStackTrace();
}
}
}
package com.x.portal.assemble.surface.factory;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import com.x.portal.assemble.surface.AbstractFactory;
import com.x.portal.assemble.surface.Business;
import com.x.portal.core.entity.File;
import com.x.portal.core.entity.File_;
import com.x.base.core.project.cache.Cache.CacheCategory;
import com.x.base.core.project.cache.Cache.CacheKey;
import com.x.base.core.project.cache.CacheManager;
import java.util.Optional;
public class FileFactory extends AbstractFactory {
static CacheCategory cache = new CacheCategory(File.class);
public FileFactory(Business abstractBusiness) throws Exception {
super(abstractBusiness);
}
public File pick(String id) throws Exception {
CacheKey cacheKey = new CacheKey(id);
Optional<?> optional = CacheManager.get(cache, cacheKey);
if (optional.isPresent()) {
return (File) optional.get();
} else {
File o = this.business().entityManagerContainer().find(id, File.class);
if (null != o) {
this.business().entityManagerContainer().get(File.class).detach(o);
CacheManager.put(cache, cacheKey, o);
return o;
}
return null;
}
}
public List<File> listWithPortalObject(String portalId) throws Exception {
EntityManager em = this.entityManagerContainer().get(File.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<File> cq = cb.createQuery(File.class);
Root<File> root = cq.from(File.class);
Predicate p = cb.equal(root.get(File_.portal), portalId);
List<File> list = em.createQuery(cq.select(root).where(p)).getResultList();
return list;
}
public List<String> listWithPortal(String portalId) throws Exception {
EntityManager em = this.entityManagerContainer().get(File.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<File> root = cq.from(File.class);
Predicate p = cb.equal(root.get(File_.portal), portalId);
List<String> list = em.createQuery(cq.select(root.get(File_.id)).where(p)).getResultList();
return list;
}
public <T extends File> List<T> sort(List<T> list) {
list = list.stream()
.sorted(Comparator.comparing(File::getAlias, Comparator.nullsLast(String::compareTo))
.thenComparing(File::getName, Comparator.nullsLast(String::compareTo)))
.collect(Collectors.toList());
return list;
}
}
\ No newline at end of file
package com.x.portal.assemble.surface.factory;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import com.x.portal.assemble.surface.AbstractFactory;
import com.x.portal.assemble.surface.Business;
import com.x.portal.core.entity.Page;
import com.x.portal.core.entity.Page_;
import com.x.portal.core.entity.Portal;
import com.x.base.core.project.cache.Cache.CacheCategory;
import com.x.base.core.project.cache.Cache.CacheKey;
import com.x.base.core.project.cache.CacheManager;
import java.util.Optional;
public class PageFactory extends AbstractFactory {
static CacheCategory cache = new CacheCategory(Page.class);
public PageFactory(Business abstractBusiness) throws Exception {
super(abstractBusiness);
}
public List<String> listWithPortal(String portalId) throws Exception {
EntityManager em = this.entityManagerContainer().get(Page.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Page> root = cq.from(Page.class);
Predicate p = cb.equal(root.get(Page_.portal), portalId);
List<String> list = em.createQuery(cq.select(root.get(Page_.id)).where(p)).getResultList();
return list;
}
public Page pick(String id) throws Exception {
CacheKey cacheKey = new CacheKey(id);
Optional<?> optional = CacheManager.get(cache, cacheKey);
if (optional.isPresent()) {
return (Page) optional.get();
} else {
Page o = this.business().entityManagerContainer().find(id, Page.class);
if (null != o) {
this.business().entityManagerContainer().get(Page.class).detach(o);
CacheManager.put(cache, cacheKey, o);
return o;
}
return null;
}
}
public Page pick(Portal portal, String flag) throws Exception {
CacheKey cacheKey = new CacheKey(portal.getId(), flag);
Optional<?> optional = CacheManager.get(cache, cacheKey);
if (optional.isPresent()) {
return (Page) optional.get();
} else {
Page o = entityManagerContainer().restrictFlag(flag, Page.class, Page.portal_FIELDNAME, portal.getId());
if (null != o) {
this.business().entityManagerContainer().get(Page.class).detach(o);
CacheManager.put(cache, cacheKey, o);
return o;
}
return null;
}
}
}
\ No newline at end of file
package com.x.portal.assemble.surface.factory;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.organization.OrganizationDefinition;
import com.x.base.core.project.tools.ListTools;
import com.x.portal.assemble.surface.AbstractFactory;
import com.x.portal.assemble.surface.Business;
import com.x.portal.core.entity.Portal;
import com.x.portal.core.entity.Portal_;
import com.x.base.core.project.cache.Cache.CacheCategory;
import com.x.base.core.project.cache.Cache.CacheKey;
import com.x.base.core.project.cache.CacheManager;
import java.util.Optional;
public class PortalFactory extends AbstractFactory {
static CacheCategory cache = new CacheCategory(Portal.class);
public PortalFactory(Business abstractBusiness) throws Exception {
super(abstractBusiness);
}
public List<String> list(EffectivePerson effectivePerson) throws Exception {
EntityManager em = this.entityManagerContainer().get(Portal.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Portal> root = cq.from(Portal.class);
Predicate p = cb.conjunction();
if (effectivePerson.isNotManager() && (!this.business().organization().person().hasRole(effectivePerson,
OrganizationDefinition.PortalManager))) {
List<String> identities = this.business().organization().identity()
.listWithPerson(effectivePerson.getDistinguishedName());
List<String> units = this.business().organization().unit()
.listWithPersonSupNested(effectivePerson.getDistinguishedName());
p = cb.equal(root.get(Portal_.creatorPerson), effectivePerson.getDistinguishedName());
p = cb.or(p, cb.isMember(effectivePerson.getDistinguishedName(), root.get(Portal_.controllerList)));
p = cb.or(cb.and(cb.isEmpty(root.get(Portal_.availableIdentityList)),
cb.isEmpty(root.get(Portal_.availableUnitList))));
p = cb.or(p, root.get(Portal_.availableIdentityList).in(identities));
p = cb.or(p, root.get(Portal_.availableUnitList).in(units));
}
cq.select(root.get(Portal_.id)).where(p).distinct(true);
return em.createQuery(cq).getResultList();
}
public boolean visible(EffectivePerson effectivePerson, Portal portal) throws Exception {
if (effectivePerson.isManager() || this.business().organization().person().hasRole(effectivePerson,
OrganizationDefinition.PortalManager)) {
return true;
}
if (effectivePerson.isPerson(portal.getCreatorPerson())) {
return true;
}
if (effectivePerson.isPerson(portal.getControllerList())) {
return true;
}
if (ListTools.isEmpty(portal.getAvailableIdentityList(), portal.getAvailableUnitList())) {
return true;
}
List<String> identities = this.business().organization().identity()
.listWithPerson(effectivePerson.getDistinguishedName());
if (ListTools.containsAny(identities, portal.getAvailableIdentityList())) {
return true;
}
List<String> units = this.business().organization().unit().listWithPersonSupNested(effectivePerson);
if (ListTools.containsAny(units, portal.getAvailableUnitList())) {
return true;
}
return false;
}
public Portal pick(String flag) throws Exception {
CacheKey cacheKey = new CacheKey(flag);
Optional<?> optional = CacheManager.get(cache, cacheKey);
if (optional.isPresent()) {
return (Portal) optional.get();
} else {
Portal o = this.business().entityManagerContainer().flag(flag, Portal.class);
if (null != o) {
this.business().entityManagerContainer().get(Portal.class).detach(o);
CacheManager.put(cache, cacheKey, o);
return o;
}
return null;
}
}
}
\ No newline at end of file
package com.x.portal.assemble.surface.factory;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import com.x.portal.assemble.surface.AbstractFactory;
import com.x.portal.assemble.surface.Business;
import com.x.portal.core.entity.Portal;
import com.x.portal.core.entity.Script;
import com.x.portal.core.entity.Script_;
import com.x.base.core.project.cache.Cache.CacheCategory;
import com.x.base.core.project.cache.Cache.CacheKey;
import com.x.base.core.project.cache.CacheManager;
import java.util.Optional;
public class ScriptFactory extends AbstractFactory {
static CacheCategory cache = new CacheCategory(Script.class);
public ScriptFactory(Business abstractBusiness) throws Exception {
super(abstractBusiness);
}
public Script flagWithPortalObject(String flag, String portalId) throws Exception {
CacheKey cacheKey = new CacheKey("flagObject", flag);
Optional<?> optional = CacheManager.get(cache, cacheKey);
if (optional.isPresent()) {
return (Script) optional.get();
} else {
EntityManager em = this.entityManagerContainer().get(Script.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Script> cq = cb.createQuery(Script.class);
Root<Script> root = cq.from(Script.class);
Predicate p = cb.equal(root.get(Script_.portal), portalId);
p = cb.and(p, cb.or(cb.equal(root.get(Script_.name), flag), cb.equal(root.get(Script_.alias), flag)));
List<Script> list = em.createQuery(cq.select(root).where(p)).setMaxResults(1).getResultList();
if (list.isEmpty()) {
return null;
} else {
Script o = list.get(0);
em.detach(o);
CacheManager.put(cache, cacheKey, o);
return o;
}
}
}
public Script pick(String id) throws Exception {
CacheKey cacheKey = new CacheKey(id);
Optional<?> optional = CacheManager.get(cache, cacheKey);
if (optional.isPresent()) {
return (Script) optional.get();
} else {
Script o = this.business().entityManagerContainer().find(id, Script.class);
if (null != o) {
this.business().entityManagerContainer().get(Script.class).detach(o);
CacheManager.put(cache, cacheKey, o);
return o;
}
return null;
}
}
public List<String> listWithPortal(String portalId) throws Exception {
EntityManager em = this.entityManagerContainer().get(Script.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Script> root = cq.from(Script.class);
Predicate p = cb.equal(root.get(Script_.portal), portalId);
List<String> list = em.createQuery(cq.select(root.get(Script_.id)).where(p)).getResultList();
return list;
}
@SuppressWarnings("unchecked")
public List<Script> listScriptNestedWithPortalWithFlag(Portal portal, String flag) throws Exception {
List<Script> list = new ArrayList<>();
CacheKey cacheKey = new CacheKey(flag, portal.getId(), "listScriptNestedWithPortalWithFlag");
Optional<?> optional = CacheManager.get(cache, cacheKey);
if (optional.isPresent()) {
list = (List<Script>) optional.get();
} else {
List<String> names = new ArrayList<>();
names.add(flag);
while (!names.isEmpty()) {
List<String> loops = new ArrayList<>();
for (String name : names) {
Script o = this.getScriptWithPortalWithFlag(portal, name);
if ((null != o) && (!list.contains(o))) {
list.add(o);
loops.addAll(o.getDependScriptList());
}
}
names = loops;
}
if (!list.isEmpty()) {
Collections.reverse(list);
CacheManager.put(cache, cacheKey, list);
}
}
return list;
}
private Script getScriptWithPortalWithFlag(Portal portal, String flag) throws Exception {
Script script = this.getWithPortalWithId(portal, flag);
if (null == script) {
script = this.getWithPortalWithAlias(portal, flag);
}
if (null == script) {
script = this.getWithPortalWithName(portal, flag);
}
return script;
}
private Script getWithPortalWithId(Portal portal, String flag) throws Exception {
EntityManager em = this.entityManagerContainer().get(Script.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Script> cq = cb.createQuery(Script.class);
Root<Script> root = cq.from(Script.class);
Predicate p = cb.equal(root.get(Script_.id), flag);
p = cb.and(p, cb.equal(root.get(Script_.portal), portal.getId()));
List<Script> list = em.createQuery(cq.where(p)).setMaxResults(1).getResultList();
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
private Script getWithPortalWithAlias(Portal portal, String flag) throws Exception {
EntityManager em = this.entityManagerContainer().get(Script.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Script> cq = cb.createQuery(Script.class);
Root<Script> root = cq.from(Script.class);
Predicate p = cb.equal(root.get(Script_.alias), flag);
p = cb.and(p, cb.equal(root.get(Script_.portal), portal.getId()));
List<Script> list = em.createQuery(cq.where(p)).setMaxResults(1).getResultList();
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
private Script getWithPortalWithName(Portal portal, String flag) throws Exception {
EntityManager em = this.entityManagerContainer().get(Script.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Script> cq = cb.createQuery(Script.class);
Root<Script> root = cq.from(Script.class);
Predicate p = cb.equal(root.get(Script_.name), flag);
p = cb.and(p, cb.equal(root.get(Script_.portal), portal.getId()));
List<Script> list = em.createQuery(cq.where(p)).setMaxResults(1).getResultList();
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
}
\ No newline at end of file
package com.x.portal.assemble.surface.factory;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import com.x.portal.assemble.surface.AbstractFactory;
import com.x.portal.assemble.surface.Business;
import com.x.portal.core.entity.Widget;
import com.x.portal.core.entity.Widget_;
import com.x.base.core.project.cache.Cache.CacheCategory;
import com.x.base.core.project.cache.Cache.CacheKey;
import com.x.base.core.project.cache.CacheManager;
import java.util.Optional;
public class WidgetFactory extends AbstractFactory {
static CacheCategory cache = new CacheCategory(Widget.class);
public WidgetFactory(Business abstractBusiness) throws Exception {
super(abstractBusiness);
}
public Widget pick(String id) throws Exception {
CacheKey cacheKey = new CacheKey(id);
Optional<?> optional = CacheManager.get(cache, cacheKey);
if (optional.isPresent()) {
return (Widget) optional.get();
} else {
Widget o = this.business().entityManagerContainer().find(id, Widget.class);
if (null != o) {
this.business().entityManagerContainer().get(Widget.class).detach(o);
CacheManager.put(cache, cacheKey, o);
return o;
}
return null;
}
}
public List<String> listWithPortal(String portalId) throws Exception {
EntityManager em = this.entityManagerContainer().get(Widget.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Widget> root = cq.from(Widget.class);
Predicate p = cb.equal(root.get(Widget_.portal), portalId);
List<String> list = em.createQuery(cq.select(root.get(Widget_.id)).where(p)).getResultList();
return list;
}
}
\ No newline at end of file
package com.x.portal.assemble.surface.jaxrs;
import java.util.Set;
import javax.ws.rs.ApplicationPath;
import com.x.base.core.project.jaxrs.AbstractActionApplication;
import com.x.portal.assemble.surface.jaxrs.file.FileAction;
import com.x.portal.assemble.surface.jaxrs.page.PageAction;
import com.x.portal.assemble.surface.jaxrs.portal.PortalAction;
import com.x.portal.assemble.surface.jaxrs.script.ScriptAction;
import com.x.portal.assemble.surface.jaxrs.widget.WidgetAction;
@ApplicationPath("jaxrs")
public class ActionApplication extends AbstractActionApplication {
public Set<Class<?>> getClasses() {
classes.add(PortalAction.class);
classes.add(WidgetAction.class);
classes.add(PageAction.class);
classes.add(ScriptAction.class);
classes.add(FileAction.class);
return classes;
}
}
package com.x.portal.assemble.surface.jaxrs;
import javax.servlet.annotation.WebFilter;
import com.x.base.core.project.jaxrs.AnonymousCipherManagerUserJaxrsFilter;
@WebFilter(urlPatterns = "/jaxrs/file/*", asyncSupported = true)
public class FileJaxrsFilter extends AnonymousCipherManagerUserJaxrsFilter {
}
package com.x.portal.assemble.surface.jaxrs;
import javax.servlet.annotation.WebFilter;
import com.x.base.core.project.jaxrs.AnonymousCipherManagerUserJaxrsFilter;
@WebFilter(urlPatterns = "/jaxrs/page/*", asyncSupported = true)
public class PageJaxrsFilter extends AnonymousCipherManagerUserJaxrsFilter {
}
package com.x.portal.assemble.surface.jaxrs;
import javax.servlet.annotation.WebFilter;
import com.x.base.core.project.jaxrs.AnonymousCipherManagerUserJaxrsFilter;
@WebFilter(urlPatterns = "/jaxrs/portal/*", asyncSupported = true)
public class PortalJaxrsFilter extends AnonymousCipherManagerUserJaxrsFilter {
}
package com.x.portal.assemble.surface.jaxrs;
import javax.servlet.annotation.WebFilter;
import com.x.base.core.project.jaxrs.AnonymousCipherManagerUserJaxrsFilter;
@WebFilter(urlPatterns = "/jaxrs/script/*", asyncSupported = true)
public class ScriptJaxrsFilter extends AnonymousCipherManagerUserJaxrsFilter {
}
package com.x.portal.assemble.surface.jaxrs;
import javax.servlet.annotation.WebFilter;
import com.x.base.core.project.jaxrs.AnonymousCipherManagerUserJaxrsFilter;
@WebFilter(urlPatterns = "/jaxrs/widget/*", asyncSupported = true)
public class WidgetJaxrsFilter extends AnonymousCipherManagerUserJaxrsFilter {
}
package com.x.portal.assemble.surface.jaxrs.file;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.base.core.project.exception.ExceptionEntityNotExist;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.base.core.project.jaxrs.WoFile;
import com.x.portal.assemble.surface.Business;
import com.x.portal.core.entity.File;
import com.x.portal.core.entity.File_;
import com.x.portal.core.entity.Portal;
import com.x.base.core.project.cache.Cache.CacheCategory;
import com.x.base.core.project.cache.Cache.CacheKey;
import com.x.base.core.project.cache.CacheManager;
import java.util.Optional;
class ActionContent extends StandardJaxrsAction {
private CacheCategory cache = new CacheCategory(File.class);
ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag, String portalFlag) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<Wo> result = new ActionResult<>();
Wo wo = null;
CacheKey cacheKey = new CacheKey(this.getClass(), flag, portalFlag);
Optional<?> optional = CacheManager.get(cache, cacheKey);
if (optional.isPresent()) {
wo = ((Wo) optional.get());
} else {
Business business = new Business(emc);
Portal portal = business.portal().pick(portalFlag);
if (null == portal) {
throw new ExceptionEntityNotExist(portalFlag, Portal.class);
}
String id = this.get(business, portal, flag);
if (StringUtils.isEmpty(id)) {
throw new ExceptionEntityNotExist(flag, File.class);
}
File file = business.file().pick(id);
byte[] bs = new byte[] {};
if (StringUtils.isNotEmpty(file.getData())) {
bs = Base64.decodeBase64(file.getData());
}
wo = new Wo(bs, this.contentType(false, file.getFileName()),
this.contentDisposition(false, file.getFileName()));
CacheManager.put(cache, cacheKey, wo);
}
result.setData(wo);
return result;
}
}
public static class Wo extends WoFile {
public Wo(byte[] bytes, String contentType, String contentDisposition) {
super(bytes, contentType, contentDisposition);
}
}
private String get(Business business, Portal portal, String flag) throws Exception {
EntityManager em = business.entityManagerContainer().get(File.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<File> root = cq.from(File.class);
Predicate p = cb.equal(root.get(File_.name), flag);
p = cb.or(p, cb.equal(root.get(File_.alias), flag));
p = cb.or(p, cb.equal(root.get(File_.id), flag));
p = cb.and(p, cb.equal(root.get(File_.portal), portal.getId()));
List<String> list = em.createQuery(cq.select(root.get(File_.id)).where(p)).setMaxResults(1).getResultList();
return list.isEmpty() ? null : list.get(0);
}
}
\ No newline at end of file
package com.x.portal.assemble.surface.jaxrs.file;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.exception.ExceptionEntityNotExist;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.base.core.project.jaxrs.WoFile;
import com.x.portal.assemble.surface.Business;
import com.x.portal.core.entity.File;
import com.x.portal.core.entity.File_;
import com.x.portal.core.entity.Portal;
import com.x.base.core.project.cache.Cache.CacheCategory;
import com.x.base.core.project.cache.Cache.CacheKey;
import com.x.base.core.project.cache.CacheManager;
import java.util.Optional;
class ActionDownload extends StandardJaxrsAction {
private CacheCategory cache = new CacheCategory(File.class);
ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag, String portalFlag) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<Wo> result = new ActionResult<>();
Wo wo = null;
CacheKey cacheKey = new CacheKey(this.getClass(), flag, portalFlag);
Optional<?> optional = CacheManager.get(cache, cacheKey);
if (optional.isPresent()) {
wo = ((Wo) optional.get());
} else {
Business business = new Business(emc);
Portal portal = business.portal().pick(portalFlag);
if (null == portal) {
throw new ExceptionEntityNotExist(portalFlag, Portal.class);
}
String id = this.get(business, portal, flag);
if (StringUtils.isEmpty(id)) {
throw new ExceptionEntityNotExist(flag, File.class);
}
File file = business.file().pick(id);
byte[] bs = new byte[] {};
if (StringUtils.isNotEmpty(file.getData())) {
bs = Base64.decodeBase64(file.getData());
}
wo = new Wo(bs, this.contentType(true, file.getFileName()),
this.contentDisposition(true, file.getFileName()));
CacheManager.put(cache, cacheKey, wo);
}
result.setData(wo);
return result;
}
}
public static class Wo extends WoFile {
public Wo(byte[] bytes, String contentType, String contentDisposition) {
super(bytes, contentType, contentDisposition);
}
}
private String get(Business business, Portal portal, String flag) throws Exception {
EntityManager em = business.entityManagerContainer().get(File.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<File> root = cq.from(File.class);
Predicate p = cb.equal(root.get(File_.name), flag);
p = cb.or(p, cb.equal(root.get(File_.alias), flag));
p = cb.or(p, cb.equal(root.get(File_.id), flag));
p = cb.and(p, cb.equal(root.get(File_.portal), portal.getId()));
List<String> list = em.createQuery(cq.select(root.get(File_.id)).where(p)).setMaxResults(1).getResultList();
return list.isEmpty() ? null : list.get(0);
}
}
\ No newline at end of file
package com.x.portal.assemble.surface.jaxrs.file;
import java.util.List;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.exception.ExceptionEntityNotExist;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.tools.ListTools;
import com.x.portal.assemble.surface.Business;
import com.x.portal.core.entity.File;
import com.x.portal.core.entity.Portal;
class ActionListWithPortal extends BaseAction {
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, String portalFlag) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
ActionResult<List<Wo>> result = new ActionResult<>();
Portal portal = business.portal().pick(portalFlag);
if (null == portal) {
throw new ExceptionEntityNotExist(portalFlag, Portal.class);
}
List<Wo> wos = emc.fetchEqual(File.class, Wo.copier, File.portal_FIELDNAME, portal.getId());
wos = business.file().sort(wos);
result.setData(wos);
return result;
}
}
public static class Wo extends File {
private static final long serialVersionUID = 3121411589636528551L;
static WrapCopier<File, Wo> copier = WrapCopierFactory.wo(File.class, Wo.class, null,
ListTools.toList(JpaObject.FieldsInvisible, File.data_FIELDNAME));
}
}
package com.x.portal.assemble.surface.jaxrs.file;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
abstract class BaseAction extends StandardJaxrsAction {
}
package com.x.portal.assemble.surface.jaxrs.file;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import com.x.base.core.project.annotation.JaxrsDescribe;
import com.x.base.core.project.annotation.JaxrsMethodDescribe;
import com.x.base.core.project.annotation.JaxrsParameterDescribe;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.http.HttpMediaType;
import com.x.base.core.project.jaxrs.ResponseFactory;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
@Path("file")
@JaxrsDescribe("文件操作")
public class FileAction extends StandardJaxrsAction {
private static Logger logger = LoggerFactory.getLogger(FileAction.class);
@JaxrsMethodDescribe(value = "列示指定站点的下所有可见的文件.", action = ActionListWithPortal.class)
@GET
@Path("list/portal/{portalFlag}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void listWithPortal(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("标识") @PathParam("portalFlag") String applicationFlag) {
ActionResult<List<ActionListWithPortal.Wo>> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionListWithPortal().execute(effectivePerson, applicationFlag);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "访问文件内容.义stream格式下载", action = ActionDownload.class)
@GET
@Path("{flag}/portal/{portalFlag}/download")
@Consumes(MediaType.APPLICATION_JSON)
public void download(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("标识") @PathParam("flag") String flag,
@JaxrsParameterDescribe("应用标识") @PathParam("portalFlag") String applicationFlag) {
ActionResult<ActionDownload.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionDownload().execute(effectivePerson, flag, applicationFlag);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "访问文件内容.", action = ActionContent.class)
@GET
@Path("{flag}/portal/{portalFlag}/content")
@Consumes(MediaType.APPLICATION_JSON)
public void content(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("标识") @PathParam("flag") String flag,
@JaxrsParameterDescribe("应用标识") @PathParam("portalFlag") String applicationFlag) {
ActionResult<ActionContent.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionContent().execute(effectivePerson, flag, applicationFlag);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
}
\ No newline at end of file
package com.x.portal.assemble.surface.jaxrs.page;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.tools.ListTools;
import com.x.portal.assemble.surface.Business;
import com.x.portal.core.entity.Page;
import com.x.portal.core.entity.Portal;
class ActionGet extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String id) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
ActionResult<Wo> result = new ActionResult<>();
Page page = business.page().pick(id);
if (null == page) {
throw new ExceptionPageNotExist(id);
}
Portal portal = business.portal().pick(page.getPortal());
if (null == portal) {
throw new ExceptionPortalNotExist(page.getPortal());
}
if (isNotLoginPage(id) && (!business.portal().visible(effectivePerson, portal))) {
throw new ExceptionPortalAccessDenied(effectivePerson.getDistinguishedName(), portal.getName(),
portal.getId());
}
Wo wo = Wo.copier.copy(page);
wo.setData(page.getDataOrMobileData());
result.setData(wo);
return result;
}
}
public static class Wo extends Page {
private static final long serialVersionUID = -8067704098385000667L;
/** 不输出data数据,单独处理 */
static WrapCopier<Page, Wo> copier = WrapCopierFactory.wo(Page.class, Wo.class, null,
ListTools.toList(JpaObject.FieldsInvisible, Page.data_FIELDNAME, Page.mobileData_FIELDNAME));
}
}
\ No newline at end of file
package com.x.portal.assemble.surface.jaxrs.page;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.tools.ListTools;
import com.x.portal.assemble.surface.Business;
import com.x.portal.core.entity.Page;
import com.x.portal.core.entity.Portal;
class ActionGetMobile extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String id) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
ActionResult<Wo> result = new ActionResult<>();
Page page = business.page().pick(id);
if (null == page) {
throw new ExceptionPageNotExist(id);
}
Portal portal = business.portal().pick(page.getPortal());
if (null == portal) {
throw new ExceptionPortalNotExist(page.getPortal());
}
if (isNotLoginPage(id) && (!business.portal().visible(effectivePerson, portal))) {
throw new ExceptionPortalAccessDenied(effectivePerson.getDistinguishedName(), portal.getName(),
portal.getId());
}
Wo wo = Wo.copier.copy(page);
wo.setData(page.getMobileDataOrData());
result.setData(wo);
return result;
}
}
public static class Wo extends Page {
private static final long serialVersionUID = -8067704098385000667L;
/** 不输出data数据,单独处理 */
static WrapCopier<Page, Wo> copier = WrapCopierFactory.wo(Page.class, Wo.class, null,
ListTools.toList(JpaObject.FieldsInvisible, Page.data_FIELDNAME, Page.mobileData_FIELDNAME));
}
}
\ No newline at end of file
package com.x.portal.assemble.surface.jaxrs.page;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.tools.ListTools;
import com.x.portal.assemble.surface.Business;
import com.x.portal.core.entity.Page;
import com.x.portal.core.entity.Portal;
import com.x.base.core.project.cache.Cache.CacheKey;
import com.x.base.core.project.cache.CacheManager;
import java.util.Optional;
class ActionGetWithPortal extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag, String portalFlag) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
Wo wo = null;
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
CacheKey cacheKey = new CacheKey(this.getClass(), flag, portalFlag);
Optional<?> optional = CacheManager.get(pageCache, cacheKey);
if (optional.isPresent()) {
wo = (Wo) optional.get();
Portal portal = business.portal().pick(wo.getPortal());
if (isNotLoginPage(flag) && (!business.portal().visible(effectivePerson, portal))) {
throw new ExceptionPortalAccessDenied(effectivePerson.getDistinguishedName(), portal.getName(),
portal.getId());
}
} else {
Portal portal = business.portal().pick(portalFlag);
if (null == portal) {
throw new ExceptionPortalNotExist(portalFlag);
}
if (isNotLoginPage(flag) && (!business.portal().visible(effectivePerson, portal))) {
throw new ExceptionPortalAccessDenied(effectivePerson.getDistinguishedName(), portal.getName(),
portal.getId());
}
Page page = business.page().pick(portal, flag);
if (null == page) {
throw new ExceptionPageNotExist(flag);
}
wo = Wo.copier.copy(page);
wo.setData(page.getDataOrMobileData());
CacheManager.put(pageCache, cacheKey, wo);
}
result.setData(wo);
return result;
}
}
public static class Wo extends Page {
private static final long serialVersionUID = 3454132769791427909L;
static WrapCopier<Page, Wo> copier = WrapCopierFactory.wo(Page.class, Wo.class, null,
ListTools.toList(JpaObject.FieldsInvisible, Page.data_FIELDNAME, Page.mobileData_FIELDNAME));
}
}
\ No newline at end of file
package com.x.portal.assemble.surface.jaxrs.page;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.tools.ListTools;
import com.x.portal.assemble.surface.Business;
import com.x.portal.core.entity.Page;
import com.x.portal.core.entity.Portal;
import com.x.base.core.project.cache.Cache.CacheKey;
import com.x.base.core.project.cache.CacheManager;
import java.util.Optional;
class ActionGetWithPortalMobile extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag, String portalFlag) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
Wo wo = null;
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
CacheKey cacheKey = new CacheKey(this.getClass(), flag, portalFlag);
Optional<?> optional = CacheManager.get(pageCache, cacheKey);
if (optional.isPresent()) {
wo = (Wo) optional.get();
Portal portal = business.portal().pick(wo.getPortal());
if (isNotLoginPage(flag) && (!business.portal().visible(effectivePerson, portal))) {
throw new ExceptionPortalAccessDenied(effectivePerson.getDistinguishedName(), portal.getName(),
portal.getId());
}
} else {
Portal portal = business.portal().pick(portalFlag);
if (null == portal) {
throw new ExceptionPortalNotExist(portalFlag);
}
if (isNotLoginPage(flag) && (!business.portal().visible(effectivePerson, portal))) {
throw new ExceptionPortalAccessDenied(effectivePerson.getDistinguishedName(), portal.getName(),
portal.getId());
}
Page page = business.page().pick(portal, flag);
wo = Wo.copier.copy(page);
wo.setData(page.getMobileDataOrData());
CacheManager.put(pageCache, cacheKey, wo);
}
result.setData(wo);
return result;
}
}
public static class Wo extends Page {
private static final long serialVersionUID = 3454132769791427909L;
static WrapCopier<Page, Wo> copier = WrapCopierFactory.wo(Page.class, Wo.class, null,
ListTools.toList(JpaObject.FieldsInvisible, Page.data_FIELDNAME, Page.mobileData_FIELDNAME));
}
}
\ No newline at end of file
package com.x.portal.assemble.surface.jaxrs.page;
import java.util.ArrayList;
import java.util.List;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.portal.assemble.surface.Business;
import com.x.portal.core.entity.Page;
import com.x.portal.core.entity.Portal;
class ActionList extends BaseAction {
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, String portalId) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
ActionResult<List<Wo>> result = new ActionResult<>();
List<Wo> wos = new ArrayList<>();
Portal portal = business.portal().pick(portalId);
if (null == portal) {
throw new ExceptionPortalNotExist(portalId);
}
if (!business.portal().visible(effectivePerson, portal)) {
throw new ExceptionPortalAccessDenied(effectivePerson.getDistinguishedName(), portal.getName(),
portal.getId());
}
List<String> ids = business.page().listWithPortal(portal.getId());
for (String id : ids) {
Page o = business.page().pick(id);
if (null == o) {
throw new ExceptionPageNotExist(id);
} else {
wos.add(Wo.copier.copy(o));
}
}
result.setData(wos);
return result;
}
}
public static class Wo extends Page {
private static final long serialVersionUID = 3454132769791427909L;
static WrapCopier<Page, Wo> copier = WrapCopierFactory.wo(Page.class, Wo.class,
JpaObject.singularAttributeField(Page.class, true, true), JpaObject.FieldsInvisible);
}
}
\ No newline at end of file
package com.x.portal.assemble.surface.jaxrs.page;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.portal.core.entity.Page;
import com.x.base.core.project.cache.Cache.CacheCategory;
abstract class BaseAction extends StandardJaxrsAction {
CacheCategory pageCache = new CacheCategory(Page.class);
protected boolean isNotLoginPage(String id) throws Exception {
return !(Config.portal().getIndexPage().getEnable()
&& StringUtils.equals(id, Config.portal().getIndexPage().getPage()));
}
}
package com.x.portal.assemble.surface.jaxrs.page;
import com.x.base.core.project.exception.PromptException;
class ExceptionPageNotExist extends PromptException {
private static final long serialVersionUID = -4908883340253465376L;
ExceptionPageNotExist(String id) {
super("指定的页面不存在:{}.", id);
}
}
package com.x.portal.assemble.surface.jaxrs.page;
import com.x.base.core.project.exception.PromptException;
class ExceptionPortalAccessDenied extends PromptException {
private static final long serialVersionUID = -4908883340253465376L;
ExceptionPortalAccessDenied(String person, String name, String id) {
super("用户: {}, 访问站点: {}, id: {}, 失败,权限不足.", person, name, id);
}
}
package com.x.portal.assemble.surface.jaxrs.page;
import com.x.base.core.project.exception.PromptException;
class ExceptionPortalNotExist extends PromptException {
private static final long serialVersionUID = -4908883340253465376L;
ExceptionPortalNotExist(String id) {
super("指定的站点不存在:{}.", id);
}
}
package com.x.portal.assemble.surface.jaxrs.page;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import com.x.base.core.project.annotation.JaxrsDescribe;
import com.x.base.core.project.annotation.JaxrsMethodDescribe;
import com.x.base.core.project.annotation.JaxrsParameterDescribe;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.http.HttpMediaType;
import com.x.base.core.project.jaxrs.ResponseFactory;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
@Path("page")
@JaxrsDescribe("页面")
public class PageAction extends StandardJaxrsAction {
private static Logger logger = LoggerFactory.getLogger(PageAction.class);
@JaxrsMethodDescribe(value = "获取Page内容.", action = ActionGet.class)
@GET
@Path("{id}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void get(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("标识") @PathParam("id") String id) {
ActionResult<ActionGet.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionGet().execute(effectivePerson, id);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "获取Page内容Mobile.", action = ActionGetMobile.class)
@GET
@Path("{id}/mobile")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void getMobile(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("标识") @PathParam("id") String id) {
ActionResult<ActionGetMobile.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionGetMobile().execute(effectivePerson, id);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "列示属于指定Portal的Page.", action = ActionList.class)
@GET
@Path("list/portal/{portal}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void list(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("门户") @PathParam("portal") String portal) {
ActionResult<List<ActionList.Wo>> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionList().execute(effectivePerson, portal);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "列示属于指定Portal的Page,其中Portal可以用name,alias和id标识,Page为在此Portal下的页面.", action = ActionGetWithPortal.class)
@GET
@Path("{flag}/portal/{portalFlag}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void getWithPortal(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("标识") @PathParam("flag") String flag,
@JaxrsParameterDescribe("门户标识") @PathParam("portalFlag") String portalFlag) {
ActionResult<ActionGetWithPortal.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionGetWithPortal().execute(effectivePerson, flag, portalFlag);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "列示属于指定Portal的Page,其中Portal可以用name,alias和id标识,Page为在此Portal下的页面Mobile.", action = ActionGetWithPortalMobile.class)
@GET
@Path("{flag}/portal/{portalFlag}/mobile")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void getWithPortalMobile(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("标识") @PathParam("flag") String flag,
@JaxrsParameterDescribe("门户标识") @PathParam("portalFlag") String portalFlag) {
ActionResult<ActionGetWithPortalMobile.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionGetWithPortalMobile().execute(effectivePerson, flag, portalFlag);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
}
\ No newline at end of file
package com.x.portal.assemble.surface.jaxrs.portal;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.tools.ListTools;
import com.x.portal.assemble.surface.Business;
import com.x.portal.core.entity.Portal;
class ActionGet extends BaseAction {
/**
* 1.身份在可使用列表中 2.部门在可使用部门中 3.公司在可使用公司中 4.没有限定身份,部门或者公司 5.个人在应用管理员中
* 6.是此Portal的创建人员 7.个人有Manage权限 8.个人拥有PortalManager
*/
ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
ActionResult<Wo> result = new ActionResult<>();
Portal o = business.portal().pick(flag);
if (null == o) {
throw new ExceptionPortalNotExist(flag);
}
if (!business.portal().visible(effectivePerson, o)) {
throw new ExceptionPortalAccessDenied(effectivePerson.getDistinguishedName(), o.getName(), o.getId());
}
Wo wo = Wo.copier.copy(o);
result.setData(wo);
return result;
}
}
public static class Wo extends Portal {
private static final long serialVersionUID = 727247858785981924L;
static WrapCopier<Portal, Wo> copier = WrapCopierFactory.wo(Portal.class, Wo.class, null,
ListTools.toList(JpaObject.FieldsInvisible));
}
}
\ No newline at end of file
package com.x.portal.assemble.surface.jaxrs.portal;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoFile;
import com.x.portal.assemble.surface.Business;
import com.x.portal.core.entity.Portal;
class ActionIcon extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String id) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
ActionResult<Wo> result = new ActionResult<>();
Portal o = business.portal().pick(id);
if (null == o) {
throw new ExceptionPortalNotExist(id);
}
// if (!business.portal().visible(effectivePerson, o)) {
// throw new
// ExceptionPortalAccessDenied(effectivePerson.getDistinguishedName(),
// o.getName(), o.getId());
// }
byte[] bs = Base64
.decodeBase64(StringUtils.isEmpty(o.getIcon()) ? DEFAULT_PORTAL_ICON_BASE64 : o.getIcon());
Wo wo = new Wo(bs, this.contentType(false, "icon.png"), this.contentDisposition(false, "icon.png"));
result.setData(wo);
return result;
}
}
public static class Wo extends WoFile {
public Wo(byte[] bytes, String contentType, String contentDisposition) {
super(bytes, contentType, contentDisposition);
}
}
}
package com.x.portal.assemble.surface.jaxrs.portal;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WrapString;
import com.x.portal.assemble.surface.Business;
import com.x.portal.core.entity.Portal;
class ActionIconBase64 extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String id) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
ActionResult<Wo> result = new ActionResult<>();
Portal o = business.portal().pick(id);
if (null == o) {
throw new ExceptionPortalNotExist(id);
}
Wo wo = new Wo();
wo.setValue(StringUtils.isEmpty(o.getIcon()) ? DEFAULT_PORTAL_ICON_BASE64 : o.getIcon());
result.setData(wo);
return result;
}
}
public static class Wo extends WrapString {
}
}
package com.x.portal.assemble.surface.jaxrs.portal;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.organization.OrganizationDefinition;
import com.x.portal.assemble.surface.Business;
import com.x.portal.core.entity.Portal;
import com.x.portal.core.entity.Portal_;
class ActionList extends BaseAction {
/**
* 1.身份在可使用列表中 2.部门在可使用部门中 3.公司在可使用公司中 4.没有限定身份,部门或者公司 5.个人在应用管理员中
* 6.是此Portal的创建人员 7.个人有Manage权限 8.个人拥有PortalManager
*/
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<List<Wo>> result = new ActionResult<>();
List<Wo> wos = new ArrayList<>();
Business business = new Business(emc);
List<String> ids = this.list(business, effectivePerson);
for (String id : ids) {
Portal o = business.portal().pick(id);
if (null == o) {
throw new ExceptionPortalNotExist(id);
} else {
wos.add(Wo.copier.copy(o));
}
}
wos = wos.stream().sorted(Comparator.comparing(Portal::getName, Comparator.nullsLast(String::compareTo)))
.collect(Collectors.toList());
result.setData(wos);
return result;
}
}
private List<String> list(Business business, EffectivePerson effectivePerson) throws Exception {
EntityManager em = business.entityManagerContainer().get(Portal.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Portal> root = cq.from(Portal.class);
Predicate p = cb.or(cb.isNull(root.get(Portal_.pcClient)), cb.isTrue(root.get(Portal_.pcClient)));
if (effectivePerson.isNotManager()
&& (!business.organization().person().hasRole(effectivePerson, OrganizationDefinition.PortalManager))) {
List<String> identities = business.organization().identity()
.listWithPerson(effectivePerson.getDistinguishedName());
List<String> units = business.organization().unit()
.listWithPersonSupNested(effectivePerson.getDistinguishedName());
Predicate who = cb.equal(root.get(Portal_.creatorPerson), effectivePerson.getDistinguishedName());
who = cb.or(who, cb.isMember(effectivePerson.getDistinguishedName(), root.get(Portal_.controllerList)));
who = cb.or(who, cb.and(cb.isEmpty(root.get(Portal_.availableIdentityList)),
cb.isEmpty(root.get(Portal_.availableUnitList))));
who = cb.or(who, root.get(Portal_.availableIdentityList).in(identities));
who = cb.or(who, root.get(Portal_.availableUnitList).in(units));
p = cb.and(p, who);
}
cq.select(root.get(Portal_.id)).where(p).distinct(true);
return em.createQuery(cq).getResultList();
}
public static class Wo extends Portal {
private static final long serialVersionUID = -5240059905993945729L;
static WrapCopier<Portal, Wo> copier = WrapCopierFactory.wo(Portal.class, Wo.class,
JpaObject.singularAttributeField(Portal.class, true, false), JpaObject.FieldsInvisible);
}
}
\ No newline at end of file
package com.x.portal.assemble.surface.jaxrs.portal;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
abstract class BaseAction extends StandardJaxrsAction {
protected static final String DEFAULT_PORTAL_ICON_BASE64 = "iVBORw0KGgoAAAANSUhEUgAAAJAAAACQCAYAAADnRuK4AAAKBklEQVR42u1dy04bSxAdkkh3kVWUZaRId4OQIiSk3F1WSFmw4RMi5SP4gghd+APEkjUsEokF2fJaEds4UUwCifMgL0AEEoKDHZhbx/T4GrCxPZ7p6Z4+JZXGGHvc3XWmurq7Hp7nGPm+fy2Xy/U+e/ZseGVlZUSuk3Kdluuc8JK8zsu1KNcduR6B1eui+t8SPqu+M6nuMYx74t4eKT20urp6XYQ7lMlk/hVBPxZeEy4L+zFxWf3GY/wmfhttoCQsofX19b9EeIPCj4QXYwZLJ6BaVG0aRBspKcO0jDztD9S0UjIAMK24hLaizdROydkxV0QA90UYUyKMAwtA05BV26fQF/SJko1f2/wtAz4uA79pK2guARP6NI4+UtIRkwxsH55U4UragNOAK6qvfZR8l5TNZgfUcvnYAeCc10jo8zTGgEjokGTw7srgzboGmkt4FmNCZLSgfD5/QwZrwkWN06ZGmsAYESkXV1U9MkAPhbcIlpZA2sJYYcyInFMDuV9ttBEgnTHGrN9lrXNVnqRRR1ZWsa3YMIYYS6fAk8vlbknH5wmAyKa1eYypKyusIen0NgUfOW9jbNM8ZV2TTo5JJ08o7Ng0EcZ2LHVuJYVC4aZ0bIFC1sYLGPO0rLJuCxcoVO2MMb9tu7F8J40HnzYd0EIGtp5j3ZMO7FKQiYNoF7KwbaUFf+NDCtAYPoRMbAIPNwfN3HQcNn7aouYxWxMZO50pg5k2jwU2kXGGNZaLXG1Z5z5rxhJfbRJyn8fCfaLENxvV8QR3mC3esU702APnLhSC9TyW2Kk6D0bTcQCr/RQfvid0yUiXK4g2fyLlSUhnsBQ6pWnxbFRuqBz0dIJoVIcDPI8p0h0V2x/X1NXD6Ak3oj1iCRlCLBIH15mp7GGk4EE0JIP+3ApejDQCFiG1OhouS0n/48eP/v7+vn94eOj//v2bLIyx2Nvbq45NNpvVBaSJqKauuzpi1d+8eeP/+fPHJ11OGKONjQ0tsfiRJHTQkSXj7du3REYHdHJyUn3gdGQF6dZBbCDuRq6urvrHx8dERQhNhCk/bvl0lZ8ICY7ibuCXL1+IhpC0ubmpQwtNhwVPnw7bBwZiIzo6Oqoa0+T9qiHdiH7+/KkrL1FfGABN6bD2G01fmOM1rjaM50wm03Cc8JBpasNUR+BR2VC1HFk0m98JnLNcqVQujBPe03XE0VH2WKSb1TUwBJAVAAKPt3vmdUWngzwBZAeAgIm2kqGrDPA+AUQANbDF7htjPIcBkMvLcxMA1NKYVuWRDgggAqhZbY9LC8Sggoxu1UwAWaWBMI09uOzgdI4AIoBaaKG5huBRxdpKBBAB1IJLDYvmrZxW+vMJIAKoDR5sBKBHBNDl9P79e6jwhvz69WuXAPSoEYAWCaDL6d27d0374RiAFi8s31cSKlBLAFkJoPKZ5bzKHu+7BKDt7e2mbhKtAAQBB/7K3759cxFA/pl4elVX3SkAFQqFqq9NQLu7u1UwBLy1tdUUQPh//fdcBBAwU6+BnrgOoJcvX17wwSGALuXH9Qb0misA+vz5s18sFqv+xBA6Xgd/n1PRtf8F0SIBgAA+vAa/evXKVQCt1WcZK7sCoLW1tY7bCM8/GtEXDWlgB7l+epN0UyCArAUQtHZvkBjcOQCtr69XNwbBmJLwXj6fr70HbgYg3CP4DIDjKoCqicvlxYiLAKo3oBFahPdgz9Q79jcDEI3oGo9AA00SQARQSA00CQDNuAgg7PMgJg384cOH2uoqeO/Xr19NAQQBB5/7+vWrywCawRT2lEY0jeiQ/BQaaJkAIoBCaqBlaKA8AUQAheQ8NFDRRQB9//69Gi4M/vTpU215HrxX3wYCqKkGKkID7XAV1tkqjACq8Q400BEBRACF1EBHzgIIp+/YjQa/ePGilqMxeC/YYSaAWgDI1SmMRnR0U1iRACKAujGiuYwngLpaxi8RQARQSA20lEg4MwGUGgDNacnEahKAkO0dwu6EA+Hh4LTZZyB0B6ewaefcOWwgq9w5XHMoI4CidygbJoAIoNAura451RNAETvV+46F9RBAEYf1uBZYSABFHFhoU2jzwcGBE4xoWKtCm21JrsA80eYA6HxyhSECiAAKnd7FlgRTBJAxACpfyBdtQ4o7AsgYAC0ak2SzUaFduJOiFCaB839ZUIzJeUKGNJOSbCaS5herjkaEyIhyuUwWblZT9sePH+ak+U0q0XiUp9iuETwLjEk0nlSpA6SSw1NG6oxg/yRRFrRpqYOkiq3UB/SR2iPYQ0FqPaOKrSRR7ilgZMYolUpERwuCd2RS4GlZ7imJgnPneWNjo5rDGYF/KGsdNTdaDkdFWFHiIYiakWoGodhwqcWUn6B8powreambIYi4CPdO89i1VfLS11x0lwCyg9suuqu77DcBZA2Pt103HkXm5QsVAogAUlwBJrxOKGljmgAyiqe8Tkm+1Cfz3jEB5DaAFAb6vDCUdNBhWMYOLbb5kYkVWwL1HESZxrVHc/730AYsv1F7w1IQTXthSQQxYOFSs5p+1zTa29vzLX0YB7xuSG4ya1OH4U9sKgUlFSziWa9bEtV71yZbCFOXqVSf9cwG2wey96IgueGELR1//vx5Q+crE07PEz6G6JQnvKgon8/fEDRu2dJ55DjEGZIJQEIb4DR3viKi4dpnCzL3oiS56UO6l7rBkLUXNcnD1JOU4z1Zr8M8ZO3FQXLz/rQecZBPjywgYy9OEvU2yoFO7dQ16sVNot6uyg/Nc8BTB555yNbTQblc7pb86DYHPjW8DZl6Ogmx0cInHHzrNc/JmTh3nSQNGKMQrOcxLylS2c0WKARreaGWZSwpKhQKN6UhBQrDOi5Adp4JJI25nWZH/DQ6yENmnkkkVvwdadguBWQ8eHYhK89Eymaz96SRhxSUsXwIGXkmk0pczuMOA48pqonBbSAFImoigzSPNeCpn85oE5lh8xg/bbUwrLk6S3C1ZazB3MkSn/tEyezzGLdU73KzkTvWGneYjdkkjPjYY4wHsPEejGKMEz+eiPsUn64g8bhkJHaqnoBxfYtOadE6g2n35zFgSruq3GO56djd5uCoNk9CQ1dp/Yz2CBc9EbsDvEXaqAexSDYFLyYZ9Iexii30xmZCNCRCatOYlyiiPD0TkUeMppEymcw/tmUFiTtLRmSJDlwilZ9o2kWNpPo83XV+HtJpuj2Vs9GFFVtF9bWPko+YVPbY8TQe0Ko+jXecDZUUatV2RWXUn0qqtkdEoEHbp9CXtpN4kyLXStdRQUaVqipZAJwS2oo2tyxcQtJLqmgeKi8+UhttZQMAU1ZtQZsGmxZrI5mpnXDAiBrncn0iAlyLGVS49xp+S/3mELVM+uyna7lcrlf5bY/IdVJ4Rl4/leuyXPNyLcp1R65HYPW6qP63rD47g++qewzjnql2o2hC/wERfmOiMxH+AQAAAABJRU5ErkJggg==";
}
package com.x.portal.assemble.surface.jaxrs.portal;
import com.x.base.core.project.exception.PromptException;
class ExceptionPortalAccessDenied extends PromptException {
private static final long serialVersionUID = -4908883340253465376L;
ExceptionPortalAccessDenied(String person, String name, String id) {
super("用户: {}, 访问站点: {}, id: {}, 失败,权限不足.", person, name, id);
}
}
package com.x.portal.assemble.surface.jaxrs.portal;
import com.x.base.core.project.exception.PromptException;
class ExceptionPortalNotExist extends PromptException {
private static final long serialVersionUID = -4908883340253465376L;
ExceptionPortalNotExist(String id) {
super("指定的站点不存在:{}.", id);
}
}
package com.x.portal.assemble.surface.jaxrs.portal;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.util.List;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import org.apache.commons.codec.binary.Base64;
import com.x.base.core.project.annotation.JaxrsDescribe;
import com.x.base.core.project.annotation.JaxrsMethodDescribe;
import com.x.base.core.project.annotation.JaxrsParameterDescribe;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.http.HttpMediaType;
import com.x.base.core.project.jaxrs.ResponseFactory;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
@Path("portal")
@JaxrsDescribe("门户")
public class PortalAction extends StandardJaxrsAction {
private static Logger logger = LoggerFactory.getLogger(PortalAction.class);
@JaxrsMethodDescribe(value = "获取单个的Portal.", action = ActionGet.class)
@GET
@Path("{flag}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void get(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("标识") @PathParam("flag") String flag) {
ActionResult<ActionGet.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionGet().execute(effectivePerson, flag);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "获取Portal的图标.", action = ActionIcon.class)
@GET
@Path("{id}/icon")
@Consumes(MediaType.APPLICATION_JSON)
public void icon(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("标识") @PathParam("id") String id) {
ActionResult<ActionIcon.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionIcon().execute(effectivePerson, id);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "获取Portal的图标Base64编码.", action = ActionIconBase64.class)
@GET
@Path("{id}/icon/base64")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void iconBase64(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("标识") @PathParam("id") String id) {
ActionResult<ActionIconBase64.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionIconBase64().execute(effectivePerson, id);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "列示当前用户所有可见的Portal.", action = ActionList.class)
@GET
@Path("list")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void list(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request) {
ActionResult<List<ActionList.Wo>> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionList().execute(effectivePerson);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
public void test() throws Exception {
try (FileInputStream in = new FileInputStream(new File("d:/a.png"));
ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
BufferedImage image = ImageIO.read(in);
ImageIO.write(image, "png", baos);
String icon = Base64.encodeBase64String(baos.toByteArray());
}
}
}
\ No newline at end of file
package com.x.portal.assemble.surface.jaxrs.script;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;
import com.google.gson.JsonElement;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.tools.ListTools;
import com.x.portal.assemble.surface.Business;
import com.x.portal.core.entity.Portal;
import com.x.portal.core.entity.Script;
class ActionFlag extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag, String portalId, JsonElement jsonElement)
throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
ActionResult<Wo> result = new ActionResult<>();
Portal portal = business.portal().pick(portalId);
if (null == portal) {
throw new ExceptionPortalNotExist(portalId);
}
if (!business.portal().visible(effectivePerson, portal)) {
throw new ExceptionPortalAccessDenied(effectivePerson.getDistinguishedName(), portal.getName(),
portal.getId());
}
List<Script> list = new ArrayList<>();
for (Script o : business.script().listScriptNestedWithPortalWithFlag(portal, flag)) {
if ((!this.contains(wi.getImportedList(), o.getAlias()))
&& (!this.contains(wi.getImportedList(), o.getName()))
&& (!this.contains(wi.getImportedList(), o.getId()))) {
list.add(o);
}
}
StringBuffer buffer = new StringBuffer();
List<String> imported = new ArrayList<>();
for (Script o : list) {
buffer.append(o.getText());
buffer.append(SystemUtils.LINE_SEPARATOR);
imported.add(o.getId());
if (StringUtils.isNotEmpty(o.getName())) {
imported.add(o.getName());
}
if (StringUtils.isNotEmpty(o.getAlias())) {
imported.add(o.getAlias());
}
}
Wo wo = new Wo();
wo.setImportedList(imported);
wo.setText(buffer.toString());
result.setData(wo);
return result;
}
}
private boolean contains(List<String> list, String value) {
if (StringUtils.isEmpty(value)) {
return false;
} else {
return ListTools.contains(list, value);
}
}
public static class Wi extends GsonPropertyObject {
@FieldDescribe("已经导入的脚本")
private List<String> importedList;
public List<String> getImportedList() {
return importedList;
}
public void setImportedList(List<String> importedList) {
this.importedList = importedList;
}
}
public static class Wo extends Script {
private static final long serialVersionUID = -8067704098385000667L;
static WrapCopier<Script, Wo> copier = WrapCopierFactory.wo(Script.class, Wo.class, null,
ListTools.toList(JpaObject.FieldsInvisible));
private List<String> importedList;
public List<String> getImportedList() {
return importedList;
}
public void setImportedList(List<String> importedList) {
this.importedList = importedList;
}
}
}
package com.x.portal.assemble.surface.jaxrs.script;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.tools.ListTools;
import com.x.portal.assemble.surface.Business;
import com.x.portal.core.entity.Portal;
import com.x.portal.core.entity.Script;
class ActionGet extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String id) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
ActionResult<Wo> result = new ActionResult<>();
Script script = business.script().pick(id);
if (null == script) {
throw new ExceptionScriptNotExist(id);
}
Portal portal = business.portal().pick(script.getPortal());
if (null == portal) {
throw new ExceptionPortalNotExist(script.getPortal());
}
if (!business.portal().visible(effectivePerson, portal)) {
throw new ExceptionPortalAccessDenied(effectivePerson.getDistinguishedName(), portal.getName(),
portal.getId());
}
Wo wo = Wo.copier.copy(script);
result.setData(wo);
return result;
}
}
public static class Wo extends Script {
private static final long serialVersionUID = 727247858785981924L;
static WrapCopier<Script, Wo> copier = WrapCopierFactory.wo(Script.class, Wo.class, null,
ListTools.toList(JpaObject.FieldsInvisible));
}
}
\ No newline at end of file
package com.x.portal.assemble.surface.jaxrs.script;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.tools.ListTools;
import com.x.portal.assemble.surface.Business;
import com.x.portal.core.entity.Portal;
import com.x.portal.core.entity.Script;
import com.x.base.core.project.cache.Cache.CacheKey;
import com.x.base.core.project.cache.CacheManager;
import java.util.Optional;
class ActionGetImported extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag, String portalId) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<Wo> result = new ActionResult<>();
Wo wo = new Wo();
CacheKey cacheKey = new CacheKey(this.getClass(), flag, portalId);
Optional<?> optional = CacheManager.get(cache, cacheKey);
if (optional.isPresent()) {
wo = (Wo) optional.get();
} else {
Business business = new Business(emc);
Portal portal = business.portal().pick(portalId);
if (null == portal) {
throw new ExceptionPortalNotExist(portalId);
}
if (!business.portal().visible(effectivePerson, portal)) {
throw new ExceptionPortalAccessDenied(effectivePerson.getDistinguishedName(), portal.getName(),
portal.getId());
}
List<Script> list = new ArrayList<>();
for (Script o : business.script().listScriptNestedWithPortalWithFlag(portal, flag)) {
list.add(o);
}
StringBuffer buffer = new StringBuffer();
List<String> imported = new ArrayList<>();
for (Script o : list) {
buffer.append(o.getText());
buffer.append(System.lineSeparator());
imported.add(o.getId());
if (StringUtils.isNotEmpty(o.getName())) {
imported.add(o.getName());
}
if (StringUtils.isNotEmpty(o.getAlias())) {
imported.add(o.getAlias());
}
}
wo.setImportedList(imported);
wo.setText(buffer.toString());
CacheManager.put(cache, cacheKey, wo);
}
result.setData(wo);
return result;
}
}
public static class Wo extends Script {
private static final long serialVersionUID = -8067704098385000667L;
static WrapCopier<Script, Wo> copier = WrapCopierFactory.wo(Script.class, Wo.class, null,
ListTools.toList(JpaObject.FieldsInvisible));
private List<String> importedList;
public List<String> getImportedList() {
return importedList;
}
public void setImportedList(List<String> importedList) {
this.importedList = importedList;
}
}
}
package com.x.portal.assemble.surface.jaxrs.script;
import java.util.ArrayList;
import java.util.List;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.portal.assemble.surface.Business;
import com.x.portal.core.entity.Portal;
import com.x.portal.core.entity.Script;
class ActionList extends BaseAction {
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, String portalId) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
ActionResult<List<Wo>> result = new ActionResult<>();
List<Wo> wos = new ArrayList<>();
Portal portal = business.portal().pick(portalId);
if (null == portal) {
throw new ExceptionPortalNotExist(portalId);
}
if (!business.portal().visible(effectivePerson, portal)) {
throw new ExceptionPortalAccessDenied(effectivePerson.getDistinguishedName(), portal.getName(),
portal.getId());
}
List<String> ids = business.script().listWithPortal(portal.getId());
for (String id : ids) {
Script o = business.script().pick(id);
if (null == o) {
throw new ExceptionScriptNotExist(id);
} else {
wos.add(Wo.copier.copy(o));
}
}
result.setData(wos);
return result;
}
}
public static class Wo extends Script {
private static final long serialVersionUID = -5240059905993945729L;
static WrapCopier<Script, Wo> copier = WrapCopierFactory.wo(Script.class, Wo.class,
JpaObject.singularAttributeField(Script.class, true, true), JpaObject.FieldsInvisible);
}
}
\ No newline at end of file
package com.x.portal.assemble.surface.jaxrs.script;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.portal.core.entity.Script;
import com.x.base.core.project.cache.Cache.CacheCategory;
abstract class BaseAction extends StandardJaxrsAction {
protected CacheCategory cache = new CacheCategory(Script.class);
}
package com.x.portal.assemble.surface.jaxrs.script;
import com.x.base.core.project.exception.PromptException;
class ExceptionPortalAccessDenied extends PromptException {
private static final long serialVersionUID = -4908883340253465376L;
ExceptionPortalAccessDenied(String person, String name, String id) {
super("用户: {}, 访问站点: {}, id: {}, 失败,权限不足.", person, name, id);
}
}
package com.x.portal.assemble.surface.jaxrs.script;
import com.x.base.core.project.exception.PromptException;
class ExceptionPortalNotExist extends PromptException {
private static final long serialVersionUID = -4908883340253465376L;
ExceptionPortalNotExist(String id) {
super("指定的站点不存在:{}.", id);
}
}
package com.x.portal.assemble.surface.jaxrs.script;
import com.x.base.core.project.exception.PromptException;
class ExceptionScriptNotExist extends PromptException {
private static final long serialVersionUID = -4908883340253465376L;
ExceptionScriptNotExist(String id) {
super("指定的脚本不存在:{}.", id);
}
}
package com.x.portal.assemble.surface.jaxrs.script;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import com.google.gson.JsonElement;
import com.x.base.core.project.annotation.JaxrsDescribe;
import com.x.base.core.project.annotation.JaxrsMethodDescribe;
import com.x.base.core.project.annotation.JaxrsParameterDescribe;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.http.HttpMediaType;
import com.x.base.core.project.jaxrs.ResponseFactory;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
@Path("script")
@JaxrsDescribe("脚本")
public class ScriptAction extends StandardJaxrsAction {
private static Logger logger = LoggerFactory.getLogger(ScriptAction.class);
@JaxrsMethodDescribe(value = "获取Script内容.", action = ActionGet.class)
@GET
@Path("{id}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void get(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("标识") @PathParam("id") String id) {
ActionResult<ActionGet.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionGet().execute(effectivePerson, id);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "获取Script内容,并递归附带应用脚本.", action = ActionGetImported.class)
@GET
@Path("portal/{portal}/name/{name}/imported")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void getImported(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("名称") @PathParam("name") String name,
@JaxrsParameterDescribe("门户标识") @PathParam("portal") String portal) {
ActionResult<ActionGetImported.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionGetImported().execute(effectivePerson, name, portal);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "在指定的Portal下根据flag获取Script.", action = ActionFlag.class)
@POST
@Path("portal/{portal}/name/{name}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void flag(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("名称") @PathParam("name") String name,
@JaxrsParameterDescribe("门户标识") @PathParam("portal") String portal, JsonElement jsonElement) {
ActionResult<ActionFlag.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionFlag().execute(effectivePerson, name, portal, jsonElement);
} catch (Exception e) {
logger.error(e, effectivePerson, request, jsonElement);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "列示属于指定Portal的Script.", action = ActionList.class)
@GET
@Path("list/portal/{portal}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void list(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("门户标识") @PathParam("portal") String portal) {
ActionResult<List<ActionList.Wo>> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionList().execute(effectivePerson, portal);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
}
\ No newline at end of file
package com.x.portal.assemble.surface.jaxrs.widget;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.tools.ListTools;
import com.x.portal.assemble.surface.Business;
import com.x.portal.core.entity.Portal;
import com.x.portal.core.entity.Widget;
class ActionGet extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String id) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
ActionResult<Wo> result = new ActionResult<>();
Widget widget = business.widget().pick(id);
if (null == widget) {
throw new ExceptionWidgetNotExist(id);
}
Portal portal = business.portal().pick(widget.getPortal());
if (null == portal) {
throw new ExceptionPortalNotExist(widget.getPortal());
}
if (!business.portal().visible(effectivePerson, portal)) {
throw new ExceptionPortalAccessDenied(effectivePerson.getDistinguishedName(), portal.getName(),
portal.getId());
}
Wo wo = Wo.copier.copy(widget);
wo.setData(widget.getDataOrMobileData());
result.setData(wo);
return result;
}
}
public static class Wo extends Widget {
private static final long serialVersionUID = -8067704098385000667L;
/** 不输出data数据,单独处理 */
static WrapCopier<Widget, Wo> copier = WrapCopierFactory.wo(Widget.class, Wo.class, null,
ListTools.toList(JpaObject.FieldsInvisible, Widget.data_FIELDNAME, Widget.mobileData_FIELDNAME));
}
}
\ No newline at end of file
package com.x.portal.assemble.surface.jaxrs.widget;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.portal.assemble.surface.Business;
import com.x.portal.core.entity.Portal;
import com.x.portal.core.entity.Widget;
class ActionGetMobile extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String id) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
ActionResult<Wo> result = new ActionResult<>();
Widget widget = business.widget().pick(id);
if (null == widget) {
throw new ExceptionWidgetNotExist(id);
}
Portal portal = business.portal().pick(widget.getPortal());
if (null == portal) {
throw new ExceptionPortalNotExist(widget.getPortal());
}
if (!business.portal().visible(effectivePerson, portal)) {
throw new ExceptionPortalAccessDenied(effectivePerson.getDistinguishedName(), portal.getName(),
portal.getId());
}
Wo wo = Wo.copier.copy(widget);
wo.setData(widget.getMobileDataOrData());
result.setData(wo);
return result;
}
}
public static class Wo extends Widget {
private static final long serialVersionUID = -8067704098385000667L;
/** 不输出data数据,单独处理 */
static WrapCopier<Widget, Wo> copier = WrapCopierFactory.wo(Widget.class, Wo.class,
JpaObject.singularAttributeField(Widget.class, true, true), JpaObject.FieldsInvisible);
}
}
\ No newline at end of file
package com.x.portal.assemble.surface.jaxrs.widget;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.portal.assemble.surface.Business;
import com.x.portal.core.entity.Portal;
import com.x.portal.core.entity.Widget;
import com.x.base.core.project.cache.Cache.CacheKey;
import com.x.base.core.project.cache.CacheManager;
import java.util.Optional;
class ActionGetWithPortal extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag, String portalFlag) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
Wo wo = null;
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
CacheKey cacheKey = new CacheKey(this.getClass(), flag, portalFlag);
Optional<?> optional = CacheManager.get(cache, cacheKey);
if (optional.isPresent()) {
wo = (Wo) optional.get();
Portal portal = business.portal().pick(wo.getPortal());
if (!business.portal().visible(effectivePerson, portal)) {
throw new ExceptionPortalAccessDenied(effectivePerson.getDistinguishedName(), portal.getName(),
portal.getId());
}
} else {
Portal portal = emc.flag(portalFlag, Portal.class);
if (null == portal) {
throw new ExceptionPortalNotExist(portalFlag);
}
if (!business.portal().visible(effectivePerson, portal)) {
throw new ExceptionPortalAccessDenied(effectivePerson.getDistinguishedName(), portal.getName(),
portal.getId());
}
Widget widget = emc.restrictFlag(flag, Widget.class, Widget.portal_FIELDNAME, portal.getId());
if (null == widget) {
throw new ExceptionWidgetNotExist(flag);
}
wo = Wo.copier.copy(widget);
wo.setData(widget.getDataOrMobileData());
CacheManager.put(cache, cacheKey, wo);
}
result.setData(wo);
return result;
}
}
public static class Wo extends Widget {
private static final long serialVersionUID = 3454132769791427909L;
/** 不输出data数据,单独处理 */
static WrapCopier<Widget, Wo> copier = WrapCopierFactory.wo(Widget.class, Wo.class,
JpaObject.singularAttributeField(Widget.class, true, true), JpaObject.FieldsInvisible);
}
}
\ No newline at end of file
package com.x.portal.assemble.surface.jaxrs.widget;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.portal.assemble.surface.Business;
import com.x.portal.core.entity.Portal;
import com.x.portal.core.entity.Widget;
import com.x.base.core.project.cache.Cache.CacheKey;
import com.x.base.core.project.cache.CacheManager;
import java.util.Optional;
class ActionGetWithPortalMobile extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag, String portalFlag) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
Wo wo = null;
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
CacheKey cacheKey = new CacheKey(this.getClass(), flag, portalFlag);
Optional<?> optional = CacheManager.get(cache, cacheKey);
if (optional.isPresent()) {
wo = (Wo) optional.get();
Portal portal = business.portal().pick(wo.getPortal());
if (!business.portal().visible(effectivePerson, portal)) {
throw new ExceptionPortalAccessDenied(effectivePerson.getDistinguishedName(), portal.getName(),
portal.getId());
}
} else {
Portal portal = emc.flag(portalFlag, Portal.class);
if (null == portal) {
throw new ExceptionPortalNotExist(portalFlag);
}
if (!business.portal().visible(effectivePerson, portal)) {
throw new ExceptionPortalAccessDenied(effectivePerson.getDistinguishedName(), portal.getName(),
portal.getId());
}
Widget widget = emc.restrictFlag(flag, Widget.class, Widget.portal_FIELDNAME, portal.getId());
if (null == widget) {
throw new ExceptionWidgetNotExist(flag);
}
wo = Wo.copier.copy(widget);
wo.setData(widget.getMobileDataOrData());
CacheManager.put(cache, cacheKey, wo);
}
result.setData(wo);
return result;
}
}
public static class Wo extends Widget {
private static final long serialVersionUID = 3454132769791427909L;
/** 不输出data数据,单独处理 */
static WrapCopier<Widget, Wo> copier = WrapCopierFactory.wo(Widget.class, Wo.class,
JpaObject.singularAttributeField(Widget.class, true, true), JpaObject.FieldsInvisible);
}
}
\ No newline at end of file
package com.x.portal.assemble.surface.jaxrs.widget;
import java.util.ArrayList;
import java.util.List;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.portal.assemble.surface.Business;
import com.x.portal.core.entity.Page;
import com.x.portal.core.entity.Portal;
import com.x.portal.core.entity.Widget;
class ActionList extends BaseAction {
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, String portalId) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
ActionResult<List<Wo>> result = new ActionResult<>();
List<Wo> wos = new ArrayList<>();
Portal portal = business.portal().pick(portalId);
if (null == portal) {
throw new ExceptionPortalNotExist(portalId);
}
if (!business.portal().visible(effectivePerson, portal)) {
throw new ExceptionPortalAccessDenied(effectivePerson.getDistinguishedName(), portal.getName(),
portal.getId());
}
List<String> ids = business.widget().listWithPortal(portal.getId());
for (String id : ids) {
Widget o = business.widget().pick(id);
if (null == o) {
throw new ExceptionWidgetNotExist(id);
} else {
wos.add(Wo.copier.copy(o));
}
}
result.setData(wos);
return result;
}
}
public static class Wo extends Page {
private static final long serialVersionUID = 3454132769791427909L;
/** 不输出data数据,单独处理 */
static WrapCopier<Widget, Wo> copier = WrapCopierFactory.wo(Widget.class, Wo.class,
JpaObject.singularAttributeField(Widget.class, true, true), JpaObject.FieldsInvisible);
}
}
\ No newline at end of file
package com.x.portal.assemble.surface.jaxrs.widget;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.portal.core.entity.Widget;
import com.x.base.core.project.cache.Cache.CacheCategory;
abstract class BaseAction extends StandardJaxrsAction {
CacheCategory cache = new CacheCategory(Widget.class);
}
package com.x.portal.assemble.surface.jaxrs.widget;
import com.x.base.core.project.exception.PromptException;
class ExceptionPortalAccessDenied extends PromptException {
private static final long serialVersionUID = -4908883340253465376L;
ExceptionPortalAccessDenied(String person, String name, String id) {
super("用户: {}, 访问站点: {}, id: {}, 失败,权限不足.", person, name, id);
}
}
package com.x.portal.assemble.surface.jaxrs.widget;
import com.x.base.core.project.exception.PromptException;
class ExceptionPortalNotExist extends PromptException {
private static final long serialVersionUID = -4908883340253465376L;
ExceptionPortalNotExist(String id) {
super("指定的站点不存在:{}.", id);
}
}
package com.x.portal.assemble.surface.jaxrs.widget;
import com.x.base.core.project.exception.PromptException;
class ExceptionWidgetNotExist extends PromptException {
private static final long serialVersionUID = -4908883340253465376L;
ExceptionWidgetNotExist(String id) {
super("指定的部件不存在:{}.", id);
}
}
......@@ -141,23 +141,23 @@ public class FormAction extends StandardJaxrsAction {
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "V2根据工作或完成工作标识获取表单,合并关联表单和关联脚本输出.", action = V2GetWithWorkOrWorkCompleted.class)
@GET
@Path("v2/workorworkcompleted/{workOrWorkCompleted}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void V2GetWithWorkOrWorkCompleted(@Suspended final AsyncResponse asyncResponse,
@Context HttpServletRequest request,
@JaxrsParameterDescribe("工作或完成工作标识") @PathParam("workOrWorkCompleted") String workOrWorkCompleted) {
ActionResult<V2GetWithWorkOrWorkCompleted.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new V2GetWithWorkOrWorkCompleted().execute(effectivePerson, workOrWorkCompleted);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
// @JaxrsMethodDescribe(value = "V2根据工作或完成工作标识获取表单,合并关联表单和关联脚本输出.", action = V2GetWithWorkOrWorkCompleted.class)
// @GET
// @Path("v2/workorworkcompleted/{workOrWorkCompleted}")
// @Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
// @Consumes(MediaType.APPLICATION_JSON)
// public void V2GetWithWorkOrWorkCompleted(@Suspended final AsyncResponse asyncResponse,
// @Context HttpServletRequest request,
// @JaxrsParameterDescribe("工作或完成工作标识") @PathParam("workOrWorkCompleted") String workOrWorkCompleted) {
// ActionResult<V2GetWithWorkOrWorkCompleted.Wo> result = new ActionResult<>();
// EffectivePerson effectivePerson = this.effectivePerson(request);
// try {
// result = new V2GetWithWorkOrWorkCompleted().execute(effectivePerson, workOrWorkCompleted);
// } catch (Exception e) {
// logger.error(e, effectivePerson, request, null);
// result.error(e);
// }
// asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
// }
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册