Java Code Examples for org.apache.commons.collections4.ListUtils#subtract()

The following examples show how to use org.apache.commons.collections4.ListUtils#subtract() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActionCover.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private <T extends JpaObject> String idleNameWithQuery(Business business, String queryId, String name, Class<T> cls,
		String excludeId) throws Exception {
	if (StringUtils.isEmpty(name)) {
		return "";
	}
	List<String> list = new ArrayList<>();
	list.add(name);
	for (int i = 1; i < 99; i++) {
		list.add(name + String.format("%02d", i));
	}
	list.add(StringTools.uniqueToken());
	EntityManager em = business.entityManagerContainer().get(cls);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<T> root = cq.from(cls);
	Predicate p = root.get("name").in(list);
	p = cb.and(p, cb.equal(root.get("query"), queryId));
	if (StringUtils.isNotEmpty(excludeId)) {
		p = cb.and(p, cb.notEqual(root.get(JpaObject.id_FIELDNAME), excludeId));
	}
	cq.select(root.get("name")).where(p);
	List<String> os = em.createQuery(cq).getResultList();
	list = ListUtils.subtract(list, os);
	return list.get(0);
}
 
Example 2
Source File: ActionCover.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private <T extends JpaObject> String idleAliasWithApplication(Business business, String applicationId, String alias,
		Class<T> cls, String excludeId) throws Exception {
	if (StringUtils.isEmpty(alias)) {
		return "";
	}
	List<String> list = new ArrayList<>();
	list.add(alias);
	for (int i = 1; i < 99; i++) {
		list.add(alias + String.format("%02d", i));
	}
	list.add(StringTools.uniqueToken());
	EntityManager em = business.entityManagerContainer().get(cls);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<T> root = cq.from(cls);
	Predicate p = root.get("alias").in(list);
	p = cb.and(p, cb.equal(root.get("application"), applicationId));
	if (StringUtils.isNotEmpty(excludeId)) {
		p = cb.and(p, cb.notEqual(root.get(JpaObject.id_FIELDNAME), excludeId));
	}
	cq.select(root.get("alias")).where(p);
	List<String> os = em.createQuery(cq).getResultList();
	list = ListUtils.subtract(list, os);
	return list.get(0);
}
 
