Search in sources :

Example 6 with ISMPServiceInformationManager

use of com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager in project phoss-smp by phax.

the class PageSecureEndpointList method showListOfExistingObjects.

@Override
protected void showListOfExistingObjects(@Nonnull final WebPageExecutionContext aWPEC) {
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
    final ICommonsList<ISMPServiceInformation> aAllServiceInfos = aServiceInfoMgr.getAllSMPServiceInformation();
    // Count unique service groups
    final ICommonsSet<String> aServiceGroupIDs = new CommonsHashSet<>();
    aAllServiceInfos.findAllMapped(ISMPServiceInformation::getServiceGroupID, aServiceGroupIDs::add);
    final boolean bHideDetails = aServiceGroupIDs.size() > 1000;
    final BootstrapButtonToolbar aToolbar = new BootstrapButtonToolbar(aWPEC);
    aToolbar.addButton("Create new Endpoint", createCreateURL(aWPEC), EDefaultIcon.NEW);
    aToolbar.addButton("Refresh", aWPEC.getSelfHref(), EDefaultIcon.REFRESH);
    if (!bHideDetails)
        aToolbar.addButton("Tree view", aWPEC.getLinkToMenuItem(CMenuSecure.MENU_ENDPOINT_TREE), EDefaultIcon.MAGNIFIER);
    aNodeList.addChild(aToolbar);
    final HCTable aTable = new HCTable(new DTCol("Service group").setInitialSorting(ESortOrder.ASCENDING).setDataSort(0, 1, 2, 3), new DTCol("Document type ID").setDataSort(1, 0, 2, 3), new DTCol("Process ID").setDataSort(2, 0, 1, 3), new DTCol("Transport profile").setDataSort(3, 0, 1, 2), new BootstrapDTColAction(aDisplayLocale)).setID(getID());
    for (final ISMPServiceInformation aServiceInfo : aAllServiceInfos) {
        final ISMPServiceGroup aServiceGroup = aServiceInfo.getServiceGroup();
        final IParticipantIdentifier aParticipantID = aServiceGroup.getParticipantIdentifier();
        final IDocumentTypeIdentifier aDocTypeID = aServiceInfo.getDocumentTypeIdentifier();
        for (final ISMPProcess aProcess : aServiceInfo.getAllProcesses()) {
            final IProcessIdentifier aProcessID = aProcess.getProcessIdentifier();
            for (final ISMPEndpoint aEndpoint : aProcess.getAllEndpoints()) {
                final StringMap aParams = createParamMap(aServiceInfo, aProcess, aEndpoint);
                final HCRow aRow = aTable.addBodyRow();
                final ISimpleURL aViewURL = createViewURL(aWPEC, aServiceInfo, aParams);
                aRow.addCell(new HCA(aViewURL).addChild(aServiceGroup.getID()));
                aRow.addCell(NiceNameUI.getDocumentTypeID(aDocTypeID, false));
                aRow.addCell(NiceNameUI.getProcessID(aDocTypeID, aProcessID, false));
                final String sTransportProfile = aEndpoint.getTransportProfile();
                aRow.addCell(new HCA(createViewURL(aWPEC, CMenuSecure.MENU_TRANSPORT_PROFILES, sTransportProfile)).addChild(NiceNameUI.getTransportProfile(sTransportProfile, false)));
                final ISimpleURL aEditURL = createEditURL(aWPEC, aServiceInfo).addAll(aParams);
                final ISimpleURL aCopyURL = createCopyURL(aWPEC, aServiceInfo).addAll(aParams);
                final ISimpleURL aDeleteURL = createDeleteURL(aWPEC, aServiceInfo).addAll(aParams);
                final ISimpleURL aPreviewURL = LinkHelper.getURLWithServerAndContext(aParticipantID.getURIPercentEncoded() + SMPRestFilter.PATH_SERVICES + aDocTypeID.getURIPercentEncoded());
                aRow.addCell(new HCA(aViewURL).setTitle("View endpoint").addChild(EDefaultIcon.MAGNIFIER.getAsNode()), new HCTextNode(" "), new HCA(aEditURL).setTitle("Edit endpoint").addChild(EDefaultIcon.EDIT.getAsNode()), new HCTextNode(" "), new HCA(aCopyURL).setTitle("Copy endpoint").addChild(EDefaultIcon.COPY.getAsNode()), new HCTextNode(" "), new HCA(aDeleteURL).setTitle("Delete endpoint").addChild(EDefaultIcon.DELETE.getAsNode()), new HCTextNode(" "), new HCA(aPreviewURL).setTitle("Perform SMP query on endpoint").setTargetBlank().addChild(EFamFamIcon.SCRIPT_GO.getAsNode()));
            }
        }
    }
    final DataTables aDataTables = BootstrapDataTables.createDefaultDataTables(aWPEC, aTable);
    aNodeList.addChild(aTable).addChild(aDataTables);
}
Also used : Locale(java.util.Locale) StringMap(com.helger.commons.collection.attr.StringMap) HCNodeList(com.helger.html.hc.impl.HCNodeList) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) HCRow(com.helger.html.hc.html.tabular.HCRow) IProcessIdentifier(com.helger.peppolid.IProcessIdentifier) ISimpleURL(com.helger.commons.url.ISimpleURL) BootstrapDTColAction(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDTColAction) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) CommonsHashSet(com.helger.commons.collection.impl.CommonsHashSet) ISMPProcess(com.helger.phoss.smp.domain.serviceinfo.ISMPProcess) DataTables(com.helger.photon.uictrls.datatables.DataTables) BootstrapDataTables(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDataTables) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) HCA(com.helger.html.hc.html.textlevel.HCA) ISMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) HCTable(com.helger.html.hc.html.tabular.HCTable) DTCol(com.helger.photon.uictrls.datatables.column.DTCol) HCTextNode(com.helger.html.hc.impl.HCTextNode) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 7 with ISMPServiceInformationManager

