提交 8c64d21f 编写于 作者: R roo00

修正增加topUnitList带来的校验问题.

上级 580e2176
package com.x.base.core.project.config;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentSkipListMap;
import org.apache.commons.collections4.set.ListOrderedSet;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
public class CenterServers extends ConcurrentSkipListMap<String, CenterServer> {
......@@ -23,24 +23,24 @@ public class CenterServers extends ConcurrentSkipListMap<String, CenterServer> {
}
}
public ListOrderedSet<Entry<String, CenterServer>> orderedEntrySet() {
ListOrderedSet<Entry<String, CenterServer>> set = new ListOrderedSet<>();
public List<Entry<String, CenterServer>> orderedEntry() {
List<Entry<String, CenterServer>> list = new ArrayList<>();
this.entrySet().stream().sorted((o1, o2) -> {
return o1.getValue().getOrder() - o2.getValue().getOrder();
return o1.getValue().getOrder().compareTo(o2.getValue().getOrder());
}).forEachOrdered(o -> {
set.add(o);
list.add(o);
});
return set;
return list;
}
public CenterServer first() {
public Entry<String, CenterServer> first() {
ListOrderedSet<Entry<String, CenterServer>> set = orderedEntrySet();
List<Entry<String, CenterServer>> list = orderedEntry();
if (set.isEmpty()) {
if (list.isEmpty()) {
return null;
} else {
return set.get(0).getValue();
return list.get(0);
}
}
......
......@@ -6,7 +6,7 @@ import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.Map.Entry;
import java.util.concurrent.LinkedBlockingQueue;
import javax.naming.InitialContext;
......@@ -829,6 +829,33 @@ public class Config {
return buffer.toString();
}
public static String url_x_program_center_jaxrs(Entry<String, CenterServer> entry, String... paths)
throws Exception {
String n = entry.getKey();
Integer p = entry.getValue().getPort();
Boolean s = entry.getValue().getSslEnable();
StringBuffer buffer = new StringBuffer();
if (s) {
buffer.append("https://").append(n);
if (!NumberTools.valueEuqals(p, 443)) {
buffer.append(":").append(p);
}
} else {
buffer.append("http://").append(n);
if (!NumberTools.valueEuqals(p, 80)) {
buffer.append(":").append(p);
}
}
buffer.append("/").append(x_program_center.class.getSimpleName());
buffer.append("/jaxrs/");
List<String> os = new ArrayList<>();
for (String path : paths) {
os.add(URLEncoder.encode(StringUtils.strip(path, "/"), DefaultCharset.name));
}
buffer.append(StringUtils.join(os, "/"));
return buffer.toString();
}
private Messages messages;
public static Messages messages() throws Exception {
......
......@@ -93,6 +93,17 @@ public class Messages extends ConcurrentSkipListMap<String, Message> {
o.put(MessageConnector.TYPE_READCOMPLETED_DELETE, new Message());
/* 待阅已阅通知结束 */
/* 日程管理消息通知 */
o.put(MessageConnector.TYPE_CALENDAR_ALARM,
new Message(MessageConnector.CONSUME_WS, MessageConnector.CONSUME_PMS,
MessageConnector.CONSUME_DINGDING, MessageConnector.CONSUME_ZHENGWUDINGDING,
MessageConnector.CONSUME_QIYEWEIXIN));
/* 文档发布消息通知 */
o.put(MessageConnector.TYPE_CMS_PUBLISH,
new Message(MessageConnector.CONSUME_WS, MessageConnector.CONSUME_PMS,
MessageConnector.CONSUME_DINGDING, MessageConnector.CONSUME_ZHENGWUDINGDING,
MessageConnector.CONSUME_QIYEWEIXIN));
return o;
}
......
......@@ -28,4 +28,12 @@ public class TestClient {
System.out.println(tree.tailMap(1, true).firstEntry().getValue());
}
@Test
public void test1() {
Integer a = 1;
Integer b = 2;
System.out.println(a.compareTo(b));
}
}
......@@ -13,7 +13,7 @@ public class MessageFactory {
LogUtil.INFO( "send calendar alarm message", event.getTitle() + ", StartTime: " + event.getStartTimeStr() );
if( ListTools.isNotEmpty( event.getParticipants() )) {
for( String participant : event.getParticipants() ) {
MessageConnector.send( MessageConnector.TYPE_CALENDAR_ALARM, event.getValarm_Summary(), participant, event );
MessageConnector.send( MessageConnector.TYPE_CALENDAR_ALARM, "日程提醒:"+event.getTitle(), participant, event );
}
}
......
......@@ -149,8 +149,6 @@ public class ActionSave extends BaseAction {
if( StringUtils.equals( "信息", wi.getDocumentType() ) && wi.getSendNotify() == null ) {
wi.setSendNotify( true );
}else {
wi.setSendNotify( false );
}
try {
......
......@@ -191,8 +191,18 @@ public class ActionPersistPublishAndNotify extends BaseAction {
try {
CategoryInfo categoryInfo = categoryInfoServiceAdv.getWithFlag( document.getCategoryId() );
if( categoryInfo != null ){
//如果分类配置为需要推送通知,或者(分类配置为空,但是文档为信息文档时),推送通知
if( categoryInfo.getSendNotify() || (categoryInfo.getSendNotify() == null && StringUtils.equals("信息", categoryInfo.getDocumentType()))){
Boolean notify = false;
if( categoryInfo.getSendNotify() == null ) {
if( StringUtils.equals("信息", categoryInfo.getDocumentType()) ) {
notify = true;
}
}else {
if( categoryInfo.getSendNotify() ) {
notify = true;
}
}
if( notify ){
logger.info("try to add notify object to queue for document:" + document.getTitle() );
ThisApplication.queueSendDocumentNotify.send( document );
}
}
......
......@@ -367,6 +367,31 @@ public class ActionPersistPublishByWorkFlow extends BaseAction {
}
}
//判断是否需要发送通知消息
if (check) {
try {
Boolean notify = false;
if( categoryInfo.getSendNotify() == null ) {
if( StringUtils.equals("信息", categoryInfo.getDocumentType()) ) {
notify = true;
}
}else {
if( categoryInfo.getSendNotify() ) {
notify = true;
}
}
if( notify ){
logger.info("try to add notify object to queue for document:" + document.getTitle() );
ThisApplication.queueSendDocumentNotify.send( document );
}
} catch (Exception e) {
check = false;
Exception exception = new ExceptionDocumentInfoProcess( e, "根据ID查询分类信息对象时发生异常。Flag:" + document.getCategoryId() );
result.error( exception );
logger.error( e, effectivePerson, request, null);
}
}
ApplicationCache.notify(Document.class);
return result;
}
......
......@@ -23,6 +23,7 @@ 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.cms.assemble.control.ThisApplication;
import com.x.cms.assemble.control.jaxrs.permission.element.PermissionInfo;
import com.x.cms.core.entity.AppInfo;
import com.x.cms.core.entity.CategoryInfo;
......@@ -327,6 +328,31 @@ public class ActionPersistPublishContent extends BaseAction {
}
}
//判断是否需要发送通知消息
if (check) {
try {
Boolean notify = false;
if( categoryInfo.getSendNotify() == null ) {
if( StringUtils.equals("信息", categoryInfo.getDocumentType()) ) {
notify = true;
}
}else {
if( categoryInfo.getSendNotify() ) {
notify = true;
}
}
if( notify ){
logger.info("try to add notify object to queue for document:" + document.getTitle() );
ThisApplication.queueSendDocumentNotify.send( document );
}
} catch (Exception e) {
check = false;
Exception exception = new ExceptionDocumentInfoProcess( e, "根据ID查询分类信息对象时发生异常。Flag:" + document.getCategoryId() );
result.error( exception );
logger.error( e, effectivePerson, request, null);
}
}
ApplicationCache.notify(Document.class);
return result;
}
......
......@@ -74,37 +74,28 @@ public class ActionQueryGetControl extends BaseAction {
}
}
String cacheKey = ApplicationCache.concreteCacheKey( id, "getControl", isManager, effectivePerson.getDistinguishedName() );
Element element = cache.get(cacheKey);
if ((null != element) && (null != element.getObjectValue())) {
document = wo = (Wo) element.getObjectValue();
result.setData(wo);
} else {
if (check) {
try {
document = documentQueryService.get(id);
if (document == null) {
check = false;
Exception exception = new ExceptionDocumentNotExists(id);
result.error(exception);
} else {
try {
wo = Wo.copier.copy(document);
} catch (Exception e) {
check = false;
Exception exception = new ExceptionDocumentInfoProcess(e, "将查询出来的文档信息对象转换为可输出的数据信息时发生异常。");
result.error(exception);
logger.error(e, effectivePerson, request, null);
}
}
} catch (Exception e) {
if (check) {
try {
document = documentQueryService.get(id);
if (document == null) {
check = false;
Exception exception = new ExceptionDocumentInfoProcess(e, "文档信息获取操作时发生异常。Id:" + id + ", Name:" + personName);
Exception exception = new ExceptionDocumentNotExists(id);
result.error(exception);
logger.error(e, effectivePerson, request, null);
}
} catch (Exception e) {
check = false;
Exception exception = new ExceptionDocumentInfoProcess(e, "文档信息获取操作时发生异常。Id:" + id + ", Name:" + personName);
result.error(exception);
logger.error(e, effectivePerson, request, null);
}
}
String cacheKey = ApplicationCache.concreteCacheKey( id, "getControl", isManager, effectivePerson.getDistinguishedName() );
Element element = cache.get(cacheKey);
if ((null != element) && (null != element.getObjectValue())) {
wo = (Wo) element.getObjectValue();
result.setData(wo);
} else {
if (check) {
try {
reviewCount = documentQueryService.getViewableReview(id, personName);
......@@ -121,7 +112,7 @@ public class ActionQueryGetControl extends BaseAction {
//判断用户是否是文档的创建者,创建者是有权限编辑文档的
if (check) {
if (wo != null && StringUtils.equals( personName, wo.getCreatorPerson())) {
if (wo != null && StringUtils.equals( personName, document.getCreatorPerson())) {
isCreator = true;
woControl.setAllowVisit(true);
}
......@@ -223,15 +214,15 @@ public class ActionQueryGetControl extends BaseAction {
// 判断当前登录者是不是该文档的可编辑者
try {
if( ListTools.isNotEmpty( document.getAuthorPersonList() )) {
if ( wo.getAuthorPersonList().contains( personName )) {
if ( document.getAuthorPersonList().contains( personName )) {
woControl.setAllowVisit(true);
woControl.setAllowEdit(true);
}
if( ListTools.containsAny( unitNames , wo.getAuthorUnitList() )) {
if( ListTools.containsAny( unitNames , document.getAuthorUnitList() )) {
woControl.setAllowVisit(true);
woControl.setAllowEdit(true);
}
if( ListTools.containsAny( groupNames , wo.getAuthorGroupList() )) {
if( ListTools.containsAny( groupNames , document.getAuthorGroupList() )) {
woControl.setAllowVisit(true);
woControl.setAllowEdit(true);
}
......@@ -248,111 +239,9 @@ public class ActionQueryGetControl extends BaseAction {
result.setData(wo);
return result;
}
// private List<String> composeAuthorUnitsWithAppAndCagetory(AppInfo appInfo, CategoryInfo category) {
// List<String> authorUnits = new ArrayList<>();
// if( ListTools.isNotEmpty( appInfo.getManageableUnitList() )) {
// for( String name : appInfo.getManageableUnitList() ) {
// if( !authorUnits.contains( name )) {
// authorUnits.add( name );
// }
// }
// }
// if( ListTools.isNotEmpty( appInfo.getPublishableUnitList() )) {
// for( String name : appInfo.getPublishableUnitList() ) {
// if( !authorUnits.contains( name )) {
// authorUnits.add( name );
// }
// }
// }
// if( ListTools.isNotEmpty( category.getManageableUnitList() )) {
// for( String name : category.getManageableUnitList() ) {
// if( !authorUnits.contains( name )) {
// authorUnits.add( name );
// }
// }
// }
// if( ListTools.isNotEmpty( category.getPublishableUnitList() )) {
// for( String name : category.getPublishableUnitList() ) {
// if( !authorUnits.contains( name )) {
// authorUnits.add( name );
// }
// }
// }
// return authorUnits;
// }
//
// private List<String> composeAuthorGroupsWithAppAndCagetory(AppInfo appInfo, CategoryInfo category) {
// List<String> authorGroups = new ArrayList<>();
// if( ListTools.isNotEmpty( appInfo.getManageableGroupList() )) {
// for( String name : appInfo.getManageableGroupList() ) {
// if( !authorGroups.contains( name )) {
// authorGroups.add( name );
// }
// }
// }
// if( ListTools.isNotEmpty( appInfo.getPublishableGroupList() )) {
// for( String name : appInfo.getPublishableGroupList() ) {
// if( !authorGroups.contains( name )) {
// authorGroups.add( name );
// }
// }
// }
// if( ListTools.isNotEmpty( category.getManageableGroupList() )) {
// for( String name : category.getManageableGroupList() ) {
// if( !authorGroups.contains( name )) {
// authorGroups.add( name );
// }
// }
// }
// if( ListTools.isNotEmpty( category.getPublishableGroupList() )) {
// for( String name : category.getPublishableGroupList() ) {
// if( !authorGroups.contains( name )) {
// authorGroups.add( name );
// }
// }
// }
// return authorGroups;
// }
//
// private List<String> composeAuthorPersonsWithAppAndCagetory(AppInfo appInfo, CategoryInfo category) {
// List<String> authorPersons = new ArrayList<>();
// if( ListTools.isNotEmpty( appInfo.getManageablePersonList() )) {
// for( String name : appInfo.getManageablePersonList() ) {
// if( !authorPersons.contains( name )) {
// authorPersons.add( name );
// }
// }
// }
// if( ListTools.isNotEmpty( appInfo.getPublishablePersonList() )) {
// for( String name : appInfo.getPublishablePersonList() ) {
// if( !authorPersons.contains( name )) {
// authorPersons.add( name );
// }
// }
// }
// if( ListTools.isNotEmpty( category.getManageablePersonList() )) {
// for( String name : category.getManageablePersonList() ) {
// if( !authorPersons.contains( name )) {
// authorPersons.add( name );
// }
// }
// }
// if( ListTools.isNotEmpty( category.getPublishablePersonList() )) {
// for( String name : category.getPublishablePersonList() ) {
// if( !authorPersons.contains( name )) {
// authorPersons.add( name );
// }
// }
// }
// return authorPersons;
// }
public static class Wo extends Document {
private static final long serialVersionUID = -5076990764713538973L;
public static class Wo {
public static WrapCopier<Document, Wo> copier = WrapCopierFactory.wo(Document.class, Wo.class, null, JpaObject.FieldsInvisible);
......@@ -366,7 +255,7 @@ public class ActionQueryGetControl extends BaseAction {
this.control = control;
}
}
public static class WoControl extends GsonPropertyObject {
@FieldDescribe("是否允许查看.")
......
package com.x.cms.assemble.control.jaxrs.document;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
......@@ -107,6 +108,7 @@ public class ActionQueryListVisiblePersons extends BaseAction {
//计算该文档有多少阅读者
ReviewService reviewService = new ReviewService();
List<String> persons = reviewService.listPermissionPersons( appInfo, categoryInfo, document );
if( ListTools.isNotEmpty( persons )) {
//有可能是*, 一般是所有的人员标识列表
if( persons.contains( "*" )) {
......@@ -124,6 +126,12 @@ public class ActionQueryListVisiblePersons extends BaseAction {
if( persons == null ) {
persons = new ArrayList<>();
}
//去一下重复
HashSet<String> set = new HashSet<String>( persons );
persons.clear();
persons.addAll(set);
wo.setValueList(persons);
result.setData(wo);
result.setCount( Long.parseLong( persons.size() + ""));
......
package com.x.cms.assemble.control.queue;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
......@@ -31,14 +32,35 @@ public class QueueSendDocumentNotify extends AbstractQueue<Document> {
public void execute( Document document ) throws Exception {
if( document == null ) {
logger.info("can not send publish notify , document is NULL!" );
return;
}
logger.debug("send publish notify for new document:" + document.getTitle() );
logger.info("send publish notify for new document:" + document.getTitle() );
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
AppInfo appInfo = emc.find( document.getAppId(), AppInfo.class );
CategoryInfo category = emc.find( document.getCategoryId(), CategoryInfo.class );
// Boolean sendNotify = false;
if( appInfo != null && category != null ) {
//计算该文档有多少阅读者
// //根据栏目和分类配置判断是否需要提醒
// if(StringUtils.equals( "信息", document.getDocumentType() )) {
// if( category.getSendNotify() == null ) {
// if( appInfo.getSendNotify() == null ) {
// //都为空,默认发送通知
// sendNotify = true;
// }else {
// sendNotify = appInfo.getSendNotify();
// }
// }else {
// sendNotify = category.getSendNotify();
// }
// }else {
// //数据类型,只有分类设置了需要通知,才会有通知,为空和为false都不通知
// if( category.getSendNotify() ) {
// sendNotify = true;
// }
// }
// if( sendNotify ) {
//计算该文档有多少阅读者
ReviewService reviewService = new ReviewService();
List<String> persons = reviewService.listPermissionPersons( appInfo, category, document );
if( ListTools.isNotEmpty( persons )) {
......@@ -56,16 +78,24 @@ public class QueueSendDocumentNotify extends AbstractQueue<Document> {
}
}
if( ListTools.isNotEmpty( persons )) {
//去一下重复
HashSet<String> set = new HashSet<String>( persons );
persons.clear();
persons.addAll(set);
MessageWo wo = MessageWo.copier.copy(document);
for( String person : persons ) {
if( !StringUtils.equals( "*", person )) {
MessageFactory.cms_publish(person, wo);
}
}
logger.debug("send total count:" + persons.size() );
logger.info("send total count:" + persons.size() );
}
logger.debug("send publish notify for new document completed! " );
logger.info("send publish notify for new document completed! " );
//}
}
logger.info("can not send publish notify for document, category or appinfo not exists! ID: " + document.getId() );
}
}
......
......@@ -62,7 +62,7 @@ public class ResourceFactory {
new Resource(Config.RESOURCE_NODE_EVENTQUEUEEXECUTOR, eventQueueExecutor);
new Resource(Config.RESOURCE_NODE_APPLICATIONS, null);
new Resource(Config.RESOURCE_NODE_APPLICATIONSTIMESTAMP, null);
Entry<String, CenterServer> entry = Config.nodes().centerServers().orderedEntrySet().get(0);
Entry<String, CenterServer> entry = Config.nodes().centerServers().first();
new Resource(Config.RESOURCE_NODE_CENTERSPRIMARYNODE, entry.getKey());
new Resource(Config.RESOURCE_NODE_CENTERSPRIMARYPORT, entry.getValue().getPort());
new Resource(Config.RESOURCE_NODE_CENTERSPRIMARYSSLENABLE, entry.getValue().getSslEnable());
......
......@@ -2,6 +2,7 @@ package com.x.server.console.node;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
......@@ -12,6 +13,7 @@ import org.eclipse.jetty.server.handler.gzip.GzipHandler;
import com.x.base.core.project.Application;
import com.x.base.core.project.Applications;
import com.x.base.core.project.config.CenterServer;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.connection.CipherConnectionAction;
import com.x.base.core.project.gson.XGsonBuilder;
......@@ -65,8 +67,11 @@ public class RegistApplicationsEvent implements Event {
req.setValue(XGsonBuilder.toJson(list));
CipherConnectionAction.put(false, Config.url_x_program_center_jaxrs("center", "regist", "applications"),
req);
for (Entry<String, CenterServer> entry : Config.nodes().centerServers().orderedEntry()) {
CipherConnectionAction.put(false,
Config.url_x_program_center_jaxrs(entry, "center", "regist", "applications"), req);
}
Config.resource_node_eventQueue().put(XGsonBuilder.instance().toJsonTree(new UpdateApplicationsEvent()));
}
......
......@@ -4,7 +4,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
......@@ -24,12 +23,13 @@ public class VoteCenterEvent implements Event {
public void execute() throws Exception {
Set<Entry<String, CenterServer>> set = Config.nodes().centerServers().orderedEntrySet();
List<Entry<String, CenterServer>> list = Config.nodes().centerServers().orderedEntry();
for (Entry<String, CenterServer> entry : set) {
for (Entry<String, CenterServer> entry : list) {
try {
ActionResponse response = CipherConnectionAction.get(false, Config.url_x_program_center_jaxrs("echo"));
ActionResponse response = CipherConnectionAction.get(false,
Config.url_x_program_center_jaxrs(entry, "echo"));
JsonElement jsonElement = response.getData();
......@@ -38,7 +38,7 @@ public class VoteCenterEvent implements Event {
|| (!Objects.equals(Config.resource_node_centersPirmaryPort(), entry.getValue().getPort()))
|| (!Objects.equals(Config.resource_node_centersPirmarySslEnable(),
entry.getValue().getSslEnable()))) {
logger.print("pirmary center set as:{}, in {}.", entry.getKey(), this.nodes(set));
logger.print("pirmary center set as:{}, in {}.", entry.getKey(), this.nodes(list));
Config.resource_node_centersPirmaryNode(entry.getKey());
Config.resource_node_centersPirmaryPort(entry.getValue().getPort());
Config.resource_node_centersPirmarySslEnable(entry.getValue().getSslEnable());
......@@ -53,9 +53,9 @@ public class VoteCenterEvent implements Event {
}
private String nodes(Set<Entry<String, CenterServer>> set) {
private String nodes(List<Entry<String, CenterServer>> list) {
List<String> os = new ArrayList<>();
for (Entry<String, CenterServer> entry : set) {
for (Entry<String, CenterServer> entry : list) {
os.add(entry.getKey());
}
return StringUtils.join(os, ",");
......
......@@ -88,7 +88,7 @@ public class WebServerTools extends JettySeverTools {
Gson gson = XGsonBuilder.instance();
LinkedHashMap<String, Object> map = new LinkedHashMap<>();
/** 覆盖掉配置的参数 */
com.x.base.core.project.config.CenterServer centerServerConfig = Config.nodes().centerServers().first();
com.x.base.core.project.config.CenterServer centerServerConfig = Config.nodes().centerServers().first().getValue();
map.putAll(centerServerConfig.getConfig());
List<Map<String, String>> centers = new ArrayList<>();
map.put("center", centers);
......
......@@ -84,8 +84,9 @@ class ActionCreate extends BaseAction {
emc.beginTransaction(Person.class);
emc.persist(identity, CheckPersistType.all);
person.setTopUnitList(
(ListTools.trim(person.getTopUnitList(), true, true, this.topUnit(business, unit).getId())));
List<Unit> topUnits = business.unit()
.pick(ListTools.trim(person.getTopUnitList(), true, true, this.topUnit(business, unit).getId()));
person.setTopUnitList(ListTools.extractField(topUnits, Unit.id_FIELDNAME, String.class, true, true));
emc.persist(person, CheckPersistType.all);
emc.commit();
......
package com.x.organization.assemble.control.jaxrs.identity;
import java.util.List;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
......@@ -68,8 +70,9 @@ class ActionEdit extends BaseAction {
}
}
emc.check(identity, CheckPersistType.all);
person.setTopUnitList(
(ListTools.trim(person.getTopUnitList(), true, true, this.topUnit(business, unit).getId())));
List<Unit> topUnits = business.unit()
.pick(ListTools.trim(person.getTopUnitList(), true, true, this.topUnit(business, unit).getId()));
person.setTopUnitList(ListTools.extractField(topUnits, Unit.id_FIELDNAME, String.class, true, true));
emc.check(person, CheckPersistType.all);
emc.commit();
ApplicationCache.notify(Identity.class);
......
......@@ -57,6 +57,8 @@ class ActionListLike extends BaseAction {
private String key;
@FieldDescribe("搜索组织范围,为空则不限定")
private List<String> unitList = new ArrayList<>();
@FieldDescribe("搜索职务范围,为空则不限定")
private List<String> dutyList = new ArrayList<>();
public String getKey() {
return key;
......
......@@ -23,10 +23,8 @@ import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.organization.OrganizationDefinition;
import com.x.base.core.project.tools.ListTools;
import com.x.organization.assemble.control.Business;
import com.x.organization.assemble.control.jaxrs.person.ActionGet.Wo;
import com.x.organization.core.entity.Person;
import net.sf.ehcache.Element;
import com.x.organization.core.entity.Unit;
class ActionCreate extends BaseAction {
......@@ -49,7 +47,8 @@ class ActionCreate extends BaseAction {
if ((!Config.token().isInitialManager(effectivePerson.getDistinguishedName()))
&& (!effectivePerson.isCipher())) {
Person current = business.person().pick(effectivePerson.getDistinguishedName());
person.setTopUnitList(current.getTopUnitList());
List<Unit> topUnits = business.unit().pick(current.getTopUnitList());
person.setTopUnitList(ListTools.extractField(topUnits, Unit.id_FIELDNAME, String.class, true, true));
} else {
person.setTopUnitList(new ArrayList<String>());
}
......
......@@ -21,6 +21,7 @@ import com.x.base.core.project.jaxrs.WoId;
import com.x.base.core.project.tools.ListTools;
import com.x.organization.assemble.control.Business;
import com.x.organization.core.entity.Person;
import com.x.organization.core.entity.Unit;
class ActionEdit extends BaseAction {
......@@ -37,6 +38,7 @@ class ActionEdit extends BaseAction {
throw new ExceptionAccessDenied(effectivePerson);
}
Wi.copier.copy(wi, person);
this.checkName(business, person.getName(), person.getId());
this.checkMobile(business, person.getMobile(), person.getId());
this.checkEmployee(business, person.getEmployee(), person.getId());
......@@ -52,6 +54,10 @@ class ActionEdit extends BaseAction {
person.setSuperior(superior.getId());
}
this.convertControllerList(effectivePerson, business, person);
if (ListTools.isNotEmpty(person.getTopUnitList())) {
List<Unit> topUnits = business.unit().pick(person.getTopUnitList());
person.setTopUnitList(ListTools.extractField(topUnits, Unit.id_FIELDNAME, String.class, true, true));
}
emc.beginTransaction(Person.class);
/*
* 从内存中pick出来的无法作为实体保存,不能在前面执行,以为后面的convertControllerList也有一个pick,
......
package com.x.program.center;
import org.apache.commons.lang3.BooleanUtils;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.connection.ActionResponse;
import com.x.base.core.project.connection.ConnectionAction;
import com.x.base.core.project.gson.GsonPropertyObject;
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.base.core.project.queue.AbstractQueue;
import com.x.program.center.CodeTransferQueue.Message;
import com.x.program.center.core.entity.Code;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
public class CodeTransferQueue extends AbstractQueue<Message> {
private static Logger logger = LoggerFactory.getLogger(CodeTransferQueue.class);
private static final Integer TRANSFER_INTERVAL = 30;
private static final Integer MAX_INTERVAL_COUNT = 5;
/** 进行缓存主要目的是判断上次发送时间,不能在短时间内重复发送 */
private static Ehcache cache = ApplicationCache.instance().getCache(Code.class, 1000, TRANSFER_INTERVAL,
TRANSFER_INTERVAL);
private static final String collect_code_transfer_address = "http://collect.xplatform.tech:20080/o2_collect_assemble/jaxrs/code/transfer";
public void execute(Message message) {
try {
if (BooleanUtils.isNotTrue(Config.collect().getEnable())) {
logger.warn("短信无法发送,系统没有启用O2云服务.");
return;
}
Integer count = this.intervalCount(message);
if (count > MAX_INTERVAL_COUNT) {
logger.warn("短信发送请求被忽略.手机号: {}, 在{}秒内重复发送{}次.", message.getMobile(), TRANSFER_INTERVAL, count);
return;
}
message.setName(Config.collect().getName());
message.setPassword(Config.collect().getPassword());
ActionResponse resp = ConnectionAction.put(collect_code_transfer_address, null, message);
Wo wo = resp.getData(Wo.class);
if (BooleanUtils.isNotTrue(wo.getValue())) {
throw new Exception("transfer code message error:" + resp);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static class Wo extends WrapBoolean {
}
private Integer intervalCount(Message message) {
String cacheKey = ApplicationCache.concreteCacheKey(message.getMobile());
Element element = cache.get(cacheKey);
Integer count = 1;
if ((null != element) && (null != element.getObjectValue())) {
count = (Integer) element.getObjectValue();
count = count + 1;
}
cache.put(new Element(cacheKey, count));
return count;
}
public class Message extends GsonPropertyObject {
private String mobile;
private String answer;
private String name;
private String password;
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getAnswer() {
return answer;
}
public void setAnswer(String answer) {
this.answer = answer;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
}
......@@ -35,7 +35,7 @@ public class ThisApplication {
public static LogQueue logQueue;
public static CodeTransferQueue codeTransferQueue;
// public static CodeTransferQueue codeTransferQueue;
public static List<Object> dingdingSyncOrganizationCallbackRequest = new ArrayList<>();
......@@ -96,7 +96,7 @@ public class ThisApplication {
try {
centerQueue.stop();
logQueue.stop();
codeTransferQueue.stop();
// codeTransferQueue.stop();
} catch (Exception e) {
e.printStackTrace();
}
......
......@@ -25,7 +25,6 @@ import com.x.program.center.jaxrs.pms.PmsAction;
import com.x.program.center.jaxrs.prompterrorlog.PromptErrorLogAction;
import com.x.program.center.jaxrs.qiyeweixin.QiyeweixinAction;
import com.x.program.center.jaxrs.schedule.ScheduleAction;
import com.x.program.center.jaxrs.storagemappings.StorageMappingsAction;
import com.x.program.center.jaxrs.test.TestAction;
import com.x.program.center.jaxrs.unexpectederrorlog.UnexpectedErrorLogAction;
import com.x.program.center.jaxrs.validation.ValidationAction;
......@@ -43,13 +42,10 @@ public class ActionApplication extends AbstractActionApplication {
classes.add(CenterAction.class);
classes.add(CodeAction.class);
classes.add(CollectAction.class);
// classes.add(DataMappingsAction.class);
classes.add(DistributeAction.class);
classes.add(PromptErrorLogAction.class);
// classes.add(StorageMappingsAction.class);
classes.add(UnexpectedErrorLogAction.class);
classes.add(WarnLogAction.class);
classes.add(TestAction.class);
classes.add(JestAction.class);
classes.add(ModuleAction.class);
classes.add(PmsAction.class);
......@@ -63,6 +59,7 @@ public class ActionApplication extends AbstractActionApplication {
classes.add(ScheduleAction.class);
classes.add(AuthenticationAction.class);
classes.add(ValidationAction.class);
classes.add(TestAction.class);
return classes;
}
}
......@@ -2,9 +2,9 @@ package com.x.program.center.jaxrs;
import javax.servlet.annotation.WebFilter;
import com.x.base.core.project.jaxrs.CipherManagerJaxrsFilter;
import com.x.base.core.project.jaxrs.AnonymousCipherManagerUserJaxrsFilter;
@WebFilter(urlPatterns = "/jaxrs/test/*", asyncSupported = true)
public class TestJaxrsFilter extends CipherManagerJaxrsFilter {
public class TestJaxrsFilter extends AnonymousCipherManagerUserJaxrsFilter {
}
......@@ -28,24 +28,7 @@ public class CenterAction extends StandardJaxrsAction {
private static Logger logger = LoggerFactory.getLogger(CenterAction.class);
// @PUT
// @Path("report/application")
// @JaxrsMethodDescribe(value = "应用报告.", action = ActionReportApplication.class)
// @Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
// @Consumes(MediaType.APPLICATION_JSON)
// public void report(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
// JsonElement jsonElement) {
// ActionResult<ActionReportApplication.Wo> result = new ActionResult<>();
// EffectivePerson effectivePerson = this.effectivePerson(request);
// try {
// result = new ActionReportApplication().execute(effectivePerson, jsonElement);
// } catch (Exception e) {
// logger.error(e, effectivePerson, request, jsonElement);
// result.error(e);
// }
// asyncResponse.resume(ResponseFactory.getDefaultActionResultResponse(result));
// }
@PUT
@Path("regist/applications")
@JaxrsMethodDescribe(value = "批量注册应用.", action = ActionRegistApplications.class)
......
......@@ -13,7 +13,7 @@ class ActionGet extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
Wo wo = new Wo();
wo.setCenterServer(WoCenterServer.copier.copy(Config.nodes().centerServers().first()));
wo.setCenterServer(WoCenterServer.copier.copy(Config.nodes().centerServers().first().getValue()));
result.setData(wo);
return result;
......
......@@ -11,7 +11,7 @@ class ActionGetCenterServer extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
Wo wo = Wo.copier.copy(Config.nodes().centerServers().first());
Wo wo = Wo.copier.copy(Config.nodes().centerServers().first().getValue());
result.setData(wo);
return result;
}
......
......@@ -21,10 +21,10 @@ class ActionGetProxy extends BaseAction {
ActionResult<Wo> result = new ActionResult<>();
Wo wo = new Wo();
wo.setApplicationList(new ArrayList<Application>());
wo.setHttpProtocol(Config.nodes().centerServers().first().getHttpProtocol());
wo.setHttpProtocol(Config.nodes().centerServers().first().getValue().getHttpProtocol());
Center center = new Center();
center.setProxyHost(Config.nodes().centerServers().first().getProxyHost());
center.setProxyPort(Config.nodes().centerServers().first().getProxyPort());
center.setProxyHost(Config.nodes().centerServers().first().getValue().getProxyHost());
center.setProxyPort(Config.nodes().centerServers().first().getValue().getProxyPort());
wo.setCenter(center);
for (Entry<String, Node> en : Config.nodes().entrySet()) {
if (null != en.getValue()) {
......
......@@ -14,10 +14,10 @@ public class ActionSetCenterServer extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
if (!Config.nodes().centerServers().first().getConfigApiEnable()) {
if (!Config.nodes().centerServers().first().getValue().getConfigApiEnable()) {
throw new ExceptionModifyConfig();
}
Wi.copier.copy(wi, Config.nodes().centerServers().first());
Wi.copier.copy(wi, Config.nodes().centerServers().first().getValue());
Config.nodes().save();
this.configFlush(effectivePerson);
Wo wo = new Wo();
......
......@@ -14,7 +14,7 @@ public class ActionSetCollect extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
if (!Config.nodes().centerServers().first().getConfigApiEnable()) {
if (!Config.nodes().centerServers().first().getValue().getConfigApiEnable()) {
throw new ExceptionModifyConfig();
}
Wi.copier.copy(wi, Config.collect());
......
......@@ -5,7 +5,6 @@ import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.config.Person;
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;
......@@ -15,7 +14,7 @@ public class ActionSetPerson extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
if (!Config.nodes().centerServers().first().getConfigApiEnable()) {
if (!Config.nodes().centerServers().first().getValue().getConfigApiEnable()) {
throw new ExceptionModifyConfig();
}
Wi.copier.copy(wi, Config.person());
......
......@@ -17,7 +17,7 @@ class ActionSetProxy extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
if (!Config.nodes().centerServers().first().getConfigApiEnable()) {
if (!Config.nodes().centerServers().first().getValue().getConfigApiEnable()) {
throw new ExceptionModifyConfig();
}
for (Entry<String, Node> en : Config.nodes().entrySet()) {
......
......@@ -26,7 +26,7 @@ public class ActionSetToken extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
if (!Config.nodes().centerServers().first().getConfigApiEnable()) {
if (!Config.nodes().centerServers().first().getValue().getConfigApiEnable()) {
throw new ExceptionModifyConfig();
}
/** 需要修改数据库密码 */
......
package com.x.program.center.jaxrs.test;
import java.util.ArrayList;
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.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import java.util.Map.Entry;
import com.x.base.core.project.Applications;
import com.x.base.core.project.config.CenterServer;
import com.x.base.core.project.config.CenterServers;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.exception.ExceptionAccessDenied;
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.organization.core.entity.Person;
class ActionTest1 extends BaseAction {
ActionResult<List<Object>> execute(EffectivePerson effectivePerson) throws Exception {
ActionResult<List<Object>> result = new ActionResult<>();
ActionResult<Wo> execute(EffectivePerson effectivePerson) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
EntityManager em = emc.get(Person.class);
List<Object> os = em.createQuery(this.criteriaQuery(Person.class, Person.class)).setMaxResults(1)
.getResultList();
result.setData(os);
ActionResult<Wo> result = new ActionResult<>();
if (!effectivePerson.isManager()) {
throw new ExceptionAccessDenied(effectivePerson);
}
return result;
}
private <T extends JpaObject, W> CriteriaQuery<Object> criteriaQuery(Class<T> t, Class<W> w) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
EntityManager em = emc.get(t);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Object> cq = cb.createQuery();
Root<T> root = cq.from(t);
Predicate p = cb.isNotNull(root.get("id"));
return cq.where(p);
Wo wo = new Wo();
wo.applications = gson.fromJson(Config.resource_node_applications(), Applications.class);
wo.resource_node_centersPirmaryNode = Config.resource_node_centersPirmaryNode();
wo.resource_node_centersPirmaryPort = Config.resource_node_centersPirmaryPort();
wo.resource_node_centersPirmarySslEnable = Config.resource_node_centersPirmarySslEnable();
for (Entry<String, CenterServer> en : Config.nodes().centerServers().orderedEntry()) {
wo.nodes_centerServers_ordered.add(en.getValue());
}
wo.centerServers = Config.nodes().centerServers();
result.setData(wo);
return result;
}
public static class Wo extends GsonPropertyObject {
private Applications applications;
private String resource_node_centersPirmaryNode;
private Integer resource_node_centersPirmaryPort;
private Boolean resource_node_centersPirmarySslEnable;
private List<CenterServer> nodes_centerServers_ordered = new ArrayList<>();
private CenterServers centerServers;
}
}
\ No newline at end of file
......@@ -34,7 +34,7 @@ public class TestAction extends StandardJaxrsAction {
@Consumes(MediaType.APPLICATION_JSON)
@JaxrsMethodDescribe(value = "测试,触发Area行政区域同步.", action = ActionTest1.class)
public void test1(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request) {
ActionResult<List<Object>> result = new ActionResult<>();
ActionResult<ActionTest1.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionTest1().execute(effectivePerson);
......
......@@ -45,7 +45,7 @@ public class CollectPerson extends BaseAction {
req.setSecret(Config.collect().getSecret());
req.setKey(Config.collect().getKey());
req.setMobileList(mobiles);
CenterServer centerServer = Config.nodes().centerServers().first();
CenterServer centerServer = Config.nodes().centerServers().first().getValue();
req.setCenterProxyHost(centerServer.getProxyHost());
if (StringUtils.isEmpty(req.getCenterProxyHost())) {
/* 如果没有设置地址,那么使用远程得到的服务器地址 */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册