Search in sources :

Example 1 with NewServiceWrapper

use of org.forgerock.openam.upgrade.NewServiceWrapper in project OpenAM by OpenRock.

the class UpgradeServiceSchemaStep method getDetailedReport.

@Override
public String getDetailedReport(String delimiter) {
    Map<String, String> tags = new HashMap<String, String>();
    tags.put(LF, delimiter);
    if (!modifiedSchemas.isEmpty()) {
        StringBuilder sBuf = new StringBuilder();
        for (Map.Entry<String, Set<SchemaUpgradeWrapper>> schemaMod : modifiedSchemas.entrySet()) {
            sBuf.append(BULLET).append(schemaMod.getKey()).append(delimiter);
            for (SchemaUpgradeWrapper schemaUpgradeWrapper : schemaMod.getValue()) {
                sBuf.append(INDENT).append(schemaUpgradeWrapper.getNewSchema().getSchemaName()).append(delimiter);
            }
            sBuf.append(delimiter);
        }
        tags.put(NEW_SCHEMAS, sBuf.toString());
    } else {
        tags.put(NEW_SCHEMAS, BUNDLE.getString("upgrade.none"));
    }
    if (addedServices != null && !addedServices.isEmpty()) {
        StringBuilder aBuf = new StringBuilder();
        for (NewServiceWrapper added : addedServices) {
            aBuf.append(BULLET).append(added.getServiceName()).append(delimiter);
        }
        tags.put(NEW_SERVICES, aBuf.toString());
    } else {
        tags.put(NEW_SERVICES, BUNDLE.getString("upgrade.none"));
    }
    if (!modifiedServices.isEmpty()) {
        StringBuilder mBuf = new StringBuilder();
        for (Map.Entry<String, Map<String, ServiceSchemaUpgradeWrapper>> mod : modifiedServices.entrySet()) {
            mBuf.append(BULLET).append(mod.getKey()).append(delimiter);
            for (Map.Entry<String, ServiceSchemaUpgradeWrapper> serviceType : mod.getValue().entrySet()) {
                ServiceSchemaUpgradeWrapper sUpdate = serviceType.getValue();
                if (sUpdate != null) {
                    if (sUpdate.getAttributesAdded() != null && sUpdate.getAttributesAdded().hasBeenModified()) {
                        mBuf.append(calculateAttrModifications(BUNDLE.getString("upgrade.addattr"), sUpdate.getAttributesAdded(), delimiter));
                    }
                    if (sUpdate.getAttributesModified() != null && sUpdate.getAttributesModified().hasBeenModified()) {
                        mBuf.append(calculateAttrModifications(BUNDLE.getString("upgrade.modattr"), sUpdate.getAttributesModified(), delimiter));
                    }
                    if (sUpdate.getAttributesDeleted() != null && sUpdate.getAttributesDeleted().hasBeenModified()) {
                        mBuf.append(calculateAttrModifications(BUNDLE.getString("upgrade.delattr"), sUpdate.getAttributesDeleted(), delimiter));
                    }
                }
            }
        }
        tags.put(MODIFIED_SERVICES, mBuf.toString());
    } else {
        tags.put(MODIFIED_SERVICES, BUNDLE.getString("upgrade.none"));
    }
    if (!modifiedSubSchemas.isEmpty()) {
        StringBuilder ssBuf = new StringBuilder();
        for (Map.Entry<String, Map<String, SubSchemaUpgradeWrapper>> ssMod : modifiedSubSchemas.entrySet()) {
            ssBuf.append(BULLET).append(ssMod.getKey()).append(delimiter);
            for (Map.Entry<String, SubSchemaUpgradeWrapper> serviceType : ssMod.getValue().entrySet()) {
                SubSchemaUpgradeWrapper ssUpdate = serviceType.getValue();
                if (ssUpdate != null) {
                    if (ssUpdate.getSubSchemasAdded() != null && ssUpdate.getSubSchemasAdded().subSchemaChanged()) {
                        ssBuf.append(INDENT).append(calculateSubSchemaAdditions(ssUpdate.getSubSchemasAdded(), delimiter));
                    }
                }
                ssBuf.append(delimiter);
            }
        }
        tags.put(NEW_SUB_SCHEMAS, ssBuf.toString());
    } else {
        tags.put(NEW_SUB_SCHEMAS, BUNDLE.getString("upgrade.none"));
    }
    if (!deletedServices.isEmpty()) {
        StringBuilder dBuf = new StringBuilder();
        for (String serviceName : deletedServices) {
            dBuf.append(BULLET).append(serviceName).append(delimiter);
        }
        tags.put(DELETED_SERVICES, dBuf.toString());
    } else {
        tags.put(DELETED_SERVICES, BUNDLE.getString("upgrade.none"));
    }
    return tagSwapReport(tags, "upgrade.servicereport");
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ServiceSchemaUpgradeWrapper(org.forgerock.openam.upgrade.ServiceSchemaUpgradeWrapper) NewServiceWrapper(org.forgerock.openam.upgrade.NewServiceWrapper) ServiceSchemaUpgradeWrapper(org.forgerock.openam.upgrade.ServiceSchemaUpgradeWrapper) SchemaUpgradeWrapper(org.forgerock.openam.upgrade.SchemaUpgradeWrapper) SubSchemaUpgradeWrapper(org.forgerock.openam.upgrade.SubSchemaUpgradeWrapper) SubSchemaUpgradeWrapper(org.forgerock.openam.upgrade.SubSchemaUpgradeWrapper) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with NewServiceWrapper

use of org.forgerock.openam.upgrade.NewServiceWrapper in project OpenAM by OpenRock.

the class UpgradeServiceSchemaStep method getShortReport.

@Override
public String getShortReport(String delimiter) {
    StringBuilder buffer = new StringBuilder();
    if (addedServices != null && !addedServices.isEmpty()) {
        for (NewServiceWrapper added : addedServices) {
            buffer.append(added.getServiceName()).append(" (").append(BUNDLE.getString("upgrade.new")).append(")");
            buffer.append(delimiter);
        }
    }
    Map<String, Set<ServiceModification>> updatedServices = new HashMap<String, Set<ServiceModification>>();
    if (!modifiedSchemas.isEmpty()) {
        for (Map.Entry<String, Set<SchemaUpgradeWrapper>> schemaMod : modifiedSchemas.entrySet()) {
            updatedServices.put(schemaMod.getKey(), asOrderedSet(ServiceModification.NEW_SCHEMA));
        }
    }
    if (!modifiedServices.isEmpty()) {
        for (Map.Entry<String, Map<String, ServiceSchemaUpgradeWrapper>> mod : modifiedServices.entrySet()) {
            if (updatedServices.keySet().contains(mod.getKey())) {
                updatedServices.get(mod.getKey()).add(ServiceModification.ATTR_MOD);
            } else {
                updatedServices.put(mod.getKey(), asOrderedSet(ServiceModification.ATTR_MOD));
            }
        }
    }
    if (!modifiedSubSchemas.isEmpty()) {
        for (Map.Entry<String, Map<String, SubSchemaUpgradeWrapper>> ssMod : modifiedSubSchemas.entrySet()) {
            if (updatedServices.keySet().contains(ssMod.getKey())) {
                updatedServices.get(ssMod.getKey()).add(ServiceModification.NEW_SUB_SCHEMA);
            } else {
                updatedServices.put(ssMod.getKey(), asOrderedSet(ServiceModification.NEW_SUB_SCHEMA));
            }
        }
    }
    for (Map.Entry<String, Set<ServiceModification>> modSvc : updatedServices.entrySet()) {
        buffer.append(modSvc.getKey()).append(" (").append(StringUtils.join(modSvc.getValue(), " & "));
        buffer.append(")").append(delimiter);
    }
    if (!deletedServices.isEmpty()) {
        for (String serviceName : deletedServices) {
            buffer.append(serviceName).append(" (").append(BUNDLE.getString("upgrade.deleted"));
            buffer.append(")").append(delimiter);
        }
    }
    return buffer.toString();
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) NewServiceWrapper(org.forgerock.openam.upgrade.NewServiceWrapper) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with NewServiceWrapper

use of org.forgerock.openam.upgrade.NewServiceWrapper in project OpenAM by OpenRock.

the class ServiceSchemaModifications method createServiceModifications.

/**
     * This will use the service schemas to find any upgrade handlers registered for the service and
     * populate the NewServiceWrapper's ServiceSchemaModificationWrappers.
     * @param newSchemaMap The service schemas representing the service.
     * @throws UpgradeException If an upgrade error occurs.
     */
private void createServiceModifications(Map<String, ServiceSchemaImpl> newSchemaMap) throws UpgradeException {
    try {
        final Map<String, ServiceSchemaModificationWrapper> serviceSchemaMap = new HashMap<String, ServiceSchemaModificationWrapper>();
        for (Map.Entry<String, ServiceSchemaImpl> newAttrSchemaEntry : newSchemaMap.entrySet()) {
            final ServiceSchemaModificationWrapper attributesAdded = getServiceModificationsRecursive(newAttrSchemaEntry.getKey(), newAttrSchemaEntry.getValue());
            if (attributesAdded.hasBeenModified()) {
                serviceSchemaMap.put(newAttrSchemaEntry.getKey(), attributesAdded);
            }
        }
        newServiceWrapper = new NewServiceWrapper(serviceName, serviceSchemaMap, serviceSchemaDoc);
    } catch (SMSException smse) {
        UpgradeUtils.debug.error("Error whilst determining schema changes for service: " + serviceName, smse);
        throw new UpgradeException(smse.getMessage(), smse);
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) ServiceSchemaModificationWrapper(org.forgerock.openam.upgrade.ServiceSchemaModificationWrapper) HashMap(java.util.HashMap) NewServiceWrapper(org.forgerock.openam.upgrade.NewServiceWrapper) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with NewServiceWrapper

use of org.forgerock.openam.upgrade.NewServiceWrapper in project OpenAM by OpenRock.

the class UpgradeServiceSchemaStep method perform.

@Override
public void perform() throws UpgradeException {
    UpgradeProgress.reportStart("upgrade.upgradeservices");
    UpgradeProgress.reportEnd("upgrade.blank");
    if (!addedServices.isEmpty()) {
        StringBuilder buffer = new StringBuilder();
        if (DEBUG.messageEnabled()) {
            buffer.append("services to add: ");
        }
        for (NewServiceWrapper serviceToAdd : addedServices) {
            final StringBuilder serviceDefinition = new StringBuilder(SERVICE_PROLOG);
            serviceDefinition.append(XMLUtils.print(serviceToAdd.getServiceDocument()));
            UpgradeProgress.reportStart("upgrade.addservice", serviceToAdd.getServiceName());
            UpgradeUtils.createService(serviceDefinition.toString(), serviceToAdd, getAdminToken());
            UpgradeProgress.reportEnd("upgrade.success");
            if (DEBUG.messageEnabled()) {
                buffer.append(serviceToAdd.getServiceName()).append(": ");
            }
        }
        if (DEBUG.messageEnabled()) {
            DEBUG.message("services to add: " + buffer.toString());
        }
    }
    if (!modifiedSchemas.isEmpty()) {
        for (Map.Entry<String, Set<SchemaUpgradeWrapper>> entry : modifiedSchemas.entrySet()) {
            String serviceName = entry.getKey();
            for (SchemaUpgradeWrapper schemaUpgradeWrapper : entry.getValue()) {
                UpgradeProgress.reportStart("upgrade.addschema", schemaUpgradeWrapper.getNewSchema().getSchemaName(), serviceName);
                UpgradeUtils.addNewSchema(serviceName, schemaUpgradeWrapper, getAdminToken());
                UpgradeProgress.reportEnd("upgrade.success");
            }
            if (DEBUG.messageEnabled()) {
                DEBUG.message("modified schema: " + serviceName);
            }
        }
    }
    if (!modifiedServices.isEmpty()) {
        for (Map.Entry<String, Map<String, ServiceSchemaUpgradeWrapper>> serviceToModify : modifiedServices.entrySet()) {
            UpgradeProgress.reportStart("upgrade.modservice", serviceToModify.getKey());
            UpgradeUtils.modifyService(serviceToModify.getKey(), serviceToModify.getValue(), getAdminToken());
            UpgradeProgress.reportEnd("upgrade.success");
            if (DEBUG.messageEnabled()) {
                DEBUG.message("modified service: " + serviceToModify.getKey());
            }
        }
    }
    if (!modifiedSubSchemas.isEmpty()) {
        for (Map.Entry<String, Map<String, SubSchemaUpgradeWrapper>> ssMod : modifiedSubSchemas.entrySet()) {
            UpgradeProgress.reportStart("upgrade.addsubschema", ssMod.getKey());
            UpgradeUtils.addNewSubSchemas(ssMod.getKey(), ssMod.getValue(), getAdminToken());
            UpgradeProgress.reportEnd("upgrade.success");
            if (DEBUG.messageEnabled()) {
                DEBUG.message("modified sub schema: " + ssMod.getKey());
            }
        }
    }
    if (!deletedServices.isEmpty()) {
        for (String serviceToDelete : deletedServices) {
            UpgradeProgress.reportStart("upgrade.delservice", serviceToDelete);
            UpgradeUtils.deleteService(serviceToDelete, getAdminToken());
            UpgradeProgress.reportEnd("upgrade.success");
            if (DEBUG.messageEnabled()) {
                DEBUG.message("deleted service: " + serviceToDelete);
            }
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) NewServiceWrapper(org.forgerock.openam.upgrade.NewServiceWrapper) ServiceSchemaUpgradeWrapper(org.forgerock.openam.upgrade.ServiceSchemaUpgradeWrapper) SchemaUpgradeWrapper(org.forgerock.openam.upgrade.SchemaUpgradeWrapper) SubSchemaUpgradeWrapper(org.forgerock.openam.upgrade.SubSchemaUpgradeWrapper) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

HashMap (java.util.HashMap)4 Map (java.util.Map)4 NewServiceWrapper (org.forgerock.openam.upgrade.NewServiceWrapper)4 HashSet (java.util.HashSet)3 Set (java.util.Set)3 SchemaUpgradeWrapper (org.forgerock.openam.upgrade.SchemaUpgradeWrapper)2 ServiceSchemaUpgradeWrapper (org.forgerock.openam.upgrade.ServiceSchemaUpgradeWrapper)2 SubSchemaUpgradeWrapper (org.forgerock.openam.upgrade.SubSchemaUpgradeWrapper)2 ServiceSchemaModificationWrapper (org.forgerock.openam.upgrade.ServiceSchemaModificationWrapper)1 UpgradeException (org.forgerock.openam.upgrade.UpgradeException)1