Exemple #1
0
        public override bool Execute(CommandActivity commandActivity)
        {
            var incomingTypeVeReferenceId = "3A655116-6B6E-4246-B2ED-7A213FD61493";
            var incomingTypeGsReferenceId = "2C22B34E-29D6-44AE-B681-854DE5236146";

            var restoreCtxId = ApplicationContext.CurrentID;

            try
            {
                var sourceFileCase = (FileCase)commandActivity.WorkItem;

                if (sourceFileCase == null)
                {
                    throw new ActivityCommandException("").WithUserMessage(LocalizedUserMessages.NoFile
                                                                           .ToLocalizedName()
                                                                           .FormatWith(commandActivity));
                }

                if (!sourceFileCase.CanEdit(true))
                {
                    throw new ActivityCommandException("").WithUserMessage(LocalizedUserMessages.NotEditable
                                                                           .ToLocalizedName()
                                                                           .FormatWith(sourceFileCase));
                }

                //Parse tenant information from incoming
                string targetTenantId = String.Empty;

                var sourceIncoming = sourceFileCase.BaseFile.BaseIncomings
                                     .Where(i => i.IncomingType.ToHasReferenceID().ReferenceID.ToUpper() ==
                                            incomingTypeVeReferenceId.ToUpper())
                                     .OrderByDescending(t => t.CreatedAt)
                                     .FirstOrDefault();
                if (sourceIncoming == null)
                {
                    throw new ActivityCommandException("").WithUserMessage(LocalizedUserMessages.IncomingNotFound
                                                                           .ToLocalizedName()
                                                                           .FormatWith(sourceFileCase.BaseFile));
                }

                var targetFileCaseUri = new Uri(sourceIncoming.GetProperty("#LHIND_MitberichtExtern_SourceFileCaseUrl") as string);

                targetTenantId = HttpUtility.ParseQueryString(targetFileCaseUri.Query).Get("TenantID");

                var sourceFileCaseUrl = UrlProvider.Current.GetOpenWorkListItemUrl(sourceFileCase);


                //Create eCH-0147 container
                var messageExport = Containers.Global.Resolve <IMessageExport>();
                var eChExport     = messageExport.Export(sourceFileCase);

                sourceFileCase.AddFileCaseContent(eChExport);

                //switch tenant
                using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope())
                    using (TenantSection.SwitchToTenant(Tenant.FindByUnqiueIdentifier(targetTenantId)))
                    {
                        //Create new incoming, set specialdata properties
                        var incoming = Incoming.NewObject();
                        ApplicationContext.CurrentID = incoming.ApplicationContextID;

                        incoming.Subject      = sourceFileCase.DisplayName + " - eCH Response";
                        incoming.IncomingType =
                            new ReferenceHandle <IncomingTypeClassificationType>(incomingTypeGsReferenceId)
                            .GetObject();
                        incoming.ExternalNumber = sourceFileCase.FormattedNumber;
                        incoming.Remark         = sourceFileCase.WorkInstruction;
                        using (new SpecialdataIgnoreReadOnlySection())
                        {
                            incoming.SetProperty("#LHIND_MitberichtExtern_SourceFileCaseUrl", sourceFileCaseUrl);
                        }

                        var targeteChDocument = Document.NewObject(incoming);
                        ((IDocument)targeteChDocument).Name = sourceFileCase.GetMultilingualValue(fc => fc.Title) + " (" +
                                                              sourceFileCase.FormattedNumber + ") - eCH Import";
                        targeteChDocument.PhysicallyPresent = false;
                        targeteChDocument.Type =
                            (DocumentClassificationType)ClassificationType.GetObject(WellKnownObjects
                                                                                     .DocumentClassification.EchImport.GetObjectID());

                        using (SecurityFreeSection.Activate())
                            using (TenantSection.DisableQueryRestrictions())
                                using (var handle = eChExport.ActiveContent.GetContent())
                                {
                                    targeteChDocument.ActiveContent.SetContent(handle, "zip", "application/zip");

                                    var targetFile = ImportHelper.TenantKnowsObject(targeteChDocument, true);
                                    if (targetFile != null)
                                    {
                                        incoming.LeadingGroup = targetFile.LeadingGroup;
                                        incoming.Insert(targetFile);
                                    }
                                    else
                                    {
                                        incoming.LeadingGroup = UserHelper.Current.GetActaNovaUserExtension().StandardGroup != null
                                ? UserHelper.Current.GetActaNovaUserExtension().StandardGroup.AsTenantGroup()
                                : UserHelper.Current.OwningGroup.AsTenantGroup();
                                    }
                                }

                        ClientTransaction.Current.Commit();
                    }
            }
            catch (Exception ex)
            {
                s_logger.Error(ex.Message, ex);
                throw;
            }
            finally
            {
                ApplicationContext.CurrentID = restoreCtxId;
            }

            return(true);
        }
