Search in sources :

Example 1 with TraceLevel

use of org.apache.syncope.common.lib.types.TraceLevel in project syncope by apache.

the class ResourceITCase method history.

@Test
public void history() {
    List<ResourceHistoryConfTO> history = resourceHistoryService.list(RESOURCE_NAME_LDAP);
    assertNotNull(history);
    int pre = history.size();
    ResourceTO ldap = resourceService.read(RESOURCE_NAME_LDAP);
    TraceLevel originalTraceLevel = SerializationUtils.clone(ldap.getUpdateTraceLevel());
    assertEquals(TraceLevel.ALL, originalTraceLevel);
    ProvisionTO originalProvision = SerializationUtils.clone(ldap.getProvision(AnyTypeKind.USER.name()).get());
    assertEquals(ObjectClass.ACCOUNT_NAME, originalProvision.getObjectClass());
    boolean originalFlag = ldap.isRandomPwdIfNotProvided();
    assertTrue(originalFlag);
    ldap.setUpdateTraceLevel(TraceLevel.FAILURES);
    ldap.getProvision(AnyTypeKind.USER.name()).get().setObjectClass("ANOTHER");
    ldap.setRandomPwdIfNotProvided(false);
    resourceService.update(ldap);
    ldap = resourceService.read(RESOURCE_NAME_LDAP);
    assertNotEquals(originalTraceLevel, ldap.getUpdateTraceLevel());
    assertNotEquals(originalProvision.getObjectClass(), ldap.getProvision(AnyTypeKind.USER.name()).get().getObjectClass());
    assertNotEquals(originalFlag, ldap.isRandomPwdIfNotProvided());
    history = resourceHistoryService.list(RESOURCE_NAME_LDAP);
    assertEquals(pre + 1, history.size());
    resourceHistoryService.restore(history.get(0).getKey());
    ldap = resourceService.read(RESOURCE_NAME_LDAP);
    assertEquals(originalTraceLevel, ldap.getUpdateTraceLevel());
    assertEquals(originalProvision.getObjectClass(), ldap.getProvision(AnyTypeKind.USER.name()).get().getObjectClass());
    assertEquals(originalFlag, ldap.isRandomPwdIfNotProvided());
}
Also used : ResourceHistoryConfTO(org.apache.syncope.common.lib.to.ResourceHistoryConfTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) TraceLevel(org.apache.syncope.common.lib.types.TraceLevel) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) Test(org.junit.jupiter.api.Test)

Example 2 with TraceLevel

use of org.apache.syncope.common.lib.types.TraceLevel in project syncope by apache.

the class AbstractProvisioningJobDelegate method createReport.

/**
 * Create a textual report of the provisionig operation, based on the trace level.
 *
 * @param provResults Provisioning results
 * @param resource Provisioning resource
 * @param dryRun dry run?
 * @return report as string
 */