Example 3
Source File: BaseAction.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public String adjustFileName(Business business, String job, String fileName) throws Exception {
	List<String> list = new ArrayList<>();
	list.add(fileName);
	String base = FilenameUtils.getBaseName(fileName);
	String extension = FilenameUtils.getExtension(fileName);
	for (int i = 1; i < 50; i++) {
		list.add(base + i + (StringUtils.isEmpty(extension) ? "" : "." + extension));
	}
	list.add(StringTools.uniqueToken());
	EntityManager em = business.entityManagerContainer().get(Attachment.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<Attachment> root = cq.from(Attachment.class);
	Predicate p = root.get(Attachment_.name).in(list);
	p = cb.and(p, cb.equal(root.get(Attachment_.job), job));
	cq.select(root.get(Attachment_.name)).where(p);
	List<String> os = em.createQuery(cq).getResultList();
	list = ListUtils.subtract(list, os);
	return list.get(0);
}
 
Example 4
Source File: ActionCover.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 根据id 和 name属性,查询重复的对象,适用CategoryInfo
 * @param business
 * @param id
 * @param name
 * @param cls
 * @param excludeId
 * @return
 * @throws Exception
 */
private <T extends JpaObject> String idleNameWithCategory(Business business, String id, String name,
		Class<T> cls, String excludeId) throws Exception {
	if (StringUtils.isEmpty(name)) {
		return "";
	}
	List<String> list = new ArrayList<>();
	list.add(name);
	for (int i = 1; i < 99; i++) {
		list.add(name + String.format("%02d", i));
	}
	list.add(StringTools.uniqueToken());
	EntityManager em = business.entityManagerContainer().get( CategoryInfo.class );
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<CategoryInfo> root = cq.from(CategoryInfo.class);
	Predicate p = root.get( CategoryInfo_.categoryName ).in(list);
	p = cb.and(p, cb.equal(root.get( CategoryInfo_.id ), id));
	if (StringUtils.isNotEmpty(excludeId)) {
		p = cb.and(p, cb.notEqual(root.get(JpaObject.id_FIELDNAME), excludeId));
	}
	cq.select(root.get( CategoryInfo_.categoryName  )).where(p);
	List<String> os = em.createQuery(cq).getResultList();
	list = ListUtils.subtract(list, os);
	return list.get(0);
}
 
Example 5
Source File: ActionCover.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private <T extends JpaObject> String idleAliasWithQuery(Business business, String queryId, String alias,
		Class<T> cls, String excludeId) throws Exception {
	if (StringUtils.isEmpty(alias)) {
		return "";
	}
	List<String> list = new ArrayList<>();
	list.add(alias);
	for (int i = 1; i < 99; i++) {
		list.add(alias + String.format("%02d", i));
	}
	list.add(StringTools.uniqueToken());
	EntityManager em = business.entityManagerContainer().get(cls);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<T> root = cq.from(cls);
	Predicate p = root.get("alias").in(list);
	p = cb.and(p, cb.equal(root.get("query"), queryId));
	if (StringUtils.isNotEmpty(excludeId)) {
		p = cb.and(p, cb.notEqual(root.get(JpaObject.id_FIELDNAME), excludeId));
	}
	cq.select(root.get("alias")).where(p);
	List<String> os = em.createQuery(cq).getResultList();
	list = ListUtils.subtract(list, os);
	return list.get(0);
}
 
Example 6
Source File: BaseAction.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
protected <T extends JpaObject> String idlePortalAlias(Business business, String alias, String excludeId)
		throws Exception {
	if (StringUtils.isEmpty(alias)) {
		return "";
	}
	List<String> list = new ArrayList<>();
	list.add(alias);
	for (int i = 1; i < 99; i++) {
		list.add(alias + String.format("%02d", i));
	}
	list.add(StringTools.uniqueToken());
	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 = root.get(Portal_.alias).in(list);
	if (StringUtils.isNotEmpty(excludeId)) {
		p = cb.and(p, cb.notEqual(root.get(JpaObject.id_FIELDNAME), excludeId));
	}
	cq.select(root.get(Portal_.alias)).where(p);
	List<String> os = em.createQuery(cq).getResultList();
	list = ListUtils.subtract(list, os);
	return list.get(0);
}
 
Example 7
Source File: ActionCover.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 根据id 和 alias属性,查询重复的对象,适用CategoryInfo
 * @param business
 * @param id
 * @param alias
 * @param cls
 * @param excludeId
 * @return
 * @throws Exception
 */
private <T extends JpaObject> String idleAliasWithCategory(Business business, String id, String alias,
		Class<T> cls, String excludeId) throws Exception {
	if (StringUtils.isEmpty(alias)) {
		return "";
	}
	List<String> list = new ArrayList<>();
	list.add(alias);
	for (int i = 1; i < 99; i++) {
		list.add(alias + String.format("%02d", i));
	}
	list.add(StringTools.uniqueToken());
	EntityManager em = business.entityManagerContainer().get(CategoryInfo.class );
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<CategoryInfo> root = cq.from(CategoryInfo.class);
	Predicate p = root.get( CategoryInfo_.categoryAlias ).in( list );
	p = cb.and(p, cb.equal(root.get(CategoryInfo_.id ), id));
	if (StringUtils.isNotEmpty(excludeId)) {
		p = cb.and(p, cb.notEqual(root.get(JpaObject.id_FIELDNAME), excludeId));
	}
	cq.select(root.get(CategoryInfo_.categoryAlias)).where(p);
	List<String> os = em.createQuery(cq).getResultList();
	list = ListUtils.subtract(list, os);
	return list.get(0);
}
 
Example 8
Source File: BaseAction.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
protected <T extends JpaObject> String idleAppInfoName(Business business, String name, String excludeId)
		throws Exception {
	if (StringUtils.isEmpty(name)) {
		return "";
	}
	List<String> list = new ArrayList<>();
	list.add(name);
	for (int i = 1; i < 99; i++) {
		list.add(name + String.format("%02d", i));
	}
	list.add(StringTools.uniqueToken());
	EntityManager em = business.entityManagerContainer().get(AppInfo.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<AppInfo> root = cq.from(AppInfo.class);
	Predicate p = root.get(AppInfo_.appName).in(list);
	if (StringUtils.isNotEmpty(excludeId)) {
		p = cb.and(p, cb.notEqual(root.get(JpaObject.id_FIELDNAME), excludeId));
	}
	cq.select(root.get(AppInfo_.appName)).where(p);
	List<String> os = em.createQuery(cq).getResultList();
	list = ListUtils.subtract(list, os);
	return list.get(0);
}
 
Example 9
Source File: BaseAction.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
protected <T extends JpaObject> String idlePortalAlias(Business business, String alias, String excludeId)
		throws Exception {
	if (StringUtils.isEmpty(alias)) {
		return "";
	}
	List<String> list = new ArrayList<>();
	list.add(alias);
	for (int i = 1; i < 99; i++) {
		list.add(alias + String.format("%02d", i));
	}
	list.add(StringTools.uniqueToken());
	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 = root.get(Portal_.alias).in(list);
	if (StringUtils.isNotEmpty(excludeId)) {
		p = cb.and(p, cb.notEqual(root.get(JpaObject.id_FIELDNAME), excludeId));
	}
	cq.select(root.get(Portal_.alias)).where(p);
	List<String> os = em.createQuery(cq).getResultList();
	list = ListUtils.subtract(list, os);
	return list.get(0);
}
 
Example 10
Source File: BaseAction.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
protected <T extends JpaObject> String idlePortalName(Business business, String name, String excludeId)
		throws Exception {
	if (StringUtils.isEmpty(name)) {
		return "";
	}
	List<String> list = new ArrayList<>();
	list.add(name);
	for (int i = 1; i < 99; i++) {
		list.add(name + String.format("%02d", i));
	}
	list.add(StringTools.uniqueToken());
	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 = root.get(Portal_.name).in(list);
	if (StringUtils.isNotEmpty(excludeId)) {
		p = cb.and(p, cb.notEqual(root.get(JpaObject.id_FIELDNAME), excludeId));
	}
	cq.select(root.get(Portal_.name)).where(p);
	List<String> os = em.createQuery(cq).getResultList();
	list = ListUtils.subtract(list, os);
	return list.get(0);
}
 
Example 11
Source File: ActionCover.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private <T extends JpaObject> String idleNameWithApplication(Business business, String applicationId, String name,
		Class<T> cls, String excludeId) throws Exception {
	if (StringUtils.isEmpty(name)) {
		return "";
	}
	List<String> list = new ArrayList<>();
	list.add(name);
	for (int i = 1; i < 99; i++) {
		list.add(name + String.format("%02d", i));
	}
	list.add(StringTools.uniqueToken());
	EntityManager em = business.entityManagerContainer().get(cls);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<T> root = cq.from(cls);
	Predicate p = root.get("name").in(list);
	p = cb.and(p, cb.equal(root.get("application"), applicationId));
	if (StringUtils.isNotEmpty(excludeId)) {
		p = cb.and(p, cb.notEqual(root.get(JpaObject.id_FIELDNAME), excludeId));
	}
	cq.select(root.get("name")).where(p);
	List<String> os = em.createQuery(cq).getResultList();
	list = ListUtils.subtract(list, os);
	return list.get(0);
}
 
Example 12
Source File: AeiObjects.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
private void commitData() throws Exception {
	List<Attachment> os = ListUtils.subtract(this.getAttachments(), this.getDeleteAttachments());
	os = ListUtils.sum(os, this.getCreateAttachments());
	Data data = this.getData().removeWork().removeAttachmentList().setAttachmentList(os);
	if (ListTools.isNotEmpty(this.getCreateWorkCompleteds())) {
		data.setWork(this.getCreateWorkCompleteds().get(0));
	} else {
		data.setWork(this.getWork());
	}
	this.getWorkDataHelper().update(data);
}
 
Example 13
Source File: ActionCreate.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
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);
		Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
		if (StringUtils.isEmpty(wi.getFileId())) {
			throw new ExceptionShareNameEmpty();
		}
		if (StringUtils.isEmpty(wi.getShareType())) {
			throw new Exception("shareType can not be empty.");
		}
		Share share = business.share().getShareByFileId(wi.getFileId(),effectivePerson.getDistinguishedName());
		boolean isExist = true;
		List<String> oldUserList = new ArrayList<>();
		List<String> oldOrgList = new ArrayList<>();
		if(share == null) {
			share = Wi.copier.copy(wi);
			isExist = false;
		}else{
			oldUserList.addAll(share.getShareUserList());
			oldOrgList.addAll(share.getShareOrgList());
			share.setPassword(wi.getPassword());
			share.setShareUserList(wi.getShareUserList());
			share.setShareOrgList(wi.getShareOrgList());
			share.setShareType(wi.getShareType());
		}
		if("password".equals(wi.getShareType())){
			if(StringUtils.isBlank(share.getPassword())){
				throw new Exception("password can not be empty.");
			}
		}else{
			if((wi.getShareUserList()==null || wi.getShareUserList().isEmpty()) &&
					(wi.getShareOrgList()==null || wi.getShareOrgList().isEmpty())){
				throw new Exception("shareUserList or shareOrgList can not be empty.");
			}
		}
		Attachment2 attachment = emc.find(wi.getFileId(), Attachment2.class);
		if(attachment == null) {
			Folder2 folder = emc.find(wi.getFileId(), Folder2.class);
			if(folder==null){
				throw new ExceptionShareNotExist(wi.getFileId());
			}else{
				if (!effectivePerson.isManager() && !StringUtils.equals(folder.getPerson(), effectivePerson.getDistinguishedName())) {
					throw new Exception("person{name:" + effectivePerson.getDistinguishedName() + "} access folder{id:" + wi.getFileId()
							+ "} denied.");
				}
				share.setFileType("folder");
				share.setName(folder.getName());
				share.setPerson(folder.getPerson());
			}
		}else{
			if (!effectivePerson.isManager() && !StringUtils.equals(attachment.getPerson(), effectivePerson.getDistinguishedName())) {
				throw new Exception("person{name:" + effectivePerson.getDistinguishedName() + "} access att{id:" + wi.getFileId()
						+ "} denied.");
			}
			share.setFileType("attachment");
			share.setName(attachment.getName());
			share.setLength(attachment.getLength());
			share.setExtension(attachment.getExtension());
			share.setPerson(attachment.getPerson());
		}
		share.setLastUpdateTime(new Date());
		if(share.getValidTime()==null){
			share.setValidTime(DateTools.getDateAfterYearAdjust(new Date(),100,null,null));
		}

		emc.beginTransaction(Share.class);
		if(isExist){
			emc.check(share, CheckPersistType.all);
		}else {
			emc.persist(share, CheckPersistType.all);
		}
		emc.commit();
		if(!"password".equals(wi.getShareType())){
			if(!oldOrgList.isEmpty()){
				oldUserList.addAll(business.organization().person().listWithUnitSubNested( oldOrgList ));
			}
			List<String> newUserList = new ArrayList<>();
			newUserList.addAll(share.getShareUserList());
			if(!share.getShareOrgList().isEmpty()){
				newUserList.addAll(business.organization().person().listWithUnitSubNested( share.getShareOrgList() ));
			}
			List<String> shareAdds = ListUtils.subtract(newUserList, oldOrgList);
			ListOrderedSet<String> set = new ListOrderedSet<>();
			set.addAll(shareAdds);
			shareAdds = set.asList();
			/* 发送共享通知 */
			for (String str : shareAdds) {
				this.message_send_attachment_share(share, str);
			}
		}
		Wo wo = new Wo();
		wo.setId(share.getId());
		result.setData(wo);
		return result;
	}
}
 
