use of org.apache.ofbiz.entity.GenericEntityException in project ofbiz-framework by apache.
the class ICalWorker method handlePropFindRequest.
public static void handlePropFindRequest(HttpServletRequest request, HttpServletResponse response, ServletContext context) throws IOException {
if (!isValidRequest(request, response)) {
return;
}
String workEffortId = (String) request.getAttribute("workEffortId");
Debug.logInfo("[handlePropFindRequest] workEffortId = " + workEffortId, module);
try {
Document requestDocument = WebDavUtil.getDocumentFromRequest(request);
if (Debug.verboseOn()) {
Debug.logVerbose("[handlePropFindRequest] PROPFIND body:\r\n" + UtilXml.writeXmlDocument(requestDocument), module);
}
PropFindHelper helper = new PropFindHelper(requestDocument);
if (!helper.isAllProp() && !helper.isPropName()) {
Document responseDocument = helper.getResponseDocument();
List<Element> supportedProps = new LinkedList<>();
List<Element> unSupportedProps = new LinkedList<>();
List<Element> propElements = helper.getFindPropsList(ResponseHelper.DAV_NAMESPACE_URI);
for (Element propElement : propElements) {
if ("getetag".equals(propElement.getNodeName())) {
Element etagElement = helper.createElementSetValue("D:getetag", String.valueOf(System.currentTimeMillis()));
supportedProps.add(etagElement);
continue;
}
if ("getlastmodified".equals(propElement.getNodeName())) {
Date lastModified = getLastModifiedDate(request);
Element lmElement = helper.createElementSetValue("D:getlastmodified", WebDavUtil.formatDate(WebDavUtil.getRFC1123DateFormat(), lastModified));
supportedProps.add(lmElement);
continue;
}
unSupportedProps.add(responseDocument.createElementNS(propElement.getNamespaceURI(), propElement.getTagName()));
}
Element responseElement = helper.createResponseElement();
responseElement.appendChild(helper.createHrefElement("/" + workEffortId + "/"));
if (supportedProps.size() > 0) {
Element propElement = helper.createPropElement(supportedProps);
responseElement.appendChild(helper.createPropStatElement(propElement, ResponseHelper.STATUS_200));
}
if (unSupportedProps.size() > 0) {
Element propElement = helper.createPropElement(unSupportedProps);
responseElement.appendChild(helper.createPropStatElement(propElement, ResponseHelper.STATUS_404));
}
Element rootElement = helper.createMultiStatusElement();
rootElement.appendChild(responseElement);
responseDocument.appendChild(rootElement);
if (Debug.verboseOn()) {
Debug.logVerbose("[handlePropFindRequest] PROPFIND response:\r\n" + UtilXml.writeXmlDocument(responseDocument), module);
}
ResponseHelper.prepareResponse(response, 207, "Multi-Status");
try (Writer writer = response.getWriter()) {
helper.writeResponse(response, writer);
}
return;
}
} catch (RuntimeException | GenericEntityException | SAXException | ParserConfigurationException e) {
Debug.logError(e, "PROPFIND error: ", module);
}
response.setStatus(HttpServletResponse.SC_OK);
response.flushBuffer();
}
use of org.apache.ofbiz.entity.GenericEntityException 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.GenericEntityException 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.GenericEntityException 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.GenericEntityException 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