internal IResult Execute(DateTime timestamp, Employee employee, LotKey lotKey, LotQualityStatus status, bool forceResolveAllDefects = false)
        {
            var lot = _lotUnitOfWork.LotRepository.FindByKey(lotKey,
                                                             l => l.ChileLot,
                                                             l => l.Attributes.Select(a => a.AttributeName),
                                                             l => l.LotDefects.Select(d => d.Resolution));

            if (lot == null)
            {
                return(new InvalidResult(string.Format(UserMessages.LotNotFound, lotKey)));
            }

            var historyResult = new RecordLotHistoryCommand(_lotUnitOfWork).Execute(lot, timestamp);

            if (!historyResult.Success)
            {
                return(historyResult);
            }

            if (forceResolveAllDefects)
            {
                foreach (var defect in lot.LotDefects)
                {
                    if (defect.Resolution == null)
                    {
                        defect.Resolution = new LotDefectResolution
                        {
                            EmployeeId     = employee.EmployeeId,
                            TimeStamp      = timestamp,
                            ResolutionType = ResolutionTypeEnum.AcceptedByUser,
                            Description    = "Forced acceptance by user."
                        };
                    }
                }
            }

            if (lot.ChileLot != null)
            {
                var chileLot = _lotUnitOfWork.ChileLotRepository.FindByKey(lotKey, LotStatusHelper.ChileLotIncludePaths);
                if (chileLot == null)
                {
                    return(new InvalidResult(string.Format(UserMessages.ChileLotNotFound, lotKey)));
                }

                if (!LotStatusHelper.GetValidLotQualityStatuses(chileLot).Contains(status))
                {
                    return(new InvalidResult(string.Format(UserMessages.CannotSetLotStatus, lotKey, chileLot.Lot.QualityStatus, status)));
                }
            }

            lot.QualityStatus = status;
            lot.EmployeeId    = employee.EmployeeId;
            lot.TimeStamp     = timestamp;

            return(new SuccessResult());
        }
Esempio n. 2
0
 private static void CheckAndAddDefectString(ChileLot chileLot, DefectTypeEnum defectType, ref string defectString)
 {
     if (LotStatusHelper.LotHasUnresolvedDefects(chileLot.Lot, defectType))
     {
         if (string.IsNullOrWhiteSpace(defectString))
         {
             defectString += defectType.ToString();
         }
         else
         {
             defectString += ", " + defectType.ToString();
         }
     }
 }
Esempio n. 3
0
 public void Returns_false_if_ChileLot_is_missing_any_LotAttribute_for_a_ChileProductRange()
 {
     Assert.IsFalse(LotStatusHelper.ChileLotAllProductSpecsEntered(new ChileLot
     {
         Lot = new Lot
         {
             Attributes = BuildLotAttributes(StaticAttributeNames.Asta, StaticAttributeNames.Scoville)
         },
         ChileProduct = new ChileProduct
         {
             ProductAttributeRanges = BuildAttributeRanges(StaticAttributeNames.Asta, StaticAttributeNames.Scan, StaticAttributeNames.Scoville)
         }
     }));
 }
            private bool SetLotQualityStatus(LotStat?lotStat, Lot newLot, ref List <LotAttributeDefect> attributeDefects)
            {
                if (lotStat == LotStat.Rejected)
                {
                    newLot.QualityStatus = LotQualityStatus.Rejected;
                    return(true);
                }

                if (lotStat.IsCompleted())
                {
                    //todo: get employee from oldLot.TesterID
                    attributeDefects.Where(d => d.LotDefect.Resolution == null).ForEach(d => d.LotDefect.ResolveDefect(LotMother.DefaultEmployee));
                }

                if (lotStat.IsAcceptable())
                {
                    newLot.QualityStatus = LotQualityStatus.Released;
                    return(true);
                }

                var unresolvedContaminated = LotStatusHelper.LotHasUnresolvedDefects(newLot, DefectTypeEnum.BacterialContamination);

                if (lotStat == LotStat.Contaminated || unresolvedContaminated)
                {
                    newLot.QualityStatus = LotQualityStatus.Contaminated;
                    return(true);
                }

                var unresolvedActionable = LotStatusHelper.LotHasUnresolvedDefects(newLot, DefectTypeEnum.ActionableDefect);

                if (lotStat.IsRequiresAttention() || (newLot.ProductSpecComplete && lotStat == LotStat.InProcess) || unresolvedActionable)
                {
                    newLot.QualityStatus = LotQualityStatus.Pending;
                    return(true);
                }

                if (newLot.ProductSpecComplete)
                {
                    newLot.QualityStatus = LotQualityStatus.Released;
                    return(true);
                }

                if (lotStat == LotStat.InProcess || lotStat == null)
                {
                    newLot.QualityStatus = LotQualityStatus.Pending;
                    return(true);
                }

                return(false);
            }
