Search in sources :

Example 76 with Delegator

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);
    }
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) TreeMap(java.util.TreeMap) LinkedList(java.util.LinkedList) IOException(java.io.IOException) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) GeneralException(org.apache.ofbiz.base.util.GeneralException) Delegator(org.apache.ofbiz.entity.Delegator) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 77 with Delegator

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;
}
Also used : Locale(java.util.Locale) GenericValue(org.apache.ofbiz.entity.GenericValue) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList) Delegator(org.apache.ofbiz.entity.Delegator) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) EntityExpr(org.apache.ofbiz.entity.condition.EntityExpr)

Example 78 with Delegator

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;
}
Also used : Locale(java.util.Locale) GenericValue(org.apache.ofbiz.entity.GenericValue) Delegator(org.apache.ofbiz.entity.Delegator) HashMap(java.util.HashMap) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) EntityExpr(org.apache.ofbiz.entity.condition.EntityExpr)

Example 79 with Delegator

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();
}
Also used : Locale(java.util.Locale) GenericValue(org.apache.ofbiz.entity.GenericValue) LocalDispatcher(org.apache.ofbiz.service.LocalDispatcher) TemporalExpression(org.apache.ofbiz.service.calendar.TemporalExpression) EntityCondition(org.apache.ofbiz.entity.condition.EntityCondition) Calendar(com.ibm.icu.util.Calendar) Timestamp(java.sql.Timestamp) Date(java.util.Date) TimeZone(java.util.TimeZone) Delegator(org.apache.ofbiz.entity.Delegator) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) TimeDuration(org.apache.ofbiz.base.util.TimeDuration) GenericServiceException(org.apache.ofbiz.service.GenericServiceException)

Example 80 with Delegator

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;
}
Also used : Locale(java.util.Locale) GenericValue(org.apache.ofbiz.entity.GenericValue) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList) Delegator(org.apache.ofbiz.entity.Delegator) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) EntityExpr(org.apache.ofbiz.entity.condition.EntityExpr)

Aggregations

Delegator (org.apache.ofbiz.entity.Delegator)869 GenericValue (org.apache.ofbiz.entity.GenericValue)721 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)611 Locale (java.util.Locale)485 HashMap (java.util.HashMap)328 LocalDispatcher (org.apache.ofbiz.service.LocalDispatcher)324 GenericServiceException (org.apache.ofbiz.service.GenericServiceException)278 BigDecimal (java.math.BigDecimal)205 LinkedList (java.util.LinkedList)166 Timestamp (java.sql.Timestamp)163 GeneralException (org.apache.ofbiz.base.util.GeneralException)130 IOException (java.io.IOException)117 Map (java.util.Map)113 EntityCondition (org.apache.ofbiz.entity.condition.EntityCondition)61 Security (org.apache.ofbiz.security.Security)60 HttpSession (javax.servlet.http.HttpSession)59 Properties (java.util.Properties)37 UtilProperties (org.apache.ofbiz.base.util.UtilProperties)37 EntityUtilProperties (org.apache.ofbiz.entity.util.EntityUtilProperties)35 EntityListIterator (org.apache.ofbiz.entity.util.EntityListIterator)33