protected override ApplicationDetailResult GetApplicationDetail(ApplicationMetadata application, InMemoryUser user, DetailRequest request) { var baseDetail = base.GetApplicationDetail(application, user, request); var resultObject = baseDetail.ResultObject; resultObject.SetAttribute("minstartdate", DateUtil.BeginOfDay(DateTime.Now.AddBusinessDays(3))); resultObject.SetAttribute("explanation", Resolver.I18NValue("offering.explanation", Explanation)); return(baseDetail); }
public void DateSearchDtoGtTest() { var searchRequestDto = new PaginatedSearchRequestDto(100, PaginatedSearchRequestDto.DefaultPaginationOptions); searchRequestDto.SetFromSearchString(_schema, "reportdate".Split(','), ">2013-01-03"); Assert.IsTrue(SearchUtils.GetWhere(searchRequestDto, "SR").Equals("( SR.reportdate > :reportdate_begin )")); var parametersMap = SearchUtils.GetParameters(searchRequestDto); Assert.IsTrue(parametersMap.Count == 1); Assert.IsTrue(parametersMap["reportdate_begin"].Equals(DateUtil.BeginOfDay(DateTime.Parse("2013-01-04")))); }
public void DateSearchDtoGteTest() { var searchRequestDto = new PaginatedSearchRequestDto(100, PaginatedSearchRequestDto.DefaultPaginationOptions); searchRequestDto.SetFromSearchString(_schema, "ticketid,description,asset_.description,siteid,affectedperson,status,reportdate".Split(','), ">=2013-01-01"); Assert.IsTrue(SearchUtils.GetWhere(searchRequestDto, "SR").Equals("( SR.reportdate >= :reportdate_begin )")); var parametersMap = SearchUtils.GetParameters(searchRequestDto); Assert.IsTrue(parametersMap.Count == 1); Assert.IsTrue(parametersMap["reportdate_begin"].Equals(DateUtil.BeginOfDay(DateTime.Parse("2013-01-01")))); }
public void DateTimeSearchDtoNeqTest() { var searchRequestDto = new PaginatedSearchRequestDto(100, PaginatedSearchRequestDto.DefaultPaginationOptions); searchRequestDto.SetFromSearchString(_schema, "reportdate".Split(','), "!=2013-01-04"); var @where = SearchUtils.GetWhere(searchRequestDto, "SR"); Assert.AreEqual("( SR.reportdate NOT BETWEEN :reportdate_begin AND :reportdate_end OR SR.reportdate IS NULL )", @where); var parametersMap = SearchUtils.GetParameters(searchRequestDto); Assert.IsTrue(parametersMap.Count == 2); Assert.AreEqual(DateUtil.BeginOfDay(DateTime.Parse("2013-01-04")), parametersMap["reportdate_begin"]); Assert.AreEqual(DateUtil.EndOfDay(DateTime.Parse("2013-01-04")), parametersMap["reportdate_end"]); }
public override void ExecuteJob() { var lowerRowstamp = ConfigFacade.Lookup <long>(ConfigurationConstants.R0042Rowstamp); var now = DateTime.Now; now = new DateTime(now.Year, now.Month, 1); var lastMonth = DateUtil.BeginOfDay(now.AddMonths(-1)); var beginOfMonth = DateUtil.BeginOfDay(now); var compMetadata = MetadataProvider.Application("asset"); var schema = compMetadata.Schemas()[new ApplicationMetadataSchemaKey("R0042Export")]; var slicedMetadata = MetadataProvider.SlicedEntityMetadata(schema.GetSchemaKey(), "asset"); var dto = new PaginatedSearchRequestDto { PageSize = PageSize }; var needsMore = true; var initOfBatch = true; var i = 1; while (needsMore) { Log.InfoFormat("R0042: fetching first {0} items restricted to rowstamp {1}".Fmt(i * PageSize, lowerRowstamp)); var searchEntityResult = FetchMore(dto, lastMonth, slicedMetadata, lowerRowstamp, initOfBatch); IList <R0042AssetHistory> items = ConvertItems(searchEntityResult.ResultList, beginOfMonth); if (!items.Any()) { break; } DAO.BulkSave(items); var greatestRowstamp = items[items.Count - 1].Rowstamp; //there´s at least one extra item, but could be thousands needsMore = items.Count == PageSize; i++; if (greatestRowstamp.HasValue) { ConfigFacade.SetValue(ConfigurationConstants.R0042Rowstamp, greatestRowstamp); Log.InfoFormat("R0042: updating rowstamp to {0}".Fmt(greatestRowstamp.Value)); lowerRowstamp = greatestRowstamp.Value; } initOfBatch = false; } }
public void DateSearchDtoTest() { var searchRequestDto = new PaginatedSearchRequestDto(100, PaginatedSearchRequestDto.DefaultPaginationOptions); searchRequestDto.SetFromSearchString(_schema, "ticketid,description,asset_.description,siteid,affectedperson,status,reportdate".Split(','), "2013-01-01"); Assert.IsNotNull(searchRequestDto); Assert.IsTrue(searchRequestDto.SearchParams.Equals("reportdate")); Assert.IsTrue(searchRequestDto.SearchValues.Equals("2013-01-01")); String whereClause = SearchUtils.GetWhere(searchRequestDto, "SR"); Assert.IsTrue(whereClause.Equals("( SR.reportdate BETWEEN :reportdate_begin AND :reportdate_end )")); IDictionary <String, Object> parametersMap = SearchUtils.GetParameters(searchRequestDto); Assert.IsTrue(parametersMap.Count == 2); Assert.IsTrue(parametersMap["reportdate_begin"].Equals(DateUtil.BeginOfDay(DateTime.Parse("2013-01-01")))); Assert.IsTrue(parametersMap["reportdate_end"].Equals(DateUtil.EndOfDay(DateTime.Parse("2013-01-01")))); }
private void HandleApprovalLeadTime(string schemaId, IEnumerable <AttributeHolder> listResultResultObject) { var toBeCheckedApprovals = new Dictionary <string, List <AttributeHolder> >(); foreach (var listItem in listResultResultObject) { var risk = listItem.GetAttribute("risk"); var workDays = CalculateFromRisk(risk == null ? null : risk.ToString()); var targetDate = listItem.GetAttribute("schedstart") as DateTime?; if (targetDate.HasValue) { DateTime approvalDate = targetDate.Value.SubtractBusinessDays(workDays); listItem.SetAttribute("#targetapprovaldate", approvalDate); if (DateUtil.BeginOfDay(approvalDate.SubtractBusinessDays(2)) <= DateUtil.BeginOfDay(DateTime.Now) && "AUTH".EqualsIc(listItem.GetAttribute("status").ToString())) { //from R0043 changes which are yet to be approved (hence AUTH) should be painted yellow if the approvaldate is within a 2 business days range from current date // since the query is expensive we´ll just do it for the items that have a chance to require it var workorderId = listItem.GetAttribute("workorderid").ToString(); if (!toBeCheckedApprovals.ContainsKey(workorderId)) { toBeCheckedApprovals.Add(workorderId, new List <AttributeHolder> { listItem }); } else { toBeCheckedApprovals[workorderId].Add(listItem); } } } } if (toBeCheckedApprovals.Any() && !"changeApprovalsDashboardList".Equals(schemaId)) { HandleGridPainting(toBeCheckedApprovals); } }
public IQuery BuildQuery(string queryst, ExpandoObject parameters, ISession session, bool native = false, PaginationData paginationData = null, string queryAlias = null) { LogQuery(queryst, queryAlias, parameters); if (paginationData != null && ApplicationConfiguration.IsDB2(ApplicationConfiguration.DBType.Maximo)) { //nhibernate pagination breaks in some scenarios, at least in DB2, keeping others intact for now queryst = NHibernatePaginationUtil.ApplyManualPaging(queryst, paginationData); } // LogPaginationQuery(queryst,queryAlias, parameters); var query = native ? session.CreateSQLQuery(queryst) : session.CreateQuery(queryst); query.SetTimeout(MetadataProvider.GlobalProperties.QueryTimeout()); if (!ApplicationConfiguration.IsDB2(ApplicationConfiguration.DBType.Maximo) && paginationData != null) { var pageSize = paginationData.PageSize; query.SetMaxResults(pageSize); query.SetFirstResult((paginationData.PageNumber - 1) * pageSize); } if (parameters == null) { return(query); } foreach (var parameter in parameters) { if (parameter.Value.GetType().IsGenericType&& parameter.Value is IEnumerable) { var list = new List <string>(); list.AddRange((IEnumerable <string>)parameter.Value); if (query.NamedParameters.Contains(parameter.Key)) { query.SetParameterList(parameter.Key, list); } } else { // TODO: This is wrong!!! The start and end date should be 2 diferent parameters. REFACTOR LATER!!! if (parameter.Key.IndexOf("___") == -1) { if (query.NamedParameters.Contains(parameter.Key)) { query.SetParameter(parameter.Key, parameter.Value); } } else { var startDateString = parameter.Value.ToString().Split(new[] { "___" }, StringSplitOptions.RemoveEmptyEntries)[0]; var startDate = DateUtil.Parse(startDateString); var inMemoryUser = SecurityFacade.CurrentUser(); if (startDate.HasValue) { startDate = startDate.Value.FromUserToRightKind(inMemoryUser); if (!startDateString.Contains(":")) { startDate = DateUtil.BeginOfDay(startDate.Value); } } var endDateString = parameter.Value.ToString().Split(new[] { "___" }, StringSplitOptions.RemoveEmptyEntries)[1]; var endDate = DateUtil.Parse(endDateString); if (endDate.HasValue) { endDate = endDate.Value.FromUserToRightKind(inMemoryUser); if (!endDateString.Contains(":")) { endDate = DateUtil.BeginOfDay(endDate.Value); } } query.SetParameter(parameter.Key + "_start", startDate); query.SetParameter(parameter.Key + "_end", endDate); } } } return(query); }
private static void HandleDateParameter(SearchParameter parameter, IDictionary <string, object> resultDictionary, KeyValuePair <string, SearchParameter> searchParameter, DateTime dt) { if (parameter.IsEqualOrNotEqual()) { if (!parameter.HasHour) { //this shall create a between interval resultDictionary.Add(searchParameter.Key + DateSearchParamBegin, DateUtil.BeginOfDay(dt)); resultDictionary.Add(searchParameter.Key + DateSearchParamEnd, DateUtil.EndOfDay(dt)); } else { //EQ 16:46 should become BETWEEN 16:46:00 and 16:46:59.999 resultDictionary.Add(searchParameter.Key + DateSearchParamBegin, dt); resultDictionary.Add(searchParameter.Key + DateSearchParamEnd, dt.AddSeconds(59).AddMilliseconds(999)); //resultDictionary.Add(searchParameter.Key, dt); } } else if (parameter.IsGtOrGte()) { if (!parameter.HasHour) { if (parameter.SearchOperator == SearchOperator.GT) { //if GT, then we need to exclude the current day from the search dt = dt.AddDays(1); } resultDictionary.Add(searchParameter.Key + DateSearchParamBegin, DateUtil.BeginOfDay(dt)); } else { if (parameter.SearchOperator == SearchOperator.GT) { //if GT let's add one minute since screen doesn't show seconds --> so GT > 16:36 becomes actually GT > 16:36:59.999 dt = dt.AddSeconds(59).AddMilliseconds(999); } //if GTE: GTE>= 16:36 keep it as it is resultDictionary.Add(searchParameter.Key + DateSearchParamBegin, dt.FromUserToMaximo(SecurityFacade.CurrentUser())); } } else if (parameter.IsLtOrLte()) { if (!parameter.HasHour) { if (parameter.SearchOperator == SearchOperator.LT) { //if GT, then we need to exclude the current day from the search, making the beggining of yesterday instead dt = dt.AddDays(-1); } resultDictionary.Add(searchParameter.Key + DateSearchParamEnd, DateUtil.EndOfDay(dt)); } else { dt = dt.AddSeconds(59).AddMilliseconds(999); if (parameter.SearchOperator == SearchOperator.LT) { //if LT let's subtract one minute since screen doesn't show seconds --> LT < 16:36 becomes LT <16:35.59.999 dt = dt.AddMinutes(-1); } resultDictionary.Add(searchParameter.Key + DateSearchParamEnd, dt.FromUserToMaximo(SecurityFacade.CurrentUser())); } } }