Example 14
Source File: V2Reset.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
ActionResult<Wo> execute(EffectivePerson effectivePerson, String id, JsonElement jsonElement) throws Exception {
	ActionResult<Wo> result = new ActionResult<>();
	this.wi = this.convertToWrapIn(jsonElement, Wi.class);
	this.effectivePerson = effectivePerson;
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {

		Business business = new Business(emc);

		this.task = emc.find(id, Task.class);

		if (null == task) {
			throw new ExceptionEntityNotExist(id, Task.class);
		}

		this.workLog = emc.firstEqualAndEqual(WorkLog.class, WorkLog.job_FIELDNAME, task.getJob(),
				WorkLog.fromActivityToken_FIELDNAME, task.getActivityToken());

		if (null == workLog) {
			throw new ExceptionEntityNotExist(WorkLog.class);
		}

		this.work = emc.find(task.getWork(), Work.class);

		if (null == work) {
			throw new ExceptionEntityNotExist(id, Work.class);
		}

		WoControl control = business.getControl(effectivePerson, task, WoControl.class);

		if (BooleanUtils.isNotTrue(control.getAllowReset())) {
			throw new ExceptionAccessDenied(effectivePerson, task);
		}

		existTaskIds = emc.idsEqual(Task.class, Task.job_FIELDNAME, work.getJob());
		/* 检查reset人员 */
		identites = business.organization().identity().list(wi.getIdentityList());

		/* 在新增待办人员中删除当前的处理人 */
		identites = ListUtils.subtract(identites, ListTools.toList(task.getIdentity()));

		if (ListTools.isEmpty(identites)) {
			throw new ExceptionIdentityEmpty();
		}

		if (StringUtils.isNotEmpty(wi.getRouteName()) || StringUtils.isNotEmpty(wi.getOpinion())) {
			emc.beginTransaction(Task.class);
			/* 如果有选择新的路由那么覆盖之前的选择 */
			if (StringUtils.isNotEmpty(wi.getRouteName())) {
				task.setRouteName(wi.getRouteName());
			}
			/* 如果有新的流程意见那么覆盖流程意见 */
			if (StringUtils.isNotEmpty(wi.getOpinion())) {
				task.setOpinion(wi.getOpinion());
			}
			emc.commit();
		}
	}

	this.reset();

	if (!wi.getKeep()) {
		this.processingTask();
	}

	this.processing();

	this.record();

	if (StringUtils.isNotEmpty(this.taskCompletedId)) {
		this.updateTaskCompleted();
	}

	this.updateTask();

	Wo wo = Wo.copier.copy(record);
	result.setData(wo);
	return result;
}
 