use of com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager in project phoss-smp by phax.

the class PageSecureEndpointTree method showListOfExistingObjects.

@Override
protected void showListOfExistingObjects(@Nonnull final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
    final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
    final BootstrapButtonToolbar aToolbar = new BootstrapButtonToolbar(aWPEC);
    aToolbar.addButton("Create new Endpoint", createCreateURL(aWPEC), EDefaultIcon.NEW);
    aToolbar.addButton("Refresh", aWPEC.getSelfHref(), EDefaultIcon.REFRESH);
    aToolbar.addButton("List view", aWPEC.getLinkToMenuItem(CMenuSecure.MENU_ENDPOINT_LIST), EDefaultIcon.MAGNIFIER);
    aNodeList.addChild(aToolbar);
    // Create list of service groups
    final ICommonsMap<ISMPServiceGroup, ICommonsList<ISMPServiceInformation>> aMap = new CommonsHashMap<>();
    aServiceInfoMgr.getAllSMPServiceInformation().forEach(x -> aMap.computeIfAbsent(x.getServiceGroup(), k -> new CommonsArrayList<>()).add(x));
    final HCUL aULSG = new HCUL();
    final ICommonsList<ISMPServiceGroup> aServiceGroups = aServiceGroupMgr.getAllSMPServiceGroups().getSortedInline(ISMPServiceGroup.comparator());
    for (final ISMPServiceGroup aServiceGroup : aServiceGroups) {
        // Print service group
        final IParticipantIdentifier aParticipantID = aServiceGroup.getParticipantIdentifier();
        final HCLI aLISG = aULSG.addAndReturnItem(new HCA(createViewURL(aWPEC, CMenuSecure.MENU_SERVICE_GROUPS, aServiceGroup)).addChild(aParticipantID.getURIEncoded()));
        final HCUL aULDT = new HCUL();
        final ICommonsList<ISMPServiceInformation> aServiceInfos = aMap.get(aServiceGroup);
        if (aServiceInfos != null) {
            for (final ISMPServiceInformation aServiceInfo : aServiceInfos.getSortedInline(ISMPServiceInformation.comparator())) {
                final HCUL aULP = new HCUL();
                final IDocumentTypeIdentifier aDocTypeID = aServiceInfo.getDocumentTypeIdentifier();
                final ICommonsList<ISMPProcess> aProcesses = aServiceInfo.getAllProcesses().getSortedInline(ISMPProcess.comparator());
                for (final ISMPProcess aProcess : aProcesses) {
                    final BootstrapTable aEPTable = new BootstrapTable(HCCol.perc(40), HCCol.perc(40), HCCol.perc(20)).setBordered(true);
                    final ICommonsList<ISMPEndpoint> aEndpoints = aProcess.getAllEndpoints().getSortedInline(ISMPEndpoint.comparator());
                    for (final ISMPEndpoint aEndpoint : aEndpoints) {
                        final StringMap aParams = createParamMap(aServiceInfo, aProcess, aEndpoint);
                        final HCRow aBodyRow = aEPTable.addBodyRow();
                        final String sTransportProfile = aEndpoint.getTransportProfile();
                        final ISimpleURL aViewURL = createViewURL(aWPEC, aServiceInfo, aParams);
                        aBodyRow.addCell(new HCA(aViewURL).addChild(NiceNameUI.getTransportProfile(sTransportProfile, false)));
                        aBodyRow.addCell(aEndpoint.getEndpointReference());
                        final ISimpleURL aEditURL = createEditURL(aWPEC, aServiceInfo).addAll(aParams);
                        final ISimpleURL aCopyURL = createCopyURL(aWPEC, aServiceInfo).addAll(aParams);
                        final ISimpleURL aDeleteURL = createDeleteURL(aWPEC, aServiceInfo).addAll(aParams);
                        final ISimpleURL aPreviewURL = LinkHelper.getURLWithServerAndContext(aParticipantID.getURIPercentEncoded() + SMPRestFilter.PATH_SERVICES + aDocTypeID.getURIPercentEncoded());
                        aBodyRow.addAndReturnCell(new HCA(aViewURL).setTitle("View endpoint").addChild(EDefaultIcon.MAGNIFIER.getAsNode()), new HCTextNode(" "), new HCA(aEditURL).setTitle("Edit endpoint").addChild(EDefaultIcon.EDIT.getAsNode()), new HCTextNode(" "), new HCA(aCopyURL).setTitle("Copy endpoint").addChild(EDefaultIcon.COPY.getAsNode()), new HCTextNode(" "), new HCA(aDeleteURL).setTitle("Delete endpoint").addChild(EDefaultIcon.DELETE.getAsNode()), new HCTextNode(" "), new HCA(aPreviewURL).setTitle("Perform SMP query on endpoint").setTargetBlank().addChild(EFamFamIcon.SCRIPT_GO.getAsNode())).addClass(CSS_CLASS_RIGHT);
                    }
                    // Show process + endpoints
                    final HCLI aLI = aULP.addItem();
                    final HCDiv aDiv = div(NiceNameUI.getProcessID(aDocTypeID, aProcess.getProcessIdentifier(), false));
                    aLI.addChild(aDiv);
                    if (aEndpoints.isEmpty()) {
                        aDiv.addChild(" ").addChild(new HCA(aWPEC.getSelfHref().addAll(createParamMap(aServiceInfo, aProcess, (ISMPEndpoint) null)).add(CPageParam.PARAM_ACTION, ACTION_DELETE_PROCESS)).setTitle("Delete process").addChild(EDefaultIcon.DELETE.getAsNode()));
                    } else
                        aLI.addChild(aEPTable);
                }
                // Show document types + children
                final HCLI aLI = aULDT.addItem();
                final HCDiv aDiv = div().addChild(NiceNameUI.getDocumentTypeID(aServiceInfo.getDocumentTypeIdentifier(), false)).addChild(" ").addChild(new HCA(LinkHelper.getURLWithServerAndContext(aParticipantID.getURIPercentEncoded() + SMPRestFilter.PATH_SERVICES + aDocTypeID.getURIPercentEncoded())).setTitle("Perform SMP query on document type ").setTargetBlank().addChild(EFamFamIcon.SCRIPT_GO.getAsNode()));
                aLI.addChild(aDiv);
                if (aProcesses.isEmpty()) {
                    aDiv.addChild(" ").addChild(new HCA(aWPEC.getSelfHref().addAll(createParamMap(aServiceInfo, (ISMPProcess) null, (ISMPEndpoint) null)).add(CPageParam.PARAM_ACTION, ACTION_DELETE_DOCUMENT_TYPE)).setTitle("Delete document type").addChild(EDefaultIcon.DELETE.getAsNode()));
                } else
                    aLI.addChild(aULP);
            }
        }
        if (aServiceInfos == null || aServiceInfos.isEmpty() || aULDT.hasNoChildren())
            aLISG.addChild(" ").addChild(badgeInfo("This service group has no assigned endpoints!"));
        else
            aLISG.addChild(aULDT);
    }
    aNodeList.addChild(aULSG);
}
Also used : HCDiv(com.helger.html.hc.html.grouping.HCDiv) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ICommonsList(com.helger.commons.collection.impl.ICommonsList) StringMap(com.helger.commons.collection.attr.StringMap) HCNodeList(com.helger.html.hc.impl.HCNodeList) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) HCRow(com.helger.html.hc.html.tabular.HCRow) CommonsHashMap(com.helger.commons.collection.impl.CommonsHashMap) ISimpleURL(com.helger.commons.url.ISimpleURL) HCLI(com.helger.html.hc.html.grouping.HCLI) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) ISMPProcess(com.helger.phoss.smp.domain.serviceinfo.ISMPProcess) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) HCA(com.helger.html.hc.html.textlevel.HCA) ISMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) HCUL(com.helger.html.hc.html.grouping.HCUL) BootstrapTable(com.helger.photon.bootstrap4.table.BootstrapTable) HCTextNode(com.helger.html.hc.impl.HCTextNode) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 8 with ISMPServiceInformationManager

