Ejemplo n.º 1
0
        public override bool Execute(CommandActivity commandActivity)
        {
            //Set template reference for FF
            const string fileCaseFfTypeReferenceId = "589AFF8A-7737-40DE-BBA4-8FA2A3178058";
            const string incomingTypeVeReferenceId = "ABC5B6D0-6764-4801-AC36-7B42B80F63D3";

            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
                //Null values handled via SpecialdataCalculatedProperty.ExpressionString
                var terminGs    = sourceFileCase.GetProperty("#LHIND_Mitbericht_TerminGs").ToString() ?? "";
                var datum       = sourceFileCase.GetProperty("#LHIND_Mitbericht_Datum").ToString() ?? "";
                var titelIdp    = sourceFileCase.GetProperty("#LHIND_Mitbericht_TitelIdp") ?? "";
                var bemerkungen = sourceFileCase.GetProperty("#LHIND_Mitbericht_Bemerkungen") ?? "";

                var ffAmt = (sourceFileCase.GetProperty("#LHIND_Mitbericht_FederführendesAmt") == null)
                    ? ""
                    : (sourceFileCase.GetProperty("#LHIND_Mitbericht_FederführendesAmt") as SpecialdataCatalogValue)
                            .DisplayName;

                var mbAemter = (sourceFileCase.GetProperty("#LHIND_Mitbericht_MitbeteiligtFdListe") == null) ? "" :
                               String.Join(", ",
                                           (sourceFileCase.GetProperty("#LHIND_Mitbericht_MitbeteiligtFdListe") as SpecialdataListPropertyValueCollection).ToList()
                                           .Select(m => m.WrappedValue.GetProperty("DisplayName"))
                                           .ToList()
                                           .ToArray());

                var rueckmeldung = (sourceFileCase.GetProperty("#LHIND_Mitbericht_Rückmeldung") == null) ? "" :
                                   String.Join(", ",
                                               (sourceFileCase.GetProperty("#LHIND_Mitbericht_Rückmeldung") as SpecialdataListPropertyValueCollection).ToList()
                                               .Select(m => m.WrappedValue.GetProperty("DisplayName"))
                                               .ToList()
                                               .ToArray());

                var auftragsart =
                    (sourceFileCase.GetProperty("#LHIND_Mitbericht_AuftragsartMitberichtsverfahren") == null)
                        ? ""
                        : (sourceFileCase.GetProperty("#LHIND_Mitbericht_AuftragsartMitberichtsverfahren") as
                           SpecialdataCatalogValue).DisplayName;

                var rueckfragenAn = (sourceFileCase.GetProperty("#LHIND_Mitbericht_RückfragenAn") == null)
                    ? ""
                    : (sourceFileCase.GetProperty("#LHIND_Mitbericht_RückfragenAn") as TenantUser).DisplayName;

                var istFederfuehrung = (sourceFileCase.Type.ToHasReferenceID().ReferenceID.ToUpper() ==
                                        fileCaseFfTypeReferenceId.ToUpper());

                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(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_Mitbericht_VE_TerminGs", terminGs);
                            incoming.SetProperty("#LHIND_Mitbericht_VE_TitelIdp", titelIdp);
                            incoming.SetProperty("#LHIND_Mitbericht_VE_FederführendesAmt", ffAmt);
                            incoming.SetProperty("#LHIND_Mitbericht_VE_MitbeteiligtFdListe", mbAemter);
                            incoming.SetProperty("#LHIND_Mitbericht_VE_Rückmeldung", rueckmeldung);
                            incoming.SetProperty("#LHIND_Mitbericht_VE_AuftragsartMitberichtsverfahren", auftragsart);
                            incoming.SetProperty("#LHIND_Mitbericht_VE_Bemerkungen", bemerkungen);
                            incoming.SetProperty("#LHIND_Mitbericht_VE_Datum", datum);
                            incoming.SetProperty("#LHIND_Mitbericht_VE_RückfragenAn", rueckfragenAn);
                            incoming.SetProperty("#LHIND_Mitbericht_SourceFileCaseUrl", sourceFileCaseUrl);
                            incoming.SetProperty("#LHIND_Mitbericht_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(Rubicon.Gever
                                                                                                          .Bund.EGovInterface.Domain.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, ex);
                throw;
            }
            finally
            {
                ApplicationContext.CurrentID = restoreCtxId;
            }

            return(true);
        }
Ejemplo n.º 2
0
        public override bool Execute(CommandActivity commandActivity)
        {
            const string incomingTypeVeReferenceId = "ABC5B6D0-6764-4801-AC36-7B42B80F63D3";
            const string incomingTypeGsReferenceId = "64E46ED4-14C2-4E3D-A5D0-F3E2E39C2E73";

            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));
                }

                //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_Mitbericht_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_Mitbericht_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(Rubicon.Gever
                                                                                                          .Bund.EGovInterface.Domain.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);
        }
Ejemplo n.º 3
0
        public override bool Execute(CommandActivity commandActivity)
        {
            const string targetIncomingTypeReferenceId = "7CFEE47F-72C7-4DDF-B2C1-71CA03E1A808";

            var restoreCtxId = ApplicationContext.CurrentID;

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

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

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

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

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

                hostObject.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      = hostObject.DisplayName + " - eCH-Dossier";
                        incoming.IncomingType =
                            new ReferenceHandle <IncomingTypeClassificationType>(targetIncomingTypeReferenceId).GetObject();
                        incoming.ExternalNumber = hostObject.FormattedNumber;
                        incoming.Remark         = hostObject.WorkInstruction;
                        using (new SpecialdataIgnoreReadOnlySection())
                            incoming.SetProperty("#LHIND_Antrag_sourceFileCaseUrl", sourceFileCaseUrl);

                        var targeteCHDocument = Document.NewObject(incoming);
                        ((IDocument)targeteCHDocument).Name = hostObject.GetMultilingualValue(fc => fc.Title) + " (" +
                                                              hostObject.FormattedNumber + ") - eCH Import";
                        targeteCHDocument.PhysicallyPresent = false;
                        targeteCHDocument.Type = (DocumentClassificationType)ClassificationType.GetObject(Rubicon.Gever
                                                                                                          .Bund.EGovInterface.Domain.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, ex);
                throw;
            }
            finally
            {
                ApplicationContext.CurrentID = restoreCtxId;
            }

            return(true);
        }