Example 15
Source File: ActionEdit.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
ActionResult<Wo> execute(EffectivePerson effectivePerson, String id, JsonElement jsonElement) throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		ActionResult<Wo> result = new ActionResult<>();
		Business business = new Business(emc);
		Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
		Meeting meeting = emc.find(id, Meeting.class);
		if (null == meeting) {
			throw new ExceptionMeetingNotExist(id);
		}
		if (!business.meetingEditAvailable(effectivePerson, meeting)) {
			throw new ExceptionAccessDenied(effectivePerson);
		}
		Room room = emc.find(wi.getRoom(), Room.class);
		if (null == room) {
			throw new ExceptionRoomNotExist(wi.getRoom());
		}
		emc.beginTransaction(Meeting.class);
		List<String> modifyInvitePersonList = ListUtils.subtract(
				this.convertToPerson(business, ListTools.trim(wi.getInvitePersonList(), true, true)),
				meeting.getInvitePersonList());
		List<String> invitePersonList = new ArrayList<>(meeting.getInvitePersonList());
		invitePersonList.addAll(modifyInvitePersonList);
		Wi.copier.copy(wi, meeting);
		meeting.setInvitePersonList(invitePersonList);
		if (!business.room().checkIdle(meeting.getRoom(), meeting.getStartTime(), meeting.getCompletedTime(),
				meeting.getId())) {
			throw new ExceptionRoomNotAvailable(room.getName());
		}
		emc.persist(meeting, CheckPersistType.all);
		emc.commit();
		if (ConfirmStatus.allow.equals(meeting.getConfirmStatus())) {
			for (String _s : modifyInvitePersonList) {
				MessageFactory.meeting_invite(_s, meeting, room);
			}
			this.notifyMeetingInviteMessage(business, meeting);
		}
		Wo wo = new Wo();
		wo.setId(meeting.getId());
		result.setData(wo);
		return result;
	}
}
 