use of com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager in project phoss-smp by phax.

the class PageSecureServiceGroup method showListOfExistingObjects.

@Override
protected void showListOfExistingObjects(@Nonnull final WebPageExecutionContext aWPEC) {
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
    final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
    final ISMPBusinessCardManager aBCMgr = SMPMetaManager.getBusinessCardMgr();
    final ISMPSettings aSettings = SMPMetaManager.getSettings();
    final ESMPRESTType eRESTType = SMPServerConfiguration.getRESTType();
    final boolean bShowExtensionDetails = SMPWebAppConfiguration.isServiceGroupsExtensionsShow();
    final boolean bShowBusinessCardName = CSMP.ENABLE_ISSUE_56 && aSettings.isDirectoryIntegrationEnabled();
    final ICommonsList<ISMPServiceGroup> aAllServiceGroups = aServiceGroupMgr.getAllSMPServiceGroups();
    final BootstrapButtonToolbar aToolbar = new BootstrapButtonToolbar(aWPEC);
    aToolbar.addButton("Create new Service group", createCreateURL(aWPEC), EDefaultIcon.NEW);
    aToolbar.addButton("Refresh", aWPEC.getSelfHref(), EDefaultIcon.REFRESH);
    if (aSettings.isSMLRequired() || aSettings.isSMLEnabled()) {
        // Disable button if no SML URL is configured
        // Disable button if no service group is present
        aToolbar.addAndReturnButton("Check DNS state", aWPEC.getSelfHref().add(CPageParam.PARAM_ACTION, ACTION_CHECK_DNS), EDefaultIcon.MAGNIFIER).setDisabled(aSettings.getSMLDNSZone() == null || aAllServiceGroups.isEmpty() || !aSettings.isSMLEnabled());
    }
    aNodeList.addChild(aToolbar);
    final boolean bShowDetails = aAllServiceGroups.size() <= 1000;
    final HCTable aTable = new HCTable(new DTCol("Participant ID").setInitialSorting(ESortOrder.ASCENDING), new DTCol("Owner"), bShowBusinessCardName ? new DTCol("Business Card Name") : null, new DTCol(span(bShowExtensionDetails ? "Ext" : "Ext?").setTitle("Is an Extension present?")), bShowDetails ? new DTCol(span("Docs").setTitle("Number of assigned document types")).setDisplayType(EDTColType.INT, aDisplayLocale) : null, bShowDetails ? new DTCol(span("Procs").setTitle("Number of assigned processes")).setDisplayType(EDTColType.INT, aDisplayLocale) : null, bShowDetails ? new DTCol(span("EPs").setTitle("Number of assigned endpoints")).setDisplayType(EDTColType.INT, aDisplayLocale) : null, new BootstrapDTColAction(aDisplayLocale)).setID(getID());
    for (final ISMPServiceGroup aCurObject : aAllServiceGroups) {
        final ISimpleURL aViewLink = createViewURL(aWPEC, aCurObject);
        final String sDisplayName = aCurObject.getParticipantIdentifier().getURIEncoded();
        final HCRow aRow = aTable.addBodyRow();
        aRow.addCell(new HCA(aViewLink).addChild(sDisplayName));
        aRow.addCell(SMPCommonUI.getOwnerName(aCurObject.getOwnerID()));
        if (bShowBusinessCardName) {
            IHCNode aName = null;
            final ISMPBusinessCard aBC = aBCMgr.getSMPBusinessCardOfServiceGroup(aCurObject);
            if (aBC != null) {
                final SMPBusinessCardEntity aEntity = aBC.getEntityAtIndex(0);
                if (aEntity != null && aEntity.names().isNotEmpty())
                    aName = HCTextNode.createOnDemand(aEntity.names().getFirst().getName());
            }
            aRow.addCell(aName);
        }
        if (bShowExtensionDetails) {
            if (aCurObject.extensions().isNotEmpty())
                aRow.addCell(new HCCode().addChildren(HCExtHelper.nl2divList(aCurObject.getFirstExtensionXML())));
            else
                aRow.addCell();
        } else {
            aRow.addCell(EPhotonCoreText.getYesOrNo(aCurObject.extensions().isNotEmpty(), aDisplayLocale));
        }
        if (bShowDetails) {
            int nProcesses = 0;
            int nEndpoints = 0;
            final ICommonsList<ISMPServiceInformation> aSIs = aServiceInfoMgr.getAllSMPServiceInformationOfServiceGroup(aCurObject);
            for (final ISMPServiceInformation aSI : aSIs) {
                nProcesses += aSI.getProcessCount();
                nEndpoints += aSI.getTotalEndpointCount();
            }
            aRow.addCell(Integer.toString(aSIs.size()));
            aRow.addCell(Integer.toString(nProcesses));
            aRow.addCell(Integer.toString(nEndpoints));
        }
        final HCNodeList aActions = new HCNodeList();
        aActions.addChildren(createEditLink(aWPEC, aCurObject, "Edit " + sDisplayName), new HCTextNode(" "), createCopyLink(aWPEC, aCurObject, "Copy " + sDisplayName), new HCTextNode(" "), createDeleteLink(aWPEC, aCurObject, "Delete " + sDisplayName), new HCTextNode(" "), new HCA(LinkHelper.getURLWithServerAndContext(aCurObject.getParticipantIdentifier().getURIPercentEncoded())).setTitle("Perform SMP query on " + sDisplayName).setTargetBlank().addChild(EFamFamIcon.SCRIPT_GO.getAsNode()));
        if (eRESTType.isCompleteServiceGroupSupported()) {
            aActions.addChildren(new HCTextNode(" "), new HCA(LinkHelper.getURLWithServerAndContext("complete/" + aCurObject.getParticipantIdentifier().getURIPercentEncoded())).setTitle("Perform complete SMP query on " + sDisplayName).setTargetBlank().addChild(EFamFamIcon.SCRIPT_LINK.getAsNode()));
        }
        aRow.addCell(aActions);
    }
    final DataTables aDataTables = BootstrapDataTables.createDefaultDataTables(aWPEC, aTable);
    aNodeList.addChild(aTable).addChild(aDataTables);
}
Also used : Locale(java.util.Locale) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) HCNodeList(com.helger.html.hc.impl.HCNodeList) HCRow(com.helger.html.hc.html.tabular.HCRow) ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) ISimpleURL(com.helger.commons.url.ISimpleURL) BootstrapDTColAction(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDTColAction) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) BootstrapDataTables(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDataTables) DataTables(com.helger.photon.uictrls.datatables.DataTables) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) HCCode(com.helger.html.hc.html.textlevel.HCCode) ESMPRESTType(com.helger.phoss.smp.ESMPRESTType) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) HCA(com.helger.html.hc.html.textlevel.HCA) SMPBusinessCardEntity(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardEntity) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) ISMPBusinessCardManager(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager) HCTable(com.helger.html.hc.html.tabular.HCTable) ISMPSettings(com.helger.phoss.smp.settings.ISMPSettings) DTCol(com.helger.photon.uictrls.datatables.column.DTCol) HCTextNode(com.helger.html.hc.impl.HCTextNode) IHCNode(com.helger.html.hc.IHCNode)