Esempio n. 5
0
 public void Returns_true_if_ChileLot_contains_LotAttributes_for_all_ChileProductAttributeRanges()
 {
     Assert.IsTrue(LotStatusHelper.ChileLotAllProductSpecsEntered(new ChileLot
     {
         Lot = new Lot
         {
             Attributes = BuildLotAttributes(StaticAttributeNames.Asta, StaticAttributeNames.Scan, StaticAttributeNames.Scoville)
         },
         ChileProduct = new ChileProduct
         {
             ProductAttributeRanges = BuildAttributeRanges(StaticAttributeNames.Asta, StaticAttributeNames.Scan, StaticAttributeNames.Scoville)
         }
     }));
 }
Esempio n. 6
0
            public void Returns_true_if_Lot_contains_BacterialContamination_defects_without_resolutions()
            {
                //Arrange
                var lot = new Lot
                {
                    LotDefects = new[]
                    {
                        BuildLotDefect(DefectTypeEnum.BacterialContamination, false),
                        BuildLotDefect(DefectTypeEnum.BacterialContamination, true)
                    }
                };

                //Act-Assert
                Assert.IsTrue(LotStatusHelper.LotHasUnresolvedDefects(lot, DefectTypeEnum.BacterialContamination));
            }
        internal IResult Execute(ILotKey lotKey)
        {
            if (lotKey == null)
            {
                throw new ArgumentNullException("lotKey");
            }

            var chileLot = _lotUnitOfWork.ChileLotRepository.FindByKey(new LotKey(lotKey), LotStatusHelper.ChileLotIncludePaths);

            if (chileLot != null)
            {
                var attributeNames = _lotUnitOfWork.AttributeNameRepository.Filter(a => true, a => a.ValidTreatments).ToList();
                LotStatusHelper.UpdateChileLotStatus(chileLot, attributeNames);
            }

            return(new SuccessResult());
        }
            private bool SetLotStatuses(LotDTO oldLot, ChileLot newChileLot, IEnumerable <AttributeName> attributeNames, ref List <LotAttributeDefect> attributeDefects)
            {
                newChileLot.AllAttributesAreLoBac = LotStatusHelper.DetermineChileLotIsLoBac(newChileLot, attributeNames);
                newChileLot.Lot.ProductionStatus  = oldLot._BatchStatID < 3 ? LotProductionStatus.Batched : LotProductionStatus.Produced;
                LotMother.SetLotHoldStatus(oldLot.LotStat, newChileLot.Lot);
                newChileLot.Lot.ProductSpecComplete   = LotStatusHelper.ChileLotAllProductSpecsEntered(newChileLot);
                newChileLot.Lot.ProductSpecOutOfRange = LotStatusHelper.ChileLotAttributeOutOfRange(newChileLot);

                if (!SetLotQualityStatus(oldLot.LotStat, newChileLot.Lot, ref attributeDefects))
                {
                    LotMother.Log(new CallbackParameters(oldLot, CallbackReason.ChileLotStatusConflict)
                    {
                        ChileLot = newChileLot
                    });
                    return(false);
                }

                return(true);
            }
Esempio n. 9
0
            public void Returns_false_if_Lot_contains_no_BacterialContamination_defects_without_resolutions()
            {
                //Arrange
                var lotWithNoDefects = new Lot
                {
                    LotDefects = new LotDefect[0]
                };

                var lotWithResolvedDefect = new Lot
                {
                    LotDefects = new[]
                    {
                        BuildLotDefect(DefectTypeEnum.BacterialContamination, true)
                    }
                };

                //Act-Assert
                Assert.IsFalse(LotStatusHelper.LotHasUnresolvedDefects(lotWithNoDefects, DefectTypeEnum.BacterialContamination));
                Assert.IsFalse(LotStatusHelper.LotHasUnresolvedDefects(lotWithResolvedDefect, DefectTypeEnum.BacterialContamination));
            }