Example 16
Source File: V2Retract.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
private void record() throws Exception {
	record = new Record(workLog);
	record.setType(Record.TYPE_RETRACT);
	record.getProperties().setElapsed(
			Config.workTime().betweenMinutes(record.getProperties().getStartTime(), record.getRecordTime()));
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		work = emc.find(work.getId(), Work.class);
		if (null != work) {
			record.setArrivedActivity(work.getActivity());
			record.setArrivedActivityType(work.getActivityType());
			record.setArrivedActivityToken(work.getActivityToken());
			record.setArrivedActivityName(work.getActivityName());
			record.setArrivedActivityAlias(work.getActivityAlias());
			record.setIdentity(taskCompleted.getIdentity());
			record.setPerson(taskCompleted.getPerson());
			record.setUnit(taskCompleted.getUnit());
			final List<String> nextTaskIdentities = new ArrayList<>();
			List<String> ids = emc.idsEqual(Task.class, Task.job_FIELDNAME, work.getJob());
			ids = ListUtils.subtract(ids, existTaskIds);
			List<Task> list = emc.fetch(ids, Task.class,
					ListTools.toList(Task.identity_FIELDNAME, Task.job_FIELDNAME, Task.work_FIELDNAME,
							Task.activity_FIELDNAME, Task.activityAlias_FIELDNAME, Task.activityName_FIELDNAME,
							Task.activityToken_FIELDNAME, Task.activityType_FIELDNAME, Task.identity_FIELDNAME));
			list.stream().collect(Collectors.groupingBy(Task::getActivity, Collectors.toList())).entrySet().stream()
					.forEach(o -> {
						Task task = o.getValue().get(0);
						NextManual nextManual = new NextManual();
						nextManual.setActivity(task.getActivity());
						nextManual.setActivityAlias(task.getActivityAlias());
						nextManual.setActivityName(task.getActivityName());
						nextManual.setActivityToken(task.getActivityToken());
						nextManual.setActivityType(task.getActivityType());
						for (Task t : o.getValue()) {
							nextManual.getTaskIdentityList().add(t.getIdentity());
							nextTaskIdentities.add(t.getIdentity());
						}
						record.getProperties().getNextManualList().add(nextManual);
					});
			/* 去重 */
			record.getProperties().setNextManualTaskIdentityList(ListTools.trim(nextTaskIdentities, true, true));
		}
	}
	WoId resp = ThisApplication.context().applications()
			.postQuery(effectivePerson.getDebugger(), x_processplatform_service_processing.class,
					Applications.joinQueryUri("record", "job", work.getJob()), record, this.work.getJob())
			.getData(WoId.class);
	if (StringUtils.isBlank(resp.getId())) {
		throw new ExceptionRetract(this.work.getId());
	}
}
 
