提交 5c8075f2 编写于 作者: O o2null

Merge branch 'feature/add-manager-empower' into 'develop'

[用户授权]管理员 增加、删除、修改授权

See merge request o2oa/o2oa!1054
package com.x.organization.assemble.personal.jaxrs.empower;
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.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.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoId;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.organization.assemble.personal.Business;
import com.x.organization.core.entity.accredit.Empower;
import org.apache.commons.lang3.StringUtils;
class ActionManagerCreate extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionManagerCreate.class);
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<Wo> result = new ActionResult<>();
if (effectivePerson.isManager()) {
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
Business business = new Business(emc);
Empower empower = Wi.copier.copy(wi);
this.check(business, empower);
String fromPerson = this.getPersonDNWithIdentityDN(business, empower.getFromIdentity());
if (StringUtils.isEmpty(fromPerson)) {
throw new ExceptionPersonNotExistWithIdentity(empower.getFromIdentity());
} else {
empower.setFromPerson(fromPerson);
}
String toPerson = this.getPersonDNWithIdentityDN(business, empower.getToIdentity());
if (StringUtils.isEmpty(toPerson)) {
throw new ExceptionPersonNotExistWithIdentity(empower.getToIdentity());
} else {
empower.setToPerson(toPerson);
}
emc.beginTransaction(Empower.class);
emc.persist(empower, CheckPersistType.all);
emc.commit();
ApplicationCache.notify(Empower.class);
Wo wo = new Wo();
wo.setId(empower.getId());
result.setData(wo);
}
return result;
}
}
public static class Wi extends Empower {
private static final long serialVersionUID = -4315296543575928054L;
static WrapCopier<Wi, Empower> copier = WrapCopierFactory.wi(Wi.class, Empower.class, null,
JpaObject.FieldsUnmodify);
}
public static class Wo extends WoId {
}
}
package com.x.organization.assemble.personal.jaxrs.empower;
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.organization.core.entity.accredit.Empower;
class ActionManagerDelete extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String id) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<Wo> result = new ActionResult<>();
Empower empower = emc.find(id, Empower.class);
if (null == empower) {
throw new ExceptionEntityNotExist(id, Empower.class);
}
if (effectivePerson.isManager()) {
emc.beginTransaction(Empower.class);
emc.remove(empower, CheckRemoveType.all);
emc.commit();
ApplicationCache.notify(Empower.class);
Wo wo = new Wo();
wo.setValue(true);
result.setData(wo);
}
return result;
}
}
public static class Wo extends WrapBoolean {
}
}
\ No newline at end of file
package com.x.organization.assemble.personal.jaxrs.empower;
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.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.ExceptionEntityNotExist;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoId;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.organization.assemble.personal.Business;
import com.x.organization.core.entity.accredit.Empower;
import org.apache.commons.lang3.StringUtils;
class ActionManagerEdit extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionManagerEdit.class);
ActionResult<Wo> execute(EffectivePerson effectivePerson, String id, JsonElement jsonElement) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<Wo> result = new ActionResult<>();
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
Business business = new Business(emc);
Empower empower = emc.find(id, Empower.class);
if (null == empower) {
throw new ExceptionEntityNotExist(id, Empower.class);
}
if(effectivePerson.isManager()){
Wi.copier.copy(wi, empower);
this.check(business, empower);
String fromPerson = this.getPersonDNWithIdentityDN(business, empower.getFromIdentity());
if (StringUtils.isEmpty(fromPerson)) {
throw new ExceptionPersonNotExistWithIdentity(empower.getFromIdentity());
} else {
empower.setFromPerson(fromPerson);
}
String toPerson = this.getPersonDNWithIdentityDN(business, empower.getToIdentity());
if (StringUtils.isEmpty(toPerson)) {
throw new ExceptionPersonNotExistWithIdentity(empower.getToIdentity());
} else {
empower.setToPerson(toPerson);
}
emc.beginTransaction(Empower.class);
emc.check(empower, CheckPersistType.all);
emc.commit();
ApplicationCache.notify(Empower.class);
Wo wo = new Wo();
wo.setId(empower.getId());
result.setData(wo);
}
return result;
}
}
public static class Wi extends Empower {
private static final long serialVersionUID = 200222480341620744L;
static WrapCopier<Wi, Empower> copier = WrapCopierFactory.wi(Wi.class, Empower.class, null,
JpaObject.FieldsUnmodify);
}
public static class Wo extends WoId {
}
}
......@@ -195,13 +195,48 @@ public class EmpowerAction extends StandardJaxrsAction {
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "管理员创建授权", action = ActionManagerCreate.class)
@Path("manager")
@POST
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void managerCreate(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
JsonElement jsonElement) {
ActionResult<ActionManagerCreate.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionManagerCreate().execute(effectivePerson, jsonElement);
} catch (Exception e) {
logger.error(e, effectivePerson, request, jsonElement);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "管理员更新授权", action = ActionManagerEdit.class)
@PUT
@Path("manager/{id}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void managerEdit(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("标识") @PathParam("id") String id, JsonElement jsonElement) {
ActionResult<ActionManagerEdit.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionManagerEdit().execute(effectivePerson, id, jsonElement);
} catch (Exception e) {
logger.error(e, effectivePerson, request, jsonElement);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "更新授权", action = ActionEdit.class)
@PUT
@Path("{id}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void edit(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("标识") @PathParam("id") String id, JsonElement jsonElement) {
@JaxrsParameterDescribe("标识") @PathParam("id") String id, JsonElement jsonElement) {
ActionResult<ActionEdit.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
......@@ -212,7 +247,6 @@ public class EmpowerAction extends StandardJaxrsAction {
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "删除授权", action = ActionDelete.class)
@DELETE
@Path("{id}")
......@@ -231,6 +265,24 @@ public class EmpowerAction extends StandardJaxrsAction {
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "管理员删除授权", action = ActionManagerDelete.class)
@DELETE
@Path("/manager/{id}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void managerDelete(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("标识") @PathParam("id") String id) {
ActionResult<ActionManagerDelete.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionManagerDelete().execute(effectivePerson, id);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "启用授权", action = ActionEnable.class)
@GET
@Path("{id}/enable")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册