Przeglądaj źródła

增加恢复默认component

roo00 6 lat temu
rodzic
commit
5abbdefdde

+ 20 - 3
o2server/x_component_assemble_control/src/main/java/com/x/component/assemble/control/Business.java

@@ -2,7 +2,9 @@ package com.x.component.assemble.control;
 
 import com.x.base.core.container.EntityManagerContainer;
 import com.x.base.core.project.http.EffectivePerson;
+import com.x.base.core.project.organization.OrganizationDefinition;
 import com.x.component.assemble.control.factory.ComponentFactory;
+import com.x.organization.core.express.Organization;
 
 public class Business {
 
@@ -25,10 +27,25 @@ public class Business {
 		return component;
 	}
 
-	public boolean componentEditAvailable(EffectivePerson effectivePerson) throws Exception {
+	private Organization organization;
+
+	public Organization organization() throws Exception {
+		if (null == this.organization) {
+			this.organization = new Organization(ThisApplication.context());
+		}
+		return organization;
+	}
+
+	public boolean editable(EffectivePerson effectivePerson) throws Exception {
+		boolean result = false;
 		if (effectivePerson.isManager()) {
-			return true;
+			result = true;
+		}
+		if (!result) {
+			if (this.organization().person().hasRole(effectivePerson, OrganizationDefinition.Manager)) {
+				result = true;
+			}
 		}
-		return false;
+		return result;
 	}
 }

+ 6 - 0
o2server/x_component_assemble_control/src/main/java/com/x/component/assemble/control/jaxrs/component/ActionCreate.java

@@ -8,15 +8,21 @@ import com.x.base.core.entity.annotation.CheckPersistType;
 import com.x.base.core.project.bean.WrapCopier;
 import com.x.base.core.project.bean.WrapCopierFactory;
 import com.x.base.core.project.cache.ApplicationCache;
+import com.x.base.core.project.exception.ExceptionAccessDenied;
 import com.x.base.core.project.http.ActionResult;
 import com.x.base.core.project.http.EffectivePerson;
 import com.x.base.core.project.jaxrs.WrapBoolean;
+import com.x.component.assemble.control.Business;
 import com.x.component.core.entity.Component;
 
 class ActionCreate extends ActionBase {
 	ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
 		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
 			ActionResult<Wo> result = new ActionResult<>();
+			Business business = new Business(emc);
+			if (!business.editable(effectivePerson)) {
+				throw new ExceptionAccessDenied(effectivePerson);
+			}
 			Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
 			Component component = Wi.copier.copy(wi);
 			emc.beginTransaction(Component.class);

+ 9 - 3
o2server/x_component_assemble_control/src/main/java/com/x/component/assemble/control/jaxrs/component/ActionDelete.java

@@ -4,19 +4,25 @@ import com.x.base.core.container.EntityManagerContainer;
 import com.x.base.core.container.factory.EntityManagerContainerFactory;
 import com.x.base.core.entity.annotation.CheckRemoveType;
 import com.x.base.core.project.cache.ApplicationCache;
+import com.x.base.core.project.exception.ExceptionAccessDenied;
 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.WrapBoolean;
+import com.x.component.assemble.control.Business;
 import com.x.component.core.entity.Component;
 
 class ActionDelete extends ActionBase {
-	ActionResult<Wo> execute(EffectivePerson effectivePerson, String id) throws Exception {
+	ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag) throws Exception {
 		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
 			ActionResult<Wo> result = new ActionResult<>();
-			Component component = emc.find(id, Component.class);
+			Business business = new Business(emc);
+			if (!business.editable(effectivePerson)) {
+				throw new ExceptionAccessDenied(effectivePerson);
+			}
+			Component component = emc.flag(flag, Component.class);
 			if (null == component) {
-				throw new ExceptionEntityNotExist(id, Component.class);
+				throw new ExceptionEntityNotExist(flag, Component.class);
 			}
 			emc.beginTransaction(Component.class);
 			emc.remove(component, CheckRemoveType.all);

+ 44 - 0
o2server/x_component_assemble_control/src/main/java/com/x/component/assemble/control/jaxrs/component/ActionDeleteAll.java

@@ -0,0 +1,44 @@
+package com.x.component.assemble.control.jaxrs.component;
+
+import com.x.base.core.container.EntityManagerContainer;
+import com.x.base.core.container.factory.EntityManagerContainerFactory;
+import com.x.base.core.entity.annotation.CheckRemoveType;
+import com.x.base.core.project.cache.ApplicationCache;
+import com.x.base.core.project.exception.ExceptionAccessDenied;
+import com.x.base.core.project.http.ActionResult;
+import com.x.base.core.project.http.EffectivePerson;
+import com.x.base.core.project.jaxrs.WrapBoolean;
+import com.x.base.core.project.logger.Logger;
+import com.x.base.core.project.logger.LoggerFactory;
+import com.x.component.assemble.control.Business;
+import com.x.component.core.entity.Component;
+
+class ActionDeleteAll extends ActionBase {
+
+	private static Logger logger = LoggerFactory.getLogger(ActionDeleteAll.class);
+
+	ActionResult<Wo> execute(EffectivePerson effectivePerson) throws Exception {
+		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+			ActionResult<Wo> result = new ActionResult<>();
+			Business business = new Business(emc);
+			if (!business.editable(effectivePerson)) {
+				throw new ExceptionAccessDenied(effectivePerson);
+			}
+			emc.beginTransaction(Component.class);
+			for (Component o : emc.listAll(Component.class)) {
+				emc.remove(o, CheckRemoveType.all);
+			}
+			emc.commit();
+			Wo wo = new Wo();
+			wo.setValue(true);
+			result.setData(wo);
+			ApplicationCache.notify(Component.class);
+			return result;
+		}
+	}
+
+	public static class Wo extends WrapBoolean {
+
+	}
+
+}

+ 9 - 3
o2server/x_component_assemble_control/src/main/java/com/x/component/assemble/control/jaxrs/component/ActionEdit.java

@@ -8,21 +8,27 @@ import com.x.base.core.entity.annotation.CheckPersistType;
 import com.x.base.core.project.bean.WrapCopier;
 import com.x.base.core.project.bean.WrapCopierFactory;
 import com.x.base.core.project.cache.ApplicationCache;
+import com.x.base.core.project.exception.ExceptionAccessDenied;
 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.WrapBoolean;
+import com.x.component.assemble.control.Business;
 import com.x.component.core.entity.Component;
 
 class ActionEdit extends ActionBase {
 
-	ActionResult<Wo> execute(EffectivePerson effectivePerson, String id, JsonElement jsonElement) throws Exception {
+	ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag, JsonElement jsonElement) throws Exception {
 		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
 			ActionResult<Wo> result = new ActionResult<>();
+			Business business = new Business(emc);
+			if (!business.editable(effectivePerson)) {
+				throw new ExceptionAccessDenied(effectivePerson);
+			}
 			Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
-			Component component = emc.find(id, Component.class);
+			Component component = emc.flag(flag, Component.class);
 			if (null == component) {
-				throw new ExceptionEntityNotExist(id, Component.class);
+				throw new ExceptionEntityNotExist(flag, Component.class);
 			}
 			Wi.copier.copy(wi, component);
 			emc.beginTransaction(Component.class);

+ 3 - 3
o2server/x_component_assemble_control/src/main/java/com/x/component/assemble/control/jaxrs/component/ActionGet.java

@@ -12,12 +12,12 @@ import com.x.component.core.entity.Component;
 
 class ActionGet extends ActionBase {
 
-	ActionResult<Wo> execute(EffectivePerson effectivePerson, String id) throws Exception {
+	ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag) throws Exception {
 		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
 			ActionResult<Wo> result = new ActionResult<>();
-			Component component = emc.find(id, Component.class);
+			Component component = emc.flag(flag, Component.class);
 			if (null == component) {
-				throw new ExceptionEntityNotExist(id, Component.class);
+				throw new ExceptionEntityNotExist(flag, Component.class);
 			}
 			Wo wo = Wo.copier.copy(component);
 			result.setData(wo);

+ 2 - 2
o2server/x_component_assemble_control/src/main/java/com/x/component/assemble/control/jaxrs/component/ActionListAll.java

@@ -159,8 +159,8 @@ class ActionListAll extends ActionBase {
 			o.setVisible(true);
 			break;
 		case COMPONENT_ANN:
-			o.setName(COMPONENT_ONLINEMEETING);
-			o.setPath(COMPONENT_ONLINEMEETING);
+			o.setName(COMPONENT_ANN);
+			o.setPath(COMPONENT_ANN);
 			o.setTitle("神经网络");
 			o.setIconPath("appicon.png");
 			o.setVisible(true);

+ 26 - 9
o2server/x_component_assemble_control/src/main/java/com/x/component/assemble/control/jaxrs/component/ComponentAction.java

@@ -52,15 +52,15 @@ public class ComponentAction extends StandardJaxrsAction {
 
 	@JaxrsMethodDescribe(value = "获取Component对象.", action = ActionGet.class)
 	@GET
-	@Path("{id}")
+	@Path("{flag}")
 	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
 	@Consumes(MediaType.APPLICATION_JSON)
 	public void get(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
-			@PathParam("id") String id) {
+			@PathParam("flag") String flag) {
 		ActionResult<ActionGet.Wo> result = new ActionResult<>();
 		EffectivePerson effectivePerson = this.effectivePerson(request);
 		try {
-			result = new ActionGet().execute(effectivePerson, id);
+			result = new ActionGet().execute(effectivePerson, flag);
 		} catch (Exception e) {
 			logger.error(e, effectivePerson, request, null);
 			result.error(e);
@@ -87,15 +87,15 @@ public class ComponentAction extends StandardJaxrsAction {
 
 	@JaxrsMethodDescribe(value = "更新Component对象.", action = ActionEdit.class)
 	@PUT
-	@Path("{id}")
+	@Path("{flag}")
 	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
 	@Consumes(MediaType.APPLICATION_JSON)
 	public void edit(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
-			@PathParam("id") String id, JsonElement jsonElement) {
+			@PathParam("flag") String flag, JsonElement jsonElement) {
 		ActionResult<ActionEdit.Wo> result = new ActionResult<>();
 		EffectivePerson effectivePerson = this.effectivePerson(request);
 		try {
-			result = new ActionEdit().execute(effectivePerson, id, jsonElement);
+			result = new ActionEdit().execute(effectivePerson, flag, jsonElement);
 		} catch (Exception e) {
 			logger.error(e, effectivePerson, request, jsonElement);
 			result.error(e);
@@ -105,15 +105,32 @@ public class ComponentAction extends StandardJaxrsAction {
 
 	@JaxrsMethodDescribe(value = "删除Component对象.", action = ActionDelete.class)
 	@DELETE
-	@Path("{id}")
+	@Path("{flag}")
 	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
 	@Consumes(MediaType.APPLICATION_JSON)
 	public void delete(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
-			@PathParam("id") String id) {
+			@PathParam("flag") String flag) {
 		ActionResult<ActionDelete.Wo> result = new ActionResult<>();
 		EffectivePerson effectivePerson = this.effectivePerson(request);
 		try {
-			result = new ActionDelete().execute(effectivePerson, id);
+			result = new ActionDelete().execute(effectivePerson, flag);
+		} catch (Exception e) {
+			logger.error(e, effectivePerson, request, null);
+			result.error(e);
+		}
+		asyncResponse.resume(ResponseFactory.getDefaultActionResultResponse(result));
+	}
+
+	@JaxrsMethodDescribe(value = "删除所有Component,还原默认布局.", action = ActionDeleteAll.class)
+	@DELETE
+	@Path("delete/all")
+	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
+	@Consumes(MediaType.APPLICATION_JSON)
+	public void deleteAll(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request) {
+		ActionResult<ActionDeleteAll.Wo> result = new ActionResult<>();
+		EffectivePerson effectivePerson = this.effectivePerson(request);
+		try {
+			result = new ActionDeleteAll().execute(effectivePerson);
 		} catch (Exception e) {
 			logger.error(e, effectivePerson, request, null);
 			result.error(e);