Esempio n. 10
0
        private IResult SetLotAttributes(LotData data, Employee employee, DateTime timestamp, List <AttributeName> attributeNames, Dictionary <AttributeNameKey, IAttributeValueParameters> attributes)
        {
            var historyResult = new RecordLotHistoryCommand(_lotUnitOfWork).Execute(data.Lot, timestamp);

            if (!historyResult.Success)
            {
                return(historyResult);
            }

            var setValuesResult = new SetLotAttributeValuesCommand(_lotUnitOfWork).Execute(new SetLotAttributesParameters
            {
                Employee  = employee,
                TimeStamp = timestamp,

                AttributeNames = attributeNames,
                Lot            = data.Lot,
                LotUnarchivedPickedInventoryItems = data.Picked,
                LotAttributeDefects = data.Lot.AttributeDefects.ToList(),
                NewAttributes       = attributes
            });

            if (!setValuesResult.Success)
            {
                return(setValuesResult);
            }

            if (data.Lot.ChileLot != null)
            {
                var updateStatusResult = LotStatusHelper.UpdateChileLotStatus(data.Lot.ChileLot, attributeNames);
                if (!updateStatusResult.Success)
                {
                    return(updateStatusResult);
                }
            }

            data.Lot.EmployeeId = employee.EmployeeId;
            data.Lot.TimeStamp  = timestamp;

            return(new SuccessResult());
        }
Esempio n. 11
0
        private static IEnumerable <IAttributeDefect> GetProductSpecDefects(IEnumerable <LotAttribute> lotAttributes, IEnumerable <IAttributeRange> productSpec, IEnumerable <IAttributeDefect> lotAttributeDefects)
        {
            var existingDefects = lotAttributeDefects == null ? new Dictionary <AttributeNameKey, List <IAttributeDefect> >() : lotAttributeDefects
                                  .Where(d => d.AttributeNameKey_ShortName != null)
                                  .GroupBy(d => d.ToAttributeNameKey())
                                  .ToDictionary(g => g.Key, g => g.ToList());

            var unresolvedAttributes = lotAttributes == null ? new Dictionary <string, double>() : lotAttributes.Where(a =>
            {
                List <IAttributeDefect> defects;
                return(!existingDefects.TryGetValue(a.ToAttributeNameKey(), out defects) || defects.Any(d => !d.HasResolution));
            })
                                       .ToDictionary(a => a.ToAttributeNameKey().KeyValue, a => a.AttributeValue);

            var specDefects = productSpec == null ? new Dictionary <AttributeNameKey, List <IAttributeDefect> >() :
                              LotStatusHelper.GetAttributeDefects(unresolvedAttributes, productSpec.ToDictionary(s => s.ToAttributeNameKey().KeyValue))
                              .GroupBy(d => d.ToAttributeNameKey())
                              .ToDictionary(g => g.Key, g => g.ToList());

            foreach (var unresolvedDefects in existingDefects
                     .ToDictionary(g => g.Key, g => g.Value.Where(d =>
                                                                  !d.HasResolution &&
                                                                  (d.DefectType == DefectTypeEnum.ProductSpec || d.DefectType == DefectTypeEnum.ActionableDefect))
                                   .ToList())
                     .Where(d => d.Value.Any()))
            {
                List <IAttributeDefect> defects;
                if (specDefects.TryGetValue(unresolvedDefects.Key, out defects))
                {
                    defects.AddRange(unresolvedDefects.Value);
                }
                else
                {
                    specDefects.Add(unresolvedDefects.Key, unresolvedDefects.Value);
                }
            }

            return(specDefects.SelectMany(d => d.Value));
        }
Esempio n. 12
0
 protected void AssertResult(LotQualityStatus expectedStatus, LotQualityStatus determinedStatus)
 {
     Assert.AreEqual(expectedStatus, LotStatusHelper.PreserveQualityStatus(CurrentStatus, determinedStatus));
 }