Example 17
Source File: ActionReset.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
ActionResult<Wo> execute(EffectivePerson effectivePerson, String id, JsonElement jsonElement) throws Exception {
	ActionResult<Wo> result = new ActionResult<>();
	Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
	Task task = null;
	List<String> identites = new ArrayList<>();
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		Business business = new Business(emc);
		task = emc.find(id, Task.class);
		if (null == task) {
			throw new ExceptionEntityNotExist(id, Task.class);
		}
		WoControl control = business.getControl(effectivePerson, task, WoControl.class);

		if (BooleanUtils.isNotTrue(control.getAllowReset())) {
			throw new ExceptionAccessDenied(effectivePerson, task);
		}

		/* 检查reset人员 */
		identites = business.organization().identity().list(wi.getIdentityList());

		/* 在新增待办人员中删除当前的处理人 */
		identites = ListUtils.subtract(identites, ListTools.toList(task.getIdentity()));

		if (!identites.isEmpty()) {
			emc.beginTransaction(Task.class);
			/* 如果有选择新的路由那么覆盖之前的选择 */
			if (StringUtils.isNotEmpty(wi.getRouteName())) {
				task.setRouteName(wi.getRouteName());
			}
			/* 如果有新的流程意见那么覆盖流程意见 */
			if (StringUtils.isNotEmpty(wi.getOpinion())) {
				task.setOpinion(wi.getOpinion());
			}
			emc.commit();
			wi.setIdentityList(identites);
		}
	}

	if (!identites.isEmpty()) {
		ThisApplication.context().applications().putQuery(x_processplatform_service_processing.class,
				Applications.joinQueryUri("task", task.getId(), "reset"), wi, task.getJob());
	}

	Wo wo = new Wo();
	wo.setId(task.getWork());
	result.setData(wo);
	return result;
}
 
