Search in sources :

Example 1 with SchemaUpgradeWrapper

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

the class ServiceSchemaModifications method calculateSchemaChanges.

private boolean calculateSchemaChanges(Map<String, ServiceSchemaImpl> newSchemaMap, Map<String, ServiceSchemaImpl> existingSchemaMap) throws UpgradeException {
    schemaModifications = new HashSet<SchemaUpgradeWrapper>();
    for (Map.Entry<String, ServiceSchemaImpl> entry : newSchemaMap.entrySet()) {
        String schemaName = entry.getKey();
        ServiceSchemaImpl schema = entry.getValue();
        if (!existingSchemaMap.containsKey(schemaName)) {
            ServiceSchemaModificationWrapper newAttrs = new ServiceSchemaModificationWrapper(serviceName, schemaName, schema.getAttributeSchemas());
            //NB: only schema additions are currently supported.
            schemaModifications.add(new SchemaUpgradeWrapper(newAttrs));
        }
    }
    return !schemaModifications.isEmpty();
}
Also used : ServiceSchemaModificationWrapper(org.forgerock.openam.upgrade.ServiceSchemaModificationWrapper) SchemaUpgradeWrapper(org.forgerock.openam.upgrade.SchemaUpgradeWrapper) ServiceSchemaUpgradeWrapper(org.forgerock.openam.upgrade.ServiceSchemaUpgradeWrapper) SubSchemaUpgradeWrapper(org.forgerock.openam.upgrade.SubSchemaUpgradeWrapper) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with SchemaUpgradeWrapper

use of org.forgerock.openam.upgrade.SchemaUpgradeWrapper 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 3 with SchemaUpgradeWrapper

use of org.forgerock.openam.upgrade.SchemaUpgradeWrapper 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)3 Map (java.util.Map)3 SchemaUpgradeWrapper (org.forgerock.openam.upgrade.SchemaUpgradeWrapper)3 ServiceSchemaUpgradeWrapper (org.forgerock.openam.upgrade.ServiceSchemaUpgradeWrapper)3 SubSchemaUpgradeWrapper (org.forgerock.openam.upgrade.SubSchemaUpgradeWrapper)3 HashSet (java.util.HashSet)2 Set (java.util.Set)2 NewServiceWrapper (org.forgerock.openam.upgrade.NewServiceWrapper)2 ServiceSchemaModificationWrapper (org.forgerock.openam.upgrade.ServiceSchemaModificationWrapper)1