private bool HandleCustomerApprovers(InMemoryUser user, AttributeHolder result, string approvalGroup, IEnumerable <Dictionary <string, object> > worklogs, IDictionary <string, object> approval, IEnumerable <Dictionary <string, object> > wostatus) { //https://controltechnologysolutions.atlassian.net/browse/HAP-976 //https://controltechnologysolutions.atlassian.net/browse/HAP-1113 --> changing the way it filters the status worklogs = FilterWorkLogsOlderThanLatestAuth(worklogs, wostatus); var wlEnumerable = worklogs as Dictionary <string, object>[] ?? worklogs.ToArray(); var apprDescription = c.GetWorkLogDescriptions(approvalGroup, true); var rejDescription = c.GetWorkLogDescriptions(approvalGroup, false); var apprWl = wlEnumerable.FirstOrDefault(w => apprDescription.EqualsIc(w["description"] as string) && c.WlApprLogType.EqualsIc(w["logtype"] as string) && w["recordkey"].Equals(result.GetAttribute("wonum")) ); var rejWl = wlEnumerable.FirstOrDefault(w => rejDescription.EqualsIc(w["description"] as string) && c.WlRejLogType.EqualsIc(w["logtype"] as string) && w["recordkey"].Equals(result.GetAttribute("wonum")) ); var anyrejWl = wlEnumerable.FirstOrDefault(w => (w["description"] != null && w["description"].ToString().StartsWith(c.RejectedWorklogDescription, StringComparison.CurrentCultureIgnoreCase)) && w["logtype"].ToString().Equals(c.WlRejLogType) && w["recordkey"].Equals(result.GetAttribute("wonum")) ); //approval["#shouldshowaction"] = LevelMatches(result, approval) && user.HasPersonGroup(approvalGroup); ; //removed due to thomas comments, on HAP-976 approval["#shouldshowaction"] = user.HasPersonGroup(approvalGroup); ; if (apprWl != null || rejWl != null) { Log.DebugFormat("Specific approval or rejected worklog found"); approval[c.ChangeByColumn] = apprWl != null ? apprWl[c.CreateByColumn] : rejWl[c.CreateByColumn]; approval[c.ChangeDateColumn] = apprWl != null ? apprWl[c.CreateDate] : rejWl[c.CreateDate]; approval[c.StatusColumn] = apprWl != null ? c.ApprovedStatus : c.RejectedStatus; approval["#shouldshowaction"] = false; } else if (anyrejWl != null) { Log.DebugFormat("At least one rejected worklog found scenario"); //if there´s a rejected worklog on the level, then all groups should be rejected, except the ones that might have approved it already... approval[c.StatusColumn] = c.RejectedStatus; //HAP-993 if any of the groups rejected it, we should no longer display the actions approval["#shouldshowaction"] = false; } Log.DebugFormat("customer approval handled " + string.Join(", ", approval.Select(m => m.Key + ":" + m.Value).ToArray())); //if this group has not yet been approved or rejectd, it will still require some action (maybe not by this user) return(!approval.ContainsKey(c.StatusColumn) || !approval[c.StatusColumn].EqualsAny(c.ApprovedStatus, c.RejectedStatus)); }
private static PersonGroup GeneratePersonGroup(AttributeHolder personGroup) { var description = (string)personGroup.GetAttribute("description"); var pg = new PersonGroup { Name = (string)personGroup.GetAttribute(PersonGroupColumn), Description = description, Rowstamp = (long)personGroup.GetAttribute("rowstamp") }; pg.SuperGroup = HlagLocationUtil.IsSuperGroup(pg); return(pg); }
private static void HandleClosedDate(AttributeHolder resultObject) { var status = resultObject.GetAttribute("status"); var statusDate = resultObject.GetAttribute("statusdate"); if ("CLOSED".Equals(status)) { resultObject.Attributes["#closeddate"] = statusDate; } else { resultObject.Attributes["#closeddate"] = ""; } }
private static PaginatedSearchRequestDto BuildSearchDTO(AssociationUpdateRequest request, ApplicationAssociationDefinition association, AttributeHolder cruddata) { var searchRequest = new PaginatedSearchRequestDto(100, PaginatedSearchRequestDto.DefaultPaginationOptions); if (request.SearchDTO == null) { request.SearchDTO = PaginatedSearchRequestDto.DefaultInstance(null); } searchRequest.PageNumber = request.SearchDTO.PageNumber; searchRequest.PageSize = request.SearchDTO.PageSize; //avoids pagination unless the association renderer defines so (lookup) searchRequest.ShouldPaginate = association.IsPaginated(); searchRequest.NeedsCountUpdate = association.IsPaginated(); var valueSearchString = request.ValueSearchString; if (association.IsLazyLoaded() && !request.HasClientSearch()) { if ((cruddata == null || cruddata.GetAttribute(association.Target) == null)) { //we should not update lazy dependant associations except in one case: //there´s a default value in place already for the dependent association // in that case, we would need to return a 1-value list to show on screen return(null); } //this will force that the search would be made only on that specific value //ex: autocomplete server, lookups that depend upon another association valueSearchString = cruddata.GetAttribute(association.Target) as string; } if (request.AssociationKey != null) { // If association has a schema key defined, the searchDTO will be filled on client, so just copy it from request searchRequest.SearchParams = request.SearchDTO.SearchParams; searchRequest.SearchValues = request.SearchDTO.SearchValues; } else { if (!String.IsNullOrWhiteSpace(valueSearchString)) { searchRequest.AppendSearchParam(association.EntityAssociation.PrimaryAttribute().To); searchRequest.AppendSearchValue("%" + valueSearchString + "%"); } if (!String.IsNullOrWhiteSpace(request.LabelSearchString)) { AppendSearchLabelString(request, association, searchRequest); } } return(searchRequest); }
/// <summary> /// This is needed to fill the locations of an asset on the screen as soon as its selected /// </summary> /// <param name="application"></param> /// <param name="request"></param> /// <param name="currentData"></param> /// <returns></returns> protected override IDictionary <string, BaseAssociationUpdateResult> DoUpdateAssociation(ApplicationMetadata application, AssociationUpdateRequest request, AttributeHolder currentData) { var defaultResult = base.DoUpdateAssociation(application, request, currentData); if (!"asset".Equals(request.TriggerFieldName)) { return(defaultResult); } var assetLocation = (string)currentData.GetAttribute("asset_.location"); var userId = (string)currentData.GetAttribute("asset_.aucisowner_.person_.personid"); if (userId != null && (application.Schema.SchemaId.StartsWith("install") || application.Schema.SchemaId.Equals("update"))) { var userIdRequest = new AssociationUpdateRequest { ValueSearchString = userId, AssociationFieldName = "person_" }; var userIdResult = base.DoUpdateAssociation(application, userIdRequest, currentData); defaultResult.Add("person_", userIdResult["person_"]); } string locationToUse; var suffix = "FromLocation"; var sections = application.Schema.GetDisplayable <ApplicationSection>(typeof(ApplicationSection)); if (sections.Any(s => s.Id == "specifylocationfrom")) { locationToUse = (string)currentData.GetAttribute("fromlocation"); } else if (sections.Any(s => s.Id == "specifylocationto")) { locationToUse = (string)currentData.GetAttribute("tolocation"); suffix = "ToLocation"; } else { //no need to perform an extra query here return(defaultResult); } var extraAssociationOptions = GetLocationOptionsFromAssetLocation(locationToUse, assetLocation, suffix); foreach (var lookupAssociationUpdateResult in extraAssociationOptions) { defaultResult.Add(lookupAssociationUpdateResult); } return(defaultResult); }
private static void FillCustomLocationDescriptionFields(AttributeHolder attributeHolder, string field, string filter) { try { DataSetUtil.FillBlank(attributeHolder, field); var location = attributeHolder.GetAttribute("location_.description"); if (DataSetUtil.IsValid(location, typeof(String))) { var l = location.ToString(); if (l.Contains(filter)) { var attributeAux = Regex.Split(l, filter); if (attributeAux.Count() > 1) { var attribute = Regex.Split(attributeAux[1], "/"); if (attribute.Count() > 1) { attributeHolder.Attributes[field] = attribute[0]; } } } } } catch { DataSetUtil.FillBlank(attributeHolder, field); } }
public static object CloneFromEntity(object target, AttributeHolder attributes) { PropertyDescriptorCollection targetProperties = TypeDescriptor.GetProperties(target); foreach (PropertyDescriptor prop in targetProperties) { var value = attributes.GetAttribute(prop.Name.ToLower()); if (value == null) { continue; } if (prop.PropertyType.IsPrimitive) { prop.SetValue(target, value); } else if (!prop.PropertyType.IsPrimitive) { object o = prop.GetValue(target); if (o == null) { object newInstance = ReflectionUtil.InstanceFromType(prop.PropertyType); prop.SetValue(target, newInstance); o = newInstance; } r.SetProperty(o, new { Value = value }); } } return(target); }
private string NewLocationDelegate(AttributeHolder holder, ApplicationFieldDefinition field, string originalData) { if (!field.Attribute.EqualsIc("#rI102newlocation")) { return(originalData); } var country = holder.GetAttribute("location_pluspservaddr_.country"); var loccode = holder.GetAttribute("hlagpluspcustomer"); var streetaddress = holder.GetAttribute("location_pluspservaddr_.streetaddress"); var floor = holder.GetAttribute("location_.floor") as string; var room = holder.GetAttribute("location_.room") as string; if (string.IsNullOrEmpty(floor) || string.IsNullOrEmpty(room)) { return(country + "/" + loccode + "/" + streetaddress); } return(country + "/" + loccode + "/" + streetaddress + "/" + floor + "/" + room); }
private string BuildComplexLabel(AttributeHolder attributeHolder, ApplicationAssociationDefinition association) { var fmt = new object[association.LabelFields.Count]; for (var i = 0; i < association.LabelFields.Count; i++) { fmt[i] = attributeHolder.GetAttribute(association.LabelFields[i], true); } return(String.Format(association.LabelPattern, fmt)); }
protected bool FullSatisfied(IDependableField dependableField, AttributeHolder originalEntity) { var dependantFields = dependableField.DependantFields; if (dependantFields.Count == 0) { return(true); } return(dependantFields.All(depField => originalEntity.GetAttribute(depField) != null)); }
public static string GetSearchValue(EntityAssociationAttribute lookupAttribute, AttributeHolder originalEntity) { if (lookupAttribute.From != null) { var attribute = originalEntity.GetAttribute(lookupAttribute.From); return(attribute == null ? null : attribute.ToString()); } return(lookupAttribute.Literal); }
public static void FillField(AttributeHolder attributeHolder, string field, string attribute) { try { FillBlank(attributeHolder, field); var value = attributeHolder.GetAttribute(attribute); if (IsValid(value, typeof(String))) { attributeHolder.Attributes[field] = value.ToString(); } } catch { FillBlank(attributeHolder, field); } }
//TODO: add locale,and format options public IDictionary <string, BaseAssociationUpdateResult> BuildAssociationOptions(AttributeHolder dataMap, ApplicationMetadata application, IAssociationPrefetcherRequest request) { var associationsToFetch = AssociationHelper.BuildAssociationsToPrefetch(request, application.Schema); if (associationsToFetch.IsNone) { return(new Dictionary <string, BaseAssociationUpdateResult>()); } IDictionary <string, BaseAssociationUpdateResult> associationOptionsDictionary = new ConcurrentDictionary <string, BaseAssociationUpdateResult>(); var before = LoggingUtil.StartMeasuring(Log, "starting association options fetching for application {0} schema {1}", application.Name, application.Schema.Name); var associations = application.Schema.Associations; var tasks = new List <Task>(); var ctx = ContextLookuper.LookupContext(); #region associations foreach (var applicationAssociation in associations) { if (!associationsToFetch.ShouldResolve(applicationAssociation.AssociationKey)) { Log.Debug("ignoring association fetching: {0}".Fmt(applicationAssociation.AssociationKey)); continue; } //only resolve the association options for non lazy associations or lazy loaded with value set. SearchRequestDto search; if (!applicationAssociation.IsLazyLoaded()) { search = new SearchRequestDto(); } else if (dataMap != null && dataMap.GetAttribute(applicationAssociation.Target) != null) { //if the field has a value, fetch only this single element, for showing eventual extra label fields... ==> lookup with a selected value search = new SearchRequestDto(); var toAttribute = applicationAssociation.EntityAssociation.PrimaryAttribute().To; var prefilledValue = dataMap.GetAttribute(applicationAssociation.Target).ToString(); search.AppendSearchEntry(toAttribute, prefilledValue); } else { //lazy association with no default value continue; } var association = applicationAssociation; tasks.Add(Task.Factory.NewThread(c => { //this will avoid that one thread impacts any other, for ex: changing metadataid of the query var perThreadContext = ctx.ShallowCopy(); Quartz.Util.LogicalThreadContext.SetData("context", perThreadContext); var associationOptions = _associationOptionResolver.ResolveOptions(application, dataMap, association, search); associationOptionsDictionary.Add(association.AssociationKey, new BaseAssociationUpdateResult(associationOptions)); }, ctx)); } #endregion #region optionfields foreach (var optionField in application.Schema.OptionFields) { if (!associationsToFetch.ShouldResolve(optionField.AssociationKey)) { Log.Debug("ignoring association fetching: {0}".Fmt(optionField.AssociationKey)); continue; } if (optionField.ProviderAttribute == null) { //if there´s no provider, there´s nothing to do --> static list continue; } var field = optionField; tasks.Add(Task.Factory.NewThread(c => { Quartz.Util.LogicalThreadContext.SetData("context", c); var associationOptions = _dynamicOptionFieldResolver.ResolveOptions(application, field, dataMap); if (associationOptionsDictionary.ContainsKey(field.AssociationKey)) { associationOptionsDictionary.Remove(field.AssociationKey); } associationOptionsDictionary.Add(field.AssociationKey, new BaseAssociationUpdateResult(associationOptions)); }, ctx)); } #endregion Task.WaitAll(tasks.ToArray()); if (Log.IsDebugEnabled) { var keys = String.Join(",", associationOptionsDictionary.Keys.Where(k => associationOptionsDictionary[k].AssociationData != null)); Log.Debug(LoggingUtil.BaseDurationMessageFormat(before, "Finished execution of options fetching. Resolved collections: {0}", keys)); } return(associationOptionsDictionary); }