Example 18
Source File: V2Reroute.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
private void record() throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		Business business = new Business(emc);
		final List<String> nextTaskIdentities = new ArrayList<>();
		record = new Record(workLog);
		record.setPerson(effectivePerson.getDistinguishedName());
		record.setType(Record.TYPE_REROUTE);
		record.setArrivedActivity(destinationActivity.getId());
		record.setArrivedActivityAlias(destinationActivity.getAlias());
		record.setArrivedActivityName(destinationActivity.getName());
		record.setArrivedActivityType(destinationActivity.getActivityType());
		record.getProperties().setElapsed(
				Config.workTime().betweenMinutes(record.getProperties().getStartTime(), record.getRecordTime()));
		/* 需要记录处理人,先查看当前用户有没有之前处理过的信息,如果没有,取默认身份 */
		TaskCompleted existTaskCompleted = emc.firstEqualAndEqual(TaskCompleted.class, TaskCompleted.job_FIELDNAME,
				work.getJob(), TaskCompleted.person_FIELDNAME, effectivePerson.getDistinguishedName());
		record.setPerson(effectivePerson.getDistinguishedName());
		if (null != existTaskCompleted) {
			record.setIdentity(existTaskCompleted.getIdentity());
			record.setUnit(existTaskCompleted.getUnit());
		} else {
			record.setIdentity(
					business.organization().identity().getMajorWithPerson(effectivePerson.getDistinguishedName()));
			record.setUnit(business.organization().unit().getWithIdentity(record.getIdentity()));
		}
		List<String> ids = emc.idsEqual(Task.class, Task.job_FIELDNAME, work.getJob());
		ids = ListUtils.subtract(ids, existTaskIds);
		List<Task> list = emc.fetch(ids, Task.class,
				ListTools.toList(Task.identity_FIELDNAME, Task.job_FIELDNAME, Task.work_FIELDNAME,
						Task.activity_FIELDNAME, Task.activityAlias_FIELDNAME, Task.activityName_FIELDNAME,
						Task.activityToken_FIELDNAME, Task.activityType_FIELDNAME, Task.identity_FIELDNAME));
		list.stream().collect(Collectors.groupingBy(Task::getActivity, Collectors.toList())).entrySet().stream()
				.forEach(o -> {
					Task task = o.getValue().get(0);
					NextManual nextManual = new NextManual();
					nextManual.setActivity(task.getActivity());
					nextManual.setActivityAlias(task.getActivityAlias());
					nextManual.setActivityName(task.getActivityName());
					nextManual.setActivityToken(task.getActivityToken());
					nextManual.setActivityType(task.getActivityType());
					for (Task t : o.getValue()) {
						nextManual.getTaskIdentityList().add(t.getIdentity());
						nextTaskIdentities.add(t.getIdentity());
					}
					record.getProperties().getNextManualList().add(nextManual);
				});
		/* 去重 */
		record.getProperties().setNextManualTaskIdentityList(ListTools.trim(nextTaskIdentities, true, true));
	}
	WoId resp = ThisApplication.context().applications()
			.postQuery(effectivePerson.getDebugger(), x_processplatform_service_processing.class,
					Applications.joinQueryUri("record", "job", work.getJob()), record, this.work.getJob())
			.getData(WoId.class);
	if (StringUtils.isBlank(resp.getId())) {
		throw new ExceptionRecord(this.work.getId());
	}
}
 
Example 19
Source File: ActionEdit.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
ActionResult<Wo> execute(EffectivePerson effectivePerson, String id, JsonElement jsonElement) throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		ActionResult<Wo> result = new ActionResult<>();
		Business business = new Business(emc);
		Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
		Meeting meeting = emc.find(id, Meeting.class);
		if (null == meeting) {
			throw new ExceptionMeetingNotExist(id);
		}
		if (!business.meetingEditAvailable(effectivePerson, meeting)) {
			throw new ExceptionAccessDenied(effectivePerson);
		}
		Room room = emc.find(wi.getRoom(), Room.class);
		if (null == room) {
			throw new ExceptionRoomNotExist(wi.getRoom());
		}
		emc.beginTransaction(Meeting.class);
		List<String> modifyInvitePersonList = ListUtils.subtract(
				this.convertToPerson(business, ListTools.trim(wi.getInvitePersonList(), true, true)),
				meeting.getInvitePersonList());
		List<String> invitePersonList = new ArrayList<>(meeting.getInvitePersonList());
		invitePersonList.addAll(modifyInvitePersonList);
		Wi.copier.copy(wi, meeting);
		meeting.setInvitePersonList(invitePersonList);
		if (!business.room().checkIdle(meeting.getRoom(), meeting.getStartTime(), meeting.getCompletedTime(),
				meeting.getId())) {
			throw new ExceptionRoomNotAvailable(room.getName());
		}
		emc.persist(meeting, CheckPersistType.all);
		emc.commit();
		if (ConfirmStatus.allow.equals(meeting.getConfirmStatus())) {
			for (String _s : modifyInvitePersonList) {
				MessageFactory.meeting_invite(_s, meeting, room);
			}
			this.notifyMeetingInviteMessage(business, meeting);
		}
		Wo wo = new Wo();
		wo.setId(meeting.getId());
		result.setData(wo);
		return result;
	}
}
 