Example 9 with ISMPServiceInformationManager

use of com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager in project phoss-smp by phax.

the class PageSecureRedirect method validateAndSaveInputParameters.

@Override
protected void validateAndSaveInputParameters(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMPRedirect aSelectedObject, @Nonnull final FormErrorList aFormErrors, @Nonnull final EWebPageFormAction eFormAction) {
    final boolean bEdit = eFormAction.isEdit();
    final ISMPServiceGroupManager aServiceGroupManager = SMPMetaManager.getServiceGroupMgr();
    final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
    final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
    final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
    final String sServiceGroupID = bEdit ? aSelectedObject.getServiceGroupID() : aWPEC.params().getAsString(FIELD_SERVICE_GROUP_ID);
    ISMPServiceGroup aServiceGroup = null;
    final String sDocTypeID = bEdit ? aSelectedObject.getDocumentTypeIdentifier().getURIEncoded() : aWPEC.params().getAsString(FIELD_DOCTYPE_ID);
    IDocumentTypeIdentifier aDocTypeID = null;
    final String sRedirectTo = aWPEC.params().getAsString(FIELD_REDIRECT_TO);
    final String sSubjectUniqueIdentifier = aWPEC.params().getAsString(FIELD_SUBJECT_UNIQUE_IDENTIFIER);
    // TODO add certificate redirect support
    final X509Certificate aCertificate = null;
    final String sExtension = aWPEC.params().getAsString(FIELD_EXTENSION);
    // validations
    if (StringHelper.hasNoText(sServiceGroupID))
        aFormErrors.addFieldError(FIELD_SERVICE_GROUP_ID, "A Service Group must be selected!");
    else {
        aServiceGroup = aServiceGroupManager.getSMPServiceGroupOfID(aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID));
        if (aServiceGroup == null)
            aFormErrors.addFieldError(FIELD_SERVICE_GROUP_ID, "The provided Service Group does not exist!");
    }
    if (StringHelper.hasNoText(sDocTypeID))
        aFormErrors.addFieldError(FIELD_DOCTYPE_ID, "Document Type ID must not be empty!");
    else {
        aDocTypeID = aIdentifierFactory.parseDocumentTypeIdentifier(sDocTypeID);
        if (aDocTypeID == null)
            aFormErrors.addFieldError(FIELD_DOCTYPE_ID, "The provided Document Type ID has an invalid syntax!");
        else {
            if (aServiceGroup != null) {
                if (aServiceInfoMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aDocTypeID) != null)
                    aFormErrors.addFieldError(FIELD_DOCTYPE_ID, "At least one Endpoint is registered for this Document Type. Delete the Endpoint before you can create a Redirect.");
                else if (!bEdit && aRedirectMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDocTypeID) != null)
                    aFormErrors.addFieldError(FIELD_DOCTYPE_ID, "Another Redirect for the provided Service Group and Document Type is already present.");
            }
        }
    }
    if (StringHelper.hasNoText(sRedirectTo))
        aFormErrors.addFieldError(FIELD_REDIRECT_TO, "The Redirect URL must not be empty!");
    else if (URLHelper.getAsURL(sRedirectTo) == null)
        aFormErrors.addFieldError(FIELD_REDIRECT_TO, "The Redirect URL is not a valid URL!");
    if (StringHelper.hasNoText(sSubjectUniqueIdentifier))
        aFormErrors.addFieldError(FIELD_SUBJECT_UNIQUE_IDENTIFIER, "Subject Unique Identifier must not be empty!");
    if (StringHelper.hasText(sExtension)) {
        final IMicroDocument aDoc = MicroReader.readMicroXML(sExtension);
        if (aDoc == null)
            aFormErrors.addFieldError(FIELD_EXTENSION, "The Extension must be XML content.");
    }
    if (aFormErrors.isEmpty()) {
        if (aRedirectMgr.createOrUpdateSMPRedirect(aServiceGroup, aDocTypeID, sRedirectTo, sSubjectUniqueIdentifier, aCertificate, sExtension) == null)
            aWPEC.postRedirectGetInternal(error("Error creating the Redirect for Service Group '" + sServiceGroupID + "'."));
        else
            aWPEC.postRedirectGetInternal(success("The Redirect for Service Group '" + sServiceGroupID + "' was successfully saved."));
    }
}
Also used : ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ISMPRedirectManager(com.helger.phoss.smp.domain.redirect.ISMPRedirectManager) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) IMicroDocument(com.helger.xml.microdom.IMicroDocument) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) X509Certificate(java.security.cert.X509Certificate)

