use of org.apache.ofbiz.entity.Delegator in project ofbiz-framework by apache.
the class WorkEffortKeywordIndex method indexKeywords.
public static void indexKeywords(GenericValue workEffort) throws GenericEntityException {
if (workEffort == null) {
return;
}
Delegator delegator = workEffort.getDelegator();
if (delegator == null) {
return;
}
String workEffortId = workEffort.getString("workEffortId");
String separators = KeywordSearchUtil.getSeparators();
String stopWordBagOr = KeywordSearchUtil.getStopWordBagOr();
String stopWordBagAnd = KeywordSearchUtil.getStopWordBagAnd();
boolean removeStems = KeywordSearchUtil.getRemoveStems();
Set<String> stemSet = KeywordSearchUtil.getStemSet();
Map<String, Long> keywords = new TreeMap<>();
List<String> strings = new LinkedList<>();
int widWeight = 1;
try {
widWeight = EntityUtilProperties.getPropertyAsInteger("workeffort", "index.weight.WorkEffort.workEffortId", 1).intValue();
} catch (Exception e) {
Debug.logWarning("Could not parse weight number: " + e.toString(), module);
}
keywords.put(workEffort.getString("workEffortId").toLowerCase(Locale.getDefault()), Long.valueOf(widWeight));
addWeightedKeywordSourceString(workEffort, "workEffortName", strings);
addWeightedKeywordSourceString(workEffort, "workEffortTypeId", strings);
addWeightedKeywordSourceString(workEffort, "currentStatusId", strings);
if (!"0".equals(EntityUtilProperties.getPropertyValue("workeffort", "index.weight.WorkEffortNoteAndData.noteInfo", "1", delegator))) {
List<GenericValue> workEffortNotes = EntityQuery.use(delegator).from("WorkEffortNoteAndData").where("workEffortId", workEffortId).queryList();
for (GenericValue workEffortNote : workEffortNotes) {
addWeightedKeywordSourceString(workEffortNote, "noteInfo", strings);
}
}
// WorkEffortAttribute
if (!"0".equals(EntityUtilProperties.getPropertyValue("workeffort", "index.weight.WorkEffortAttribute.attrName", "1", delegator)) || !"0".equals(EntityUtilProperties.getPropertyValue("workeffort", "index.weight.WorkEffortAttribute.attrValue", "1", delegator))) {
List<GenericValue> workEffortAttributes = EntityQuery.use(delegator).from("WorkEffortAttribute").where("workEffortId", workEffortId).queryList();
for (GenericValue workEffortAttribute : workEffortAttributes) {
addWeightedKeywordSourceString(workEffortAttribute, "attrName", strings);
addWeightedKeywordSourceString(workEffortAttribute, "attrValue", strings);
}
}
String workEffortContentTypes = EntityUtilProperties.getPropertyValue("workeffort", "index.include.WorkEffortContentTypes", delegator);
for (String workEffortContentTypeId : workEffortContentTypes.split(",")) {
int weight = 1;
try {
weight = EntityUtilProperties.getPropertyAsInteger("workeffort", "index.weight.WorkEffortContent." + workEffortContentTypeId, 1).intValue();
} catch (Exception e) {
Debug.logWarning("Could not parse weight number: " + e.toString(), module);
}
List<GenericValue> workEffortContentAndInfos = EntityQuery.use(delegator).from("WorkEffortContentAndInfo").where("workEffortId", workEffortId, "workEffortContentTypeId", workEffortContentTypeId).queryList();
for (GenericValue workEffortContentAndInfo : workEffortContentAndInfos) {
addWeightedDataResourceString(workEffortContentAndInfo, weight, strings, delegator, workEffort);
List<GenericValue> alternateViews = workEffortContentAndInfo.getRelated("ContentAssocDataResourceViewTo", UtilMisc.toMap("caContentAssocTypeId", "ALTERNATE_LOCALE"), UtilMisc.toList("-caFromDate"), false);
alternateViews = EntityUtil.filterByDate(alternateViews, UtilDateTime.nowTimestamp(), "caFromDate", "caThruDate", true);
for (GenericValue thisView : alternateViews) {
addWeightedDataResourceString(thisView, weight, strings, delegator, workEffort);
}
}
}
for (String str : strings) {
// call process keywords method here
KeywordSearchUtil.processKeywordsForIndex(str, keywords, separators, stopWordBagAnd, stopWordBagOr, removeStems, stemSet);
}
List<GenericValue> toBeStored = new LinkedList<>();
for (Map.Entry<String, Long> entry : keywords.entrySet()) {
if (entry.getKey().length() < 60) {
// ignore very long strings, cannot be stored anyway
GenericValue workEffortKeyword = delegator.makeValue("WorkEffortKeyword", UtilMisc.toMap("workEffortId", workEffort.getString("workEffortId"), "keyword", entry.getKey(), "relevancyWeight", entry.getValue()));
toBeStored.add(workEffortKeyword);
}
}
if (toBeStored.size() > 0) {
if (Debug.verboseOn()) {
Debug.logVerbose("WorkEffortKeywordIndex indexKeywords Storing " + toBeStored.size() + " keywords for workEffortId " + workEffort.getString("workEffortId"), module);
}
delegator.storeAll(toBeStored);
}
}
use of org.apache.ofbiz.entity.Delegator in project ofbiz-framework by apache.
the class WorkEffortServices method getWorkEffortAssignedEventsForRoleOfAllParties.
public static Map<String, Object> getWorkEffortAssignedEventsForRoleOfAllParties(DispatchContext ctx, Map<String, ? extends Object> context) {
Delegator delegator = ctx.getDelegator();
String roleTypeId = (String) context.get("roleTypeId");
Locale locale = (Locale) context.get("locale");
List<GenericValue> validWorkEfforts = null;
try {
List<EntityExpr> conditionList = new LinkedList<>();
conditionList.add(EntityCondition.makeCondition("roleTypeId", EntityOperator.EQUALS, roleTypeId));
conditionList.add(EntityCondition.makeCondition("workEffortTypeId", EntityOperator.EQUALS, "EVENT"));
conditionList.add(EntityCondition.makeCondition("currentStatusId", EntityOperator.NOT_EQUAL, "CAL_DECLINED"));
conditionList.add(EntityCondition.makeCondition("currentStatusId", EntityOperator.NOT_EQUAL, "CAL_DELEGATED"));
conditionList.add(EntityCondition.makeCondition("currentStatusId", EntityOperator.NOT_EQUAL, "CAL_COMPLETED"));
conditionList.add(EntityCondition.makeCondition("currentStatusId", EntityOperator.NOT_EQUAL, "CAL_CANCELLED"));
EntityConditionList<EntityExpr> ecl = EntityCondition.makeCondition(conditionList, EntityOperator.AND);
validWorkEfforts = EntityQuery.use(delegator).from("WorkEffortAndPartyAssign").where(ecl).orderBy("estimatedStartDate", "priority").filterByDate().queryList();
} catch (GenericEntityException e) {
Debug.logWarning(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "WorkEffortNotFound", UtilMisc.toMap("errorString", e.toString()), locale));
}
Map<String, Object> result = new HashMap<>();
if (validWorkEfforts == null) {
validWorkEfforts = new LinkedList<>();
}
result.put("events", validWorkEfforts);
return result;
}
use of org.apache.ofbiz.entity.Delegator in project ofbiz-framework by apache.
the class WorkEffortServices method getWorkEffortAssignedEventsForRole.
public static Map<String, Object> getWorkEffortAssignedEventsForRole(DispatchContext ctx, Map<String, ? extends Object> context) {
Delegator delegator = ctx.getDelegator();
GenericValue userLogin = (GenericValue) context.get("userLogin");
String roleTypeId = (String) context.get("roleTypeId");
Locale locale = (Locale) context.get("locale");
List<GenericValue> validWorkEfforts = null;
if (userLogin != null && userLogin.get("partyId") != null) {
try {
EntityConditionList<EntityExpr> ecl = EntityCondition.makeCondition(EntityOperator.AND, EntityCondition.makeCondition("partyId", EntityOperator.EQUALS, userLogin.get("partyId")), EntityCondition.makeCondition("roleTypeId", EntityOperator.EQUALS, roleTypeId), EntityCondition.makeCondition("workEffortTypeId", EntityOperator.EQUALS, "EVENT"), EntityCondition.makeCondition("currentStatusId", EntityOperator.NOT_EQUAL, "CAL_DECLINED"), EntityCondition.makeCondition("currentStatusId", EntityOperator.NOT_EQUAL, "CAL_DELEGATED"), EntityCondition.makeCondition("currentStatusId", EntityOperator.NOT_EQUAL, "CAL_COMPLETED"), EntityCondition.makeCondition("currentStatusId", EntityOperator.NOT_EQUAL, "CAL_CANCELLED"));
validWorkEfforts = EntityQuery.use(delegator).from("WorkEffortAndPartyAssign").where(ecl).orderBy("estimatedStartDate", "priority").filterByDate().queryList();
} catch (GenericEntityException e) {
Debug.logWarning(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "WorkEffortNotFound", UtilMisc.toMap("errorString", e.toString()), locale));
}
}
Map<String, Object> result = new HashMap<>();
if (validWorkEfforts == null) {
validWorkEfforts = new LinkedList<>();
}
result.put("events", validWorkEfforts);
return result;
}
use of org.apache.ofbiz.entity.Delegator in project ofbiz-framework by apache.
the class WorkEffortServices method processWorkEffortEventReminders.
/**
* Process work effort event reminders. This service is used by the job scheduler.
* @param ctx the dispatch context
* @param context the context
* @return returns the result of the service execution
*/
public static Map<String, Object> processWorkEffortEventReminders(DispatchContext ctx, Map<String, ? extends Object> context) {
Delegator delegator = ctx.getDelegator();
LocalDispatcher dispatcher = ctx.getDispatcher();
Locale localePar = (Locale) context.get("locale");
Timestamp now = new Timestamp(System.currentTimeMillis());
List<GenericValue> eventReminders = null;
try {
eventReminders = EntityQuery.use(delegator).from("WorkEffortEventReminder").where(EntityCondition.makeCondition(UtilMisc.<EntityCondition>toList(EntityCondition.makeCondition("reminderDateTime", EntityOperator.EQUALS, null), EntityCondition.makeCondition("reminderDateTime", EntityOperator.LESS_THAN_EQUAL_TO, now)), EntityOperator.OR)).queryList();
} catch (GenericEntityException e) {
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "WorkEffortEventRemindersRetrivingError", UtilMisc.toMap("errorString", e), localePar));
}
for (GenericValue reminder : eventReminders) {
if (UtilValidate.isEmpty(reminder.get("contactMechId"))) {
continue;
}
int repeatCount = reminder.get("repeatCount") == null ? 0 : reminder.getLong("repeatCount").intValue();
int currentCount = reminder.get("currentCount") == null ? 0 : reminder.getLong("currentCount").intValue();
GenericValue workEffort = null;
try {
workEffort = reminder.getRelatedOne("WorkEffort", false);
} catch (GenericEntityException e) {
Debug.logWarning("Error while getting work effort: " + e, module);
}
if (workEffort == null) {
try {
reminder.remove();
} catch (GenericEntityException e) {
Debug.logWarning("Error while removing work effort event reminder: " + e, module);
}
continue;
}
Locale locale = reminder.getString("localeId") == null ? Locale.getDefault() : new Locale(reminder.getString("localeId"));
TimeZone timeZone = reminder.getString("timeZoneId") == null ? TimeZone.getDefault() : TimeZone.getTimeZone(reminder.getString("timeZoneId"));
Map<String, Object> parameters = UtilMisc.toMap("locale", locale, "timeZone", timeZone, "workEffortId", reminder.get("workEffortId"));
Map<String, Object> processCtx = UtilMisc.toMap("reminder", reminder, "bodyParameters", parameters, "userLogin", context.get("userLogin"));
Calendar cal = UtilDateTime.toCalendar(now, timeZone, locale);
Timestamp reminderStamp = reminder.getTimestamp("reminderDateTime");
Date eventDateTime = workEffort.getTimestamp("estimatedStartDate");
String tempExprId = workEffort.getString("tempExprId");
if (UtilValidate.isNotEmpty(tempExprId)) {
TemporalExpression temporalExpression = null;
try {
temporalExpression = TemporalExpressionWorker.getTemporalExpression(delegator, tempExprId);
} catch (GenericEntityException e) {
Debug.logWarning("Error while getting temporal expression, id = " + tempExprId + ": " + e, module);
}
if (temporalExpression != null) {
eventDateTime = temporalExpression.first(cal).getTime();
Date reminderDateTime = null;
long reminderOffset = reminder.get("reminderOffset") == null ? 0 : reminder.getLong("reminderOffset").longValue();
if (reminderStamp == null) {
if (reminderOffset != 0) {
cal.setTime(eventDateTime);
TimeDuration duration = TimeDuration.fromLong(reminderOffset);
duration.addToCalendar(cal);
reminderDateTime = cal.getTime();
} else {
reminderDateTime = eventDateTime;
}
} else {
reminderDateTime = new Date(reminderStamp.getTime());
}
if (reminderDateTime.before(now) && reminderStamp != null) {
try {
parameters.put("eventDateTime", new Timestamp(eventDateTime.getTime()));
Map<String, Object> result = dispatcher.runSync("processWorkEffortEventReminder", processCtx);
if (ServiceUtil.isError(result)) {
return ServiceUtil.returnError(ServiceUtil.getErrorMessage(result));
}
if (repeatCount != 0 && currentCount + 1 >= repeatCount) {
reminder.remove();
} else {
cal.setTime(reminderDateTime);
Date newReminderDateTime = null;
if (reminderOffset != 0) {
TimeDuration duration = TimeDuration.fromLong(-reminderOffset);
duration.addToCalendar(cal);
cal.setTime(temporalExpression.next(cal).getTime());
duration = TimeDuration.fromLong(reminderOffset);
duration.addToCalendar(cal);
newReminderDateTime = cal.getTime();
} else {
newReminderDateTime = temporalExpression.next(cal).getTime();
}
reminder.set("currentCount", Long.valueOf(currentCount + 1));
reminder.set("reminderDateTime", new Timestamp(newReminderDateTime.getTime()));
reminder.store();
}
} catch (GenericEntityException e) {
Debug.logWarning("Error while processing temporal expression reminder, id = " + tempExprId + ": " + e, module);
} catch (GenericServiceException e) {
Debug.logError(e, module);
}
} else if (reminderStamp == null) {
try {
reminder.set("reminderDateTime", new Timestamp(reminderDateTime.getTime()));
reminder.store();
} catch (GenericEntityException e) {
Debug.logWarning("Error while processing temporal expression reminder, id = " + tempExprId + ": " + e, module);
}
}
}
continue;
}
if (reminderStamp != null) {
Date reminderDateTime = new Date(reminderStamp.getTime());
if (reminderDateTime.before(now)) {
try {
parameters.put("eventDateTime", eventDateTime);
Map<String, Object> result = dispatcher.runSync("processWorkEffortEventReminder", processCtx);
if (ServiceUtil.isError(result)) {
return ServiceUtil.returnError(ServiceUtil.getErrorMessage(result));
}
TimeDuration duration = TimeDuration.fromNumber(reminder.getLong("repeatInterval"));
if ((repeatCount != 0 && currentCount + 1 >= repeatCount) || duration.isZero()) {
reminder.remove();
} else {
cal.setTime(now);
duration.addToCalendar(cal);
reminderDateTime = cal.getTime();
reminder.set("currentCount", Long.valueOf(currentCount + 1));
reminder.set("reminderDateTime", new Timestamp(reminderDateTime.getTime()));
reminder.store();
}
} catch (GenericEntityException e) {
Debug.logWarning("Error while processing event reminder: " + e, module);
} catch (GenericServiceException e) {
Debug.logError(e, module);
}
}
}
}
return ServiceUtil.returnSuccess();
}
use of org.apache.ofbiz.entity.Delegator in project ofbiz-framework by apache.
the class WorkEffortServices method getWorkEffortAssignedActivitiesByGroup.
public static Map<String, Object> getWorkEffortAssignedActivitiesByGroup(DispatchContext ctx, Map<String, ? extends Object> context) {
Delegator delegator = ctx.getDelegator();
GenericValue userLogin = (GenericValue) context.get("userLogin");
Locale locale = (Locale) context.get("locale");
List<GenericValue> groupWorkEfforts = null;
if (userLogin != null && userLogin.get("partyId") != null) {
try {
List<EntityExpr> constraints = new LinkedList<>();
constraints.add(EntityCondition.makeCondition("partyId", EntityOperator.EQUALS, userLogin.get("partyId")));
constraints.add(EntityCondition.makeCondition("workEffortTypeId", EntityOperator.EQUALS, "ACTIVITY"));
constraints.add(EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "CAL_DECLINED"));
constraints.add(EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "CAL_DELEGATED"));
constraints.add(EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "CAL_COMPLETED"));
constraints.add(EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "CAL_CANCELLED"));
constraints.add(EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "PRTYASGN_UNASSIGNED"));
constraints.add(EntityCondition.makeCondition("currentStatusId", EntityOperator.NOT_EQUAL, "WF_COMPLETED"));
constraints.add(EntityCondition.makeCondition("currentStatusId", EntityOperator.NOT_EQUAL, "WF_TERMINATED"));
constraints.add(EntityCondition.makeCondition("currentStatusId", EntityOperator.NOT_EQUAL, "WF_ABORTED"));
groupWorkEfforts = EntityQuery.use(delegator).from("WorkEffortPartyAssignByGroup").where(constraints).orderBy("priority").filterByDate().queryList();
} catch (GenericEntityException e) {
Debug.logWarning(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "WorkEffortNotFound", UtilMisc.toMap("errorString", e.toString()), locale));
}
}
Map<String, Object> result = new HashMap<>();
if (groupWorkEfforts == null) {
groupWorkEfforts = new LinkedList<>();
}
result.put("groupActivities", groupWorkEfforts);
return result;
}
Aggregations