Example 20
Source File: ActionCreate.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
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);
		Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
		if (StringUtils.isEmpty(wi.getFileId())) {
			throw new ExceptionShareNameEmpty();
		}
		if (StringUtils.isEmpty(wi.getShareType())) {
			throw new Exception("shareType can not be empty.");
		}
		Share share = business.share().getShareByFileId(wi.getFileId(),effectivePerson.getDistinguishedName());
		boolean isExist = true;
		List<String> oldUserList = new ArrayList<>();
		List<String> oldOrgList = new ArrayList<>();
		if(share == null) {
			share = Wi.copier.copy(wi);
			isExist = false;
		}else{
			oldUserList.addAll(share.getShareUserList());
			oldOrgList.addAll(share.getShareOrgList());
			share.setPassword(wi.getPassword());
			share.setShareUserList(wi.getShareUserList());
			share.setShareOrgList(wi.getShareOrgList());
			share.setShareType(wi.getShareType());
		}
		if("password".equals(wi.getShareType())){
			if(StringUtils.isBlank(share.getPassword())){
				throw new Exception("password can not be empty.");
			}
		}else{
			if((wi.getShareUserList()==null || wi.getShareUserList().isEmpty()) &&
					(wi.getShareOrgList()==null || wi.getShareOrgList().isEmpty())){
				throw new Exception("shareUserList or shareOrgList can not be empty.");
			}
		}
		Attachment2 attachment = emc.find(wi.getFileId(), Attachment2.class);
		if(attachment == null) {
			Folder2 folder = emc.find(wi.getFileId(), Folder2.class);
			if(folder==null){
				throw new ExceptionShareNotExist(wi.getFileId());
			}else{
				if (!effectivePerson.isManager() && !StringUtils.equals(folder.getPerson(), effectivePerson.getDistinguishedName())) {
					throw new Exception("person{name:" + effectivePerson.getDistinguishedName() + "} access folder{id:" + wi.getFileId()
							+ "} denied.");
				}
				share.setFileType("folder");
				share.setName(folder.getName());
				share.setPerson(folder.getPerson());
			}
		}else{
			if (!effectivePerson.isManager() && !StringUtils.equals(attachment.getPerson(), effectivePerson.getDistinguishedName())) {
				throw new Exception("person{name:" + effectivePerson.getDistinguishedName() + "} access att{id:" + wi.getFileId()
						+ "} denied.");
			}
			share.setFileType("attachment");
			share.setName(attachment.getName());
			share.setLength(attachment.getLength());
			share.setExtension(attachment.getExtension());
			share.setPerson(attachment.getPerson());
		}
		share.setLastUpdateTime(new Date());
		if(share.getValidTime()==null){
			share.setValidTime(DateTools.getDateAfterYearAdjust(new Date(),100,null,null));
		}

		emc.beginTransaction(Share.class);
		if(isExist){
			emc.check(share, CheckPersistType.all);
		}else {
			emc.persist(share, CheckPersistType.all);
		}
		emc.commit();
		if(!"password".equals(wi.getShareType())){
			if(!oldOrgList.isEmpty()){
				oldUserList.addAll(business.organization().person().listWithUnitSubNested( oldOrgList ));
			}
			List<String> newUserList = new ArrayList<>();
			newUserList.addAll(share.getShareUserList());
			if(!share.getShareOrgList().isEmpty()){
				newUserList.addAll(business.organization().person().listWithUnitSubNested( share.getShareOrgList() ));
			}
			List<String> shareAdds = ListUtils.subtract(newUserList, oldOrgList);
			ListOrderedSet<String> set = new ListOrderedSet<>();
			set.addAll(shareAdds);
			shareAdds = set.asList();
			/* 发送共享通知 */
			for (String str : shareAdds) {
				this.message_send_attachment_share(share, str);
			}
		}
		Wo wo = new Wo();
		wo.setId(share.getId());
		result.setData(wo);
		return result;
	}
}