Exemple #2
0
        public override bool Execute(CommandActivity commandActivity)
        {
            //Set template reference for FF
            var fileCaseFfTypeReferenceId = "A8DE3E44-A236-4CBA-91A0-AD16A2D734BA";
            var incomingTypeVeReferenceId = "3A655116-6B6E-4246-B2ED-7A213FD61493";

            var restoreCtxId = ApplicationContext.CurrentID;

            try
            {
                var sourceFileCase = (FileCase)commandActivity.WorkItem;

                if (sourceFileCase == null)
                {
                    throw new ActivityCommandException("").WithUserMessage(LocalizedUserMessages.NoFileCase
                                                                           .ToLocalizedName()
                                                                           .FormatWith(commandActivity));
                }

                if (!sourceFileCase.CanEdit(true))
                {
                    throw new ActivityCommandException("").WithUserMessage(LocalizedUserMessages.NotEditable
                                                                           .ToLocalizedName()
                                                                           .FormatWith(sourceFileCase));
                }

                //Read specialdata and document values
                var terminGsObject = sourceFileCase.GetProperty("#LHIND_MitberichtExtern_TerminGs").ToString();
                var terminGs       = "";
                if (terminGsObject != null)
                {
                    terminGs = terminGsObject;
                }

                var datumObject = sourceFileCase.GetProperty("#LHIND_MitberichtExtern_Datum").ToString();
                var datum       = "";
                if (datumObject != null)
                {
                    datum = datumObject;
                }

                var ffAmtObject =
                    sourceFileCase.GetProperty("#LHIND_MitberichtExtern_FederfuhrendesAmt") as SpecialdataCatalogValue;
                var ffAmt = "";
                if (ffAmtObject != null)
                {
                    ffAmt = ffAmtObject.DisplayName;
                }

                var rueckfragenAnObject =
                    sourceFileCase.GetProperty("#LHIND_MitberichtExtern_RückfragenAn") as TenantUser;
                var rueckfragenAn = "";
                if (rueckfragenAnObject != null)
                {
                    rueckfragenAn = rueckfragenAnObject.DisplayName;
                }

                var mbAemterCatalogValues =
                    sourceFileCase.GetProperty("#LHIND_MitberichtExtern_MitbeteiligtFdListe") as
                    SpecialdataListPropertyValueCollection;

                var mbAemter = string.Join(", ",
                                           mbAemterCatalogValues.ToList()
                                           .Select(m => m.WrappedValue.GetProperty("DisplayName"))
                                           .ToList()
                                           .ToArray());

                var title = sourceFileCase.GetProperty("#LHIND_MitberichtExtern_TitelIdp") as string;

                var auftragsartObject =
                    sourceFileCase.GetProperty("#LHIND_MitberichtExtern_AuftragsartMitberichtsverfahren") as
                    SpecialdataCatalogValue;
                var auftragsart = "";
                if (auftragsartObject != null)
                {
                    auftragsart = auftragsartObject.DisplayName;
                }

                var rueckmeldungCatalogValues =
                    sourceFileCase.GetProperty("#LHIND_MitberichtExtern_RückmeldungAn") as
                    SpecialdataListPropertyValueCollection;
                var rueckmeldung = string.Join(", ",
                                               rueckmeldungCatalogValues.ToList()
                                               .Select(m => m.WrappedValue.GetProperty("DisplayName"))
                                               .ToList()
                                               .ToArray());

                var bemerkungObject = sourceFileCase.GetProperty("#LHIND_MitberichtExtern_Bemerkungen") as string;
                var bemerkung       = "";
                if (bemerkungObject != null)
                {
                    bemerkung = bemerkungObject;
                }

                var  sourceFileCaseUrl = UrlProvider.Current.GetOpenWorkListItemUrl(sourceFileCase);
                bool istFederfuehrung  = sourceFileCase.Type.ToHasReferenceID().ReferenceID.ToUpper() == fileCaseFfTypeReferenceId.ToUpper();

                //Create eCH-0147 container
                var messageExport = Containers.Global.Resolve <IMessageExport>();
                var eChExport     = messageExport.Export(sourceFileCase);

                sourceFileCase.AddFileCaseContent(eChExport);

                //switch tenant
                using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope())
                    using (TenantSection.SwitchToTenant(UserHelper.Current.Tenant))
                    {
                        //Create new incoming, set specialdata properties
                        var incoming = Incoming.NewObject();
                        ApplicationContext.CurrentID = incoming.ApplicationContextID;

                        incoming.Subject      = sourceFileCase.DisplayName + " - eCH-Dossier";
                        incoming.IncomingType =
                            new ReferenceHandle <IncomingTypeClassificationType>(incomingTypeVeReferenceId).GetObject();
                        incoming.ExternalNumber = sourceFileCase.FormattedNumber;
                        incoming.Remark         = sourceFileCase.WorkInstruction;

                        using (new SpecialdataIgnoreReadOnlySection())
                        {
                            incoming.SetProperty("#LHIND_MitberichtExtern_VE_TerminGs", terminGs);
                            incoming.SetProperty("#LHIND_MitberichtExtern_VE_Titel", title);
                            incoming.SetProperty("#LHIND_MitberichtExtern_VE_FfAmt", ffAmt);
                            incoming.SetProperty("#LHIND_MitberichtExtern_VE_Mitbeteiligt", mbAemter);
                            incoming.SetProperty("#LHIND_MitberichtExtern_VE_Rückmeldung", rueckmeldung);
                            incoming.SetProperty("#LHIND_MitberichtExtern_VE_AuftragsartMitbericht", auftragsart);
                            incoming.SetProperty("#LHIND_MitberichtExtern_VE_Bemerkungen", bemerkung);
                            incoming.SetProperty("#LHIND_MitberichtExtern_VE_Datum", datum);
                            incoming.SetProperty("#LHIND_MitberichtExtern_VE_RückfragenAn", rueckfragenAn);
                            incoming.SetProperty("#LHIND_MitberichtExtern_SourceFileCaseUrl", sourceFileCaseUrl);
                            incoming.SetProperty("#LHIND_MitberichtExtern_VE_IstFederfuehrung", istFederfuehrung);
                        }

                        var targeteChDocument = Document.NewObject(incoming);
                        ((IDocument)targeteChDocument).Name = sourceFileCase.GetMultilingualValue(fc => fc.Title) + " (" +
                                                              sourceFileCase.FormattedNumber + ") - eCH Import";
                        targeteChDocument.PhysicallyPresent = false;
                        targeteChDocument.Type =
                            (DocumentClassificationType)ClassificationType.GetObject(WellKnownObjects
                                                                                     .DocumentClassification.EchImport.GetObjectID());

                        using (TenantSection.DisableQueryRestrictions())
                            using (var handle = eChExport.ActiveContent.GetContent())
                            {
                                targeteChDocument.ActiveContent.SetContent(handle, "zip", "application/zip");
                            }

                        var targetFile = ImportHelper.TenantKnowsObject(targeteChDocument, true);
                        if (targetFile != null)
                        {
                            incoming.LeadingGroup = targetFile.LeadingGroup;
                            incoming.Insert(targetFile);
                        }
                        else
                        {
                            incoming.LeadingGroup = UserHelper.Current.GetActaNovaUserExtension().StandardGroup != null
                            ? UserHelper.Current.GetActaNovaUserExtension().StandardGroup.AsTenantGroup()
                            : UserHelper.Current.OwningGroup.AsTenantGroup();
                        }

                        ClientTransaction.Current.Commit();
                    }
            }
            catch (Exception ex)
            {
                s_logger.Error(ex.Message);
                throw;
            }
            finally
            {
                ApplicationContext.CurrentID = restoreCtxId;
            }

            return(true);
        }