protected String createReport(final Collection<ProvisioningReport> provResults, final ExternalResource resource, final boolean dryRun) {
    TraceLevel traceLevel = resource.getProvisioningTraceLevel();
    if (traceLevel == TraceLevel.NONE) {
        return null;
    }
    StringBuilder report = new StringBuilder();
    if (dryRun) {
        report.append("==> Dry run only, no modifications were made <==\n\n");
    }
    if (interrupted) {
        report.append("==> Execution was interrupted <==\n\n");
    }
    List<ProvisioningReport> rSuccCreate = new ArrayList<>();
    List<ProvisioningReport> rFailCreate = new ArrayList<>();
    List<ProvisioningReport> rSuccUpdate = new ArrayList<>();
    List<ProvisioningReport> rFailUpdate = new ArrayList<>();
    List<ProvisioningReport> rSuccDelete = new ArrayList<>();
    List<ProvisioningReport> rFailDelete = new ArrayList<>();
    List<ProvisioningReport> rSuccNone = new ArrayList<>();
    List<ProvisioningReport> rIgnore = new ArrayList<>();
    List<ProvisioningReport> uSuccCreate = new ArrayList<>();
    List<ProvisioningReport> uFailCreate = new ArrayList<>();
    List<ProvisioningReport> uSuccUpdate = new ArrayList<>();
    List<ProvisioningReport> uFailUpdate = new ArrayList<>();
    List<ProvisioningReport> uSuccDelete = new ArrayList<>();
    List<ProvisioningReport> uFailDelete = new ArrayList<>();
    List<ProvisioningReport> uSuccNone = new ArrayList<>();
    List<ProvisioningReport> uIgnore = new ArrayList<>();
    List<ProvisioningReport> gSuccCreate = new ArrayList<>();
    List<ProvisioningReport> gFailCreate = new ArrayList<>();
    List<ProvisioningReport> gSuccUpdate = new ArrayList<>();
    List<ProvisioningReport> gFailUpdate = new ArrayList<>();
    List<ProvisioningReport> gSuccDelete = new ArrayList<>();
    List<ProvisioningReport> gFailDelete = new ArrayList<>();
    List<ProvisioningReport> gSuccNone = new ArrayList<>();
    List<ProvisioningReport> gIgnore = new ArrayList<>();
    List<ProvisioningReport> aSuccCreate = new ArrayList<>();
    List<ProvisioningReport> aFailCreate = new ArrayList<>();
    List<ProvisioningReport> aSuccUpdate = new ArrayList<>();
    List<ProvisioningReport> aFailUpdate = new ArrayList<>();
    List<ProvisioningReport> aSuccDelete = new ArrayList<>();
    List<ProvisioningReport> aFailDelete = new ArrayList<>();
    List<ProvisioningReport> aSuccNone = new ArrayList<>();
    List<ProvisioningReport> aIgnore = new ArrayList<>();
    for (ProvisioningReport provResult : provResults) {
        AnyType anyType = anyTypeDAO.find(provResult.getAnyType());
        switch(provResult.getStatus()) {
            case SUCCESS:
                switch(provResult.getOperation()) {
                    case CREATE:
                        if (anyType == null) {
                            rSuccCreate.add(provResult);
                        } else {
                            switch(anyType.getKind()) {
                                case USER:
                                    uSuccCreate.add(provResult);
                                    break;
                                case GROUP:
                                    gSuccCreate.add(provResult);
                                    break;
                                case ANY_OBJECT:
                                default:
                                    aSuccCreate.add(provResult);
                            }
                        }
                        break;
                    case UPDATE:
                        if (anyType == null) {
                            rSuccUpdate.add(provResult);
                        } else {
                            switch(anyType.getKind()) {
                                case USER:
                                    uSuccUpdate.add(provResult);
                                    break;
                                case GROUP:
                                    gSuccUpdate.add(provResult);
                                    break;
                                case ANY_OBJECT:
                                default:
                                    aSuccUpdate.add(provResult);
                            }
                        }
                        break;
                    case DELETE:
                        if (anyType == null) {
                            rSuccDelete.add(provResult);
                        } else {
                            switch(anyType.getKind()) {
                                case USER:
                                    uSuccDelete.add(provResult);
                                    break;
                                case GROUP:
                                    gSuccDelete.add(provResult);
                                    break;
                                case ANY_OBJECT:
                                default:
                                    aSuccDelete.add(provResult);
                            }
                        }
                        break;
                    case NONE:
                        if (anyType == null) {
                            rSuccNone.add(provResult);
                        } else {
                            switch(anyType.getKind()) {
                                case USER:
                                    uSuccNone.add(provResult);
                                    break;
                                case GROUP:
                                    gSuccNone.add(provResult);
                                    break;
                                case ANY_OBJECT:
                                default:
                                    aSuccNone.add(provResult);
                            }
                        }
                        break;
                    default:
                }
                break;
            case FAILURE:
                switch(provResult.getOperation()) {
                    case CREATE:
                        if (anyType == null) {
                            rFailCreate.add(provResult);
                        } else {
                            switch(anyType.getKind()) {
                                case USER:
                                    uFailCreate.add(provResult);
                                    break;
                                case GROUP:
                                    gFailCreate.add(provResult);
                                    break;
                                case ANY_OBJECT:
                                default:
                                    aFailCreate.add(provResult);
                            }
                        }
                        break;
                    case UPDATE:
                        if (anyType == null) {
                            rFailUpdate.add(provResult);
                        } else {
                            switch(anyType.getKind()) {
                                case USER:
                                    uFailUpdate.add(provResult);
                                    break;
                                case GROUP:
                                    gFailUpdate.add(provResult);
                                    break;
                                case ANY_OBJECT:
                                default:
                                    aFailUpdate.add(provResult);
                            }
                        }
                        break;
                    case DELETE:
                        if (anyType == null) {
                            rFailDelete.add(provResult);
                        } else {
                            switch(anyType.getKind()) {
                                case USER:
                                    uFailDelete.add(provResult);
                                    break;
                                case GROUP:
                                    gFailDelete.add(provResult);
                                    break;
                                case ANY_OBJECT:
                                default:
                                    aFailDelete.add(provResult);
                            }
                        }
                        break;
                    default:
                }
                break;
            case IGNORE:
                if (anyType == null) {
                    rIgnore.add(provResult);
                } else {
                    switch(anyType.getKind()) {
                        case USER:
                            uIgnore.add(provResult);
                            break;
                        case GROUP:
                            gIgnore.add(provResult);
                            break;
                        case ANY_OBJECT:
                        default:
                            aIgnore.add(provResult);
                    }
                }
                break;
            default:
        }
    }
    // Summary, also to be included for FAILURE and ALL, so create it anyway.
    boolean includeUser = resource.getProvision(anyTypeDAO.findUser()) != null;
    boolean includeGroup = resource.getProvision(anyTypeDAO.findGroup()) != null;
    boolean includeAnyObject = resource.getProvisions().stream().anyMatch(provision -> provision.getAnyType().getKind() == AnyTypeKind.ANY_OBJECT);
    boolean includeRealm = resource.getOrgUnit() != null;
    if (includeUser) {
        report.append("Users ").append("[created/failures]: ").append(uSuccCreate.size()).append('/').append(uFailCreate.size()).append(' ').append("[updated/failures]: ").append(uSuccUpdate.size()).append('/').append(uFailUpdate.size()).append(' ').append("[deleted/failures]: ").append(uSuccDelete.size()).append('/').append(uFailDelete.size()).append(' ').append("[no operation/ignored]: ").append(uSuccNone.size()).append('/').append(uIgnore.size()).append('\n');
    }
    if (includeGroup) {
        report.append("Groups ").append("[created/failures]: ").append(gSuccCreate.size()).append('/').append(gFailCreate.size()).append(' ').append("[updated/failures]: ").append(gSuccUpdate.size()).append('/').append(gFailUpdate.size()).append(' ').append("[deleted/failures]: ").append(gSuccDelete.size()).append('/').append(gFailDelete.size()).append(' ').append("[no operation/ignored]: ").append(gSuccNone.size()).append('/').append(gIgnore.size()).append('\n');
    }
    if (includeAnyObject) {
        report.append("Any objects ").append("[created/failures]: ").append(aSuccCreate.size()).append('/').append(aFailCreate.size()).append(' ').append("[updated/failures]: ").append(aSuccUpdate.size()).append('/').append(aFailUpdate.size()).append(' ').append("[deleted/failures]: ").append(aSuccDelete.size()).append('/').append(aFailDelete.size()).append(' ').append("[no operation/ignored]: ").append(aSuccNone.size()).append('/').append(aIgnore.size());
    }
    if (includeRealm) {
        report.append("Realms ").append("[created/failures]: ").append(rSuccCreate.size()).append('/').append(rFailCreate.size()).append(' ').append("[updated/failures]: ").append(rSuccUpdate.size()).append('/').append(rFailUpdate.size()).append(' ').append("[deleted/failures]: ").append(rSuccDelete.size()).append('/').append(rFailDelete.size()).append(' ').append("[no operation/ignored]: ").append(rSuccNone.size()).append('/').append(rIgnore.size());
    }
    // Failures
    if (traceLevel == TraceLevel.FAILURES || traceLevel == TraceLevel.ALL) {
        if (includeUser) {
            if (!uFailCreate.isEmpty()) {
                report.append("\n\nUsers failed to create: ");
                report.append(ProvisioningReport.generate(uFailCreate, traceLevel));
            }
            if (!uFailUpdate.isEmpty()) {
                report.append("\nUsers failed to update: ");
                report.append(ProvisioningReport.generate(uFailUpdate, traceLevel));
            }
            if (!uFailDelete.isEmpty()) {
                report.append("\nUsers failed to delete: ");
                report.append(ProvisioningReport.generate(uFailDelete, traceLevel));
            }
        }
        if (includeGroup) {
            if (!gFailCreate.isEmpty()) {
                report.append("\n\nGroups failed to create: ");
                report.append(ProvisioningReport.generate(gFailCreate, traceLevel));
            }
            if (!gFailUpdate.isEmpty()) {
                report.append("\nGroups failed to update: ");
                report.append(ProvisioningReport.generate(gFailUpdate, traceLevel));
            }
            if (!gFailDelete.isEmpty()) {
                report.append("\nGroups failed to delete: ");
                report.append(ProvisioningReport.generate(gFailDelete, traceLevel));
            }
        }
        if (includeAnyObject && !aFailCreate.isEmpty()) {
            report.append("\nAny objects failed to create: ");
            report.append(ProvisioningReport.generate(aFailCreate, traceLevel));
        }
        if (includeAnyObject && !aFailUpdate.isEmpty()) {
            report.append("\nAny objects failed to update: ");
            report.append(ProvisioningReport.generate(aFailUpdate, traceLevel));
        }
        if (includeAnyObject && !aFailDelete.isEmpty()) {
            report.append("\nAny objects failed to delete: ");
            report.append(ProvisioningReport.generate(aFailDelete, traceLevel));
        }
        if (includeRealm) {
            if (!rFailCreate.isEmpty()) {
                report.append("\nRealms failed to create: ");
                report.append(ProvisioningReport.generate(rFailCreate, traceLevel));
            }
            if (!rFailUpdate.isEmpty()) {
                report.append("\nRealms failed to update: ");
                report.append(ProvisioningReport.generate(rFailUpdate, traceLevel));
            }
            if (!rFailDelete.isEmpty()) {
                report.append("\nRealms failed to delete: ");
                report.append(ProvisioningReport.generate(rFailDelete, traceLevel));
            }
        }
    }
    // Succeeded, only if on 'ALL' level
    if (traceLevel == TraceLevel.ALL) {
        if (includeUser) {
            if (!uSuccCreate.isEmpty()) {
                report.append("\n\nUsers created:\n").append(ProvisioningReport.generate(uSuccCreate, traceLevel));
            }
            if (!uSuccUpdate.isEmpty()) {
                report.append("\nUsers updated:\n").append(ProvisioningReport.generate(uSuccUpdate, traceLevel));
            }
            if (!uSuccDelete.isEmpty()) {
                report.append("\nUsers deleted:\n").append(ProvisioningReport.generate(uSuccDelete, traceLevel));
            }
            if (!uSuccNone.isEmpty()) {
                report.append("\nUsers no operation:\n").append(ProvisioningReport.generate(uSuccNone, traceLevel));
            }
            if (!uIgnore.isEmpty()) {
                report.append("\nUsers ignored:\n").append(ProvisioningReport.generate(uIgnore, traceLevel));
            }
        }
        if (includeGroup) {
            if (!gSuccCreate.isEmpty()) {
                report.append("\n\nGroups created:\n").append(ProvisioningReport.generate(gSuccCreate, traceLevel));
            }
            if (!gSuccUpdate.isEmpty()) {
                report.append("\nGroups updated:\n").append(ProvisioningReport.generate(gSuccUpdate, traceLevel));
            }
            if (!gSuccDelete.isEmpty()) {
                report.append("\nGroups deleted:\n").append(ProvisioningReport.generate(gSuccDelete, traceLevel));
            }
            if (!gSuccNone.isEmpty()) {
                report.append("\nGroups no operation:\n").append(ProvisioningReport.generate(gSuccNone, traceLevel));
            }
            if (!gIgnore.isEmpty()) {
                report.append("\nGroups ignored:\n").append(ProvisioningReport.generate(gIgnore, traceLevel));
            }
        }
        if (includeAnyObject) {
            if (!aSuccCreate.isEmpty()) {
                report.append("\n\nAny objects created:\n").append(ProvisioningReport.generate(aSuccCreate, traceLevel));
            }
            if (!aSuccUpdate.isEmpty()) {
                report.append("\nAny objects updated:\n").append(ProvisioningReport.generate(aSuccUpdate, traceLevel));
            }
            if (!aSuccDelete.isEmpty()) {
                report.append("\nAny objects deleted:\n").append(ProvisioningReport.generate(aSuccDelete, traceLevel));
            }
            if (!aSuccNone.isEmpty()) {
                report.append("\nAny objects no operation:\n").append(ProvisioningReport.generate(aSuccNone, traceLevel));
            }
            if (!aIgnore.isEmpty()) {
                report.append("\nAny objects ignored:\n").append(ProvisioningReport.generate(aIgnore, traceLevel));
            }
        }
        if (includeRealm) {
            if (!rSuccCreate.isEmpty()) {
                report.append("\n\nRealms created:\n").append(ProvisioningReport.generate(rSuccCreate, traceLevel));
            }
            if (!rSuccUpdate.isEmpty()) {
                report.append("\nRealms updated:\n").append(ProvisioningReport.generate(rSuccUpdate, traceLevel));
            }
            if (!rSuccDelete.isEmpty()) {
                report.append("\nRealms deleted:\n").append(ProvisioningReport.generate(rSuccDelete, traceLevel));
            }
            if (!rSuccNone.isEmpty()) {
                report.append("\nRealms no operation:\n").append(ProvisioningReport.generate(rSuccNone, traceLevel));
            }
            if (!rIgnore.isEmpty()) {
                report.append("\nRealms ignored:\n").append(ProvisioningReport.generate(rIgnore, traceLevel));
            }
        }
    }
    return report.toString();
}
Also used : ArrayList(java.util.ArrayList) TraceLevel(org.apache.syncope.common.lib.types.TraceLevel) ProvisioningReport(org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType)

Aggregations

TraceLevel (org.apache.syncope.common.lib.types.TraceLevel)2 ArrayList (java.util.ArrayList)1 ProvisionTO (org.apache.syncope.common.lib.to.ProvisionTO)1 ResourceHistoryConfTO (org.apache.syncope.common.lib.to.ResourceHistoryConfTO)1 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)1 AnyType (org.apache.syncope.core.persistence.api.entity.AnyType)1 ProvisioningReport (org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport)1 Test (org.junit.jupiter.api.Test)1