Example 10 with ISMPServiceInformationManager

use of com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager in project phoss-smp by phax.

the class ServiceGroupExport method createExportDataXMLVer10.

/**
 * Create XML export data for the provided service groups.
 *
 * @param aServiceGroups
 *        The service groups to export. May not be <code>null</code> but maybe
 *        empty.
 * @param bIncludeBusinessCards
 *        <code>true</code> to include Business Cards, <code>false</code> to
 *        skip them
 * @return The created XML document. Never <code>null</code>.
 */
@Nonnull
public static IMicroDocument createExportDataXMLVer10(@Nonnull final ICommonsList<ISMPServiceGroup> aServiceGroups, final boolean bIncludeBusinessCards) {
    ValueEnforcer.notNull(aServiceGroups, "ServiceGroups");
    if (LOGGER.isInfoEnabled())
        LOGGER.info("Start creating Service Group export data XML v1.0 for " + aServiceGroups.size() + " entries - " + (bIncludeBusinessCards ? "incl. Business Cards" : "excl. Business Cards"));
    final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
    final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
    final IMicroDocument aDoc = new MicroDocument();
    final IMicroElement eRoot = aDoc.appendElement(CSMPExchange.ELEMENT_SMP_DATA);
    eRoot.setAttribute(CSMPExchange.ATTR_VERSION, CSMPExchange.VERSION_10);
    final ICommonsList<ISMPServiceGroup> aSortedServiceGroups = aServiceGroups.getSorted(ISMPServiceGroup.comparator());
    // Add all service groups
    for (final ISMPServiceGroup aServiceGroup : aSortedServiceGroups) {
        final IMicroElement eServiceGroup = eRoot.appendChild(MicroTypeConverter.convertToMicroElement(aServiceGroup, CSMPExchange.ELEMENT_SERVICEGROUP));
        // Add all service information
        final ICommonsList<ISMPServiceInformation> aAllServiceInfos = aServiceInfoMgr.getAllSMPServiceInformationOfServiceGroup(aServiceGroup);
        for (final ISMPServiceInformation aServiceInfo : aAllServiceInfos.getSortedInline(ISMPServiceInformation.comparator())) {
            eServiceGroup.appendChild(MicroTypeConverter.convertToMicroElement(aServiceInfo, CSMPExchange.ELEMENT_SERVICEINFO));
        }
        // Add all redirects
        final ICommonsList<ISMPRedirect> aAllRedirects = aRedirectMgr.getAllSMPRedirectsOfServiceGroup(aServiceGroup);
        for (final ISMPRedirect aServiceInfo : aAllRedirects.getSortedInline(ISMPRedirect.comparator())) {
            eServiceGroup.appendChild(MicroTypeConverter.convertToMicroElement(aServiceInfo, CSMPExchange.ELEMENT_REDIRECT));
        }
    }
    // Add Business cards only if PD integration is enabled
    if (bIncludeBusinessCards) {
        // Add all business cards
        final ISMPBusinessCardManager aBusinessCardMgr = SMPMetaManager.getBusinessCardMgr();
        for (final ISMPServiceGroup aServiceGroup : aSortedServiceGroups) {
            final ISMPBusinessCard aBusinessCard = aBusinessCardMgr.getSMPBusinessCardOfID(aServiceGroup.getParticipantIdentifier());
            if (aBusinessCard != null) {
                eRoot.appendChild(SMPBusinessCardMicroTypeConverter.convertToMicroElement(aBusinessCard, null, CSMPExchange.ELEMENT_BUSINESSCARD, true));
            }
        }
    }
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Finished creating Service Group XML data");
    return aDoc;
}
Also used : ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) ISMPRedirectManager(com.helger.phoss.smp.domain.redirect.ISMPRedirectManager) IMicroDocument(com.helger.xml.microdom.IMicroDocument) MicroDocument(com.helger.xml.microdom.MicroDocument) ISMPBusinessCardManager(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager) IMicroElement(com.helger.xml.microdom.IMicroElement) ISMPRedirect(com.helger.phoss.smp.domain.redirect.ISMPRedirect) IMicroDocument(com.helger.xml.microdom.IMicroDocument) Nonnull(javax.annotation.Nonnull)

Aggregations

ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)28 ISMPServiceInformationManager (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager)28 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)21 ISMPServiceInformation (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation)21 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)20 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)17 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)16 ISMPRedirectManager (com.helger.phoss.smp.domain.redirect.ISMPRedirectManager)14 SMPNotFoundException (com.helger.phoss.smp.exception.SMPNotFoundException)14 SMPServerException (com.helger.phoss.smp.exception.SMPServerException)13 Nonnull (javax.annotation.Nonnull)12 ICommonsList (com.helger.commons.collection.impl.ICommonsList)7 ISMPRedirect (com.helger.phoss.smp.domain.redirect.ISMPRedirect)7 ISMPProcess (com.helger.phoss.smp.domain.serviceinfo.ISMPProcess)7 IUser (com.helger.photon.security.user.IUser)7 HCNodeList (com.helger.html.hc.impl.HCNodeList)6 ISMPEndpoint (com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint)6 SMPEndpoint (com.helger.phoss.smp.domain.serviceinfo.SMPEndpoint)6 Locale (java.util.Locale)6 EChange (com.helger.commons.state.EChange)4