protected List<GenericValue> getAssignedRequsetType(GenericDelegator delegator, String partyId) throws GenericEntityException { List<GenericValue> assignedRequestType = null; try { assignedRequestType = delegator.findByAnd("PartyRequestView", UtilMisc.toMap("asignedPartyId", partyId)); } catch (GenericEntityException e) { // TODO Auto-generated catch block e.printStackTrace(); } return assignedRequestType; }
protected Process(EntityPersistentMgr mgr, Delegator delegator, String processId) throws PersistenceException { super(mgr, delegator); if (this.delegator != null) { try { this.process = delegator.findByPrimaryKey( org.ofbiz.shark.SharkConstants.WfProcess, UtilMisc.toMap(org.ofbiz.shark.SharkConstants.processId, processId)); } catch (GenericEntityException e) { Debug.logError("Invalid delegator object passed", module); e.printStackTrace(); throw new PersistenceException(e); } } else { Debug.logError("Invalid delegator object passed", module); } }
public Object resolve(String operandName, GenericDelegator delegator) { Debug.logInfo("Method resolve " + operandName, module); Object obj = null; // First try it in the Map (RuleContext) Debug.logInfo( "Method resolve::Not found in the RuleContext Map. Trying to evaluate against Employee.", module); EntityCondition entityCondition = EntityCondition.makeCondition(UtilMisc.toMap("description", operandName)); Set<String> fieldsToSelect = new HashSet<String>(); fieldsToSelect.add("className"); String className = null; try { List<GenericValue> genericValues = delegator.findList("PayrollEmplAttr", entityCondition, fieldsToSelect, null, null, false); if (genericValues.size() == 1) { className = genericValues.get(0).getString("className"); } } catch (GenericEntityException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } Debug.logInfo( "Method resolve::Delegating to class " + className + " for evaluating " + operandName, module); Class klass = null; try { klass = Class.forName(className, true, Thread.currentThread().getContextClassLoader()); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } java.lang.reflect.Method m = null; try { m = klass.getMethod("execute", new Class[0]); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { obj = m.invoke(new Object[0]); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } Debug.logInfo("Method resolve: Operand " + operandName + " evaluated to value " + obj, module); Object ret = newField(obj.toString()); return ret; }
public static String timeSheetChecker(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); Delegator delegator = (Delegator) session.getAttribute("delegator"); GenericValue userLogin = (GenericValue) session.getAttribute("userLogin"); List<Map<String, Object>> noTimeEntryList = new LinkedList<Map<String, Object>>(); String partyId = userLogin.getString("partyId"); Timestamp now = UtilDateTime.nowTimestamp(); Timestamp weekStart = UtilDateTime.getWeekStart(now); if (UtilValidate.isEmpty(delegator)) { delegator = (Delegator) request.getAttribute("delegator"); } try { // should be scrum team or scrum master. EntityConditionList<EntityExpr> exprOrs = EntityCondition.makeCondition( UtilMisc.toList( EntityCondition.makeCondition("roleTypeId", EntityOperator.EQUALS, "SCRUM_TEAM"), EntityCondition.makeCondition( "roleTypeId", EntityOperator.EQUALS, "SCRUM_MASTER")), EntityOperator.OR); EntityConditionList<EntityCondition> exprAnds = EntityCondition.makeCondition( UtilMisc.toList( exprOrs, EntityCondition.makeCondition("partyId", EntityOperator.EQUALS, partyId)), EntityOperator.AND); List<GenericValue> partyRoleList = EntityQuery.use(delegator).from("PartyRole").where(exprAnds).queryList(); if (UtilValidate.isNotEmpty(partyRoleList)) { List<GenericValue> timesheetList = EntityQuery.use(delegator) .from("Timesheet") .where("partyId", partyId, "statusId", "TIMESHEET_IN_PROCESS") .cache(true) .queryList(); if (UtilValidate.isNotEmpty(timesheetList)) { for (GenericValue timesheetMap : timesheetList) { String timesheetId = timesheetMap.getString("timesheetId"); Timestamp timesheetDate = timesheetMap.getTimestamp("fromDate"); // check monday - friday for (int i = 0; i < 5; i++) { Timestamp realTimeDate = UtilDateTime.addDaysToTimestamp(timesheetDate, i); Timestamp nowStartDate = UtilDateTime.getDayStart(now); // compare week and compare date if ((timesheetDate.compareTo(weekStart) <= 0) && (realTimeDate.compareTo(nowStartDate) < 0)) { // check time entry List<GenericValue> timeEntryList = timesheetMap.getRelated( "TimeEntry", UtilMisc.toMap( "partyId", partyId, "timesheetId", timesheetId, "fromDate", realTimeDate), null, false); // check EmplLeave List<GenericValue> emplLeaveList = EntityQuery.use(delegator) .from("EmplLeave") .where("partyId", partyId, "fromDate", realTimeDate) .cache(true) .queryList(); if (UtilValidate.isEmpty(timeEntryList) && UtilValidate.isEmpty(emplLeaveList)) { Map<String, Object> noEntryMap = new HashMap<String, Object>(); noEntryMap.put("timesheetId", timesheetId); noTimeEntryList.add(noEntryMap); break; } } } } } } } catch (GenericEntityException EntEx) { EntEx.printStackTrace(); Debug.logError(EntEx.getMessage(), module); } if (UtilValidate.isNotEmpty(noTimeEntryList)) { StringBuilder warningDataBuffer = new StringBuilder(); int size = noTimeEntryList.size(); for (Map<String, Object> dataMap : noTimeEntryList) { if (--size == 0) { warningDataBuffer.append(dataMap.get("timesheetId")); } else { warningDataBuffer.append(dataMap.get("timesheetId")).append(", "); } warningDataBuffer.append(dataMap.get("timesheetId")); } String warningData = warningDataBuffer.toString(); Debug.logInfo("The following time sheet no time entry: [" + warningData + "]", module); request.setAttribute( "_ERROR_MESSAGE_", UtilProperties.getMessage( "scrumUiLabels", "ScrumTimesheetWarningMessage", UtilMisc.toMap("warningMessage", warningData), UtilHttp.getLocale(request))); } return "success"; }