GNDMS 0.6.0
RESTful verison of GNDMS
Public Types | Public Member Functions | Private Member Functions | Private Attributes

de.zib.gndms.logic.model.gorfx.ConfigTaskFlowTypeAction Class Reference

An Action to manage the configuration map of an TaskFlowType entity. More...

Inherits de::zib::gndms::logic::model::config::ConfigAction< String >.

List of all members.

Public Types

enum  OutFormat { PROPS, OPTS, NONE, PRINT_OK }
enum  UpdateMode { READ, UPDATE, OVERWRITE, DELKEYS }

Public Member Functions

void initialize ()
String execute (final @NotNull EntityManager em, final @NotNull PrintWriter writer)
 Retrieves the TaskFlowType entity with the primary key getTaskFlowType() and the entityclass TaskFlowType.class, which is managed by em.
String getTaskFlowType ()
void setTaskFlowType (final String taskFlowTypeParam)

Private Member Functions

boolean isValidConfigOptionName (final String name)
 Returns true if name does not start with 'cfg' and is not the String 'taskFlowType'.
String genOutput (final Map< String, String > configMapParam)
 Depending on the selected OutFormat, another message is returned.

Private Attributes

String taskFlowType
UpdateMode cfgUpdateMode
OutFormat cfgOutFormat

Detailed Description

An Action to manage the configuration map of an TaskFlowType entity.

Depending on the chosen UpdateMode, it will either delete, just update or completly overwrite all keys and their corresponding values of the entity's configuration map, being a valid config option (see isValidConfigOptionName(String)).

Before this action is started, the following parameters must be set in the configuration map: 'cfgOutFormat', 'cfgUpdateMode'. If not already denoted, 'offerType' must also be set in the map. Otherwise an IllegalStateException will be thrown.

See also:
de.zib.gndms.neomodel.gorfx.TaskFlowType
Author:
try ste fan pla nti kow zib
Version:
$Id$

User: stepn Date: 06.10.2008 Time: 11:50:03


Member Function Documentation

String de.zib.gndms.logic.model.gorfx.ConfigTaskFlowTypeAction.execute ( final @NotNull EntityManager  em,
final @NotNull PrintWriter  writer 
)

Retrieves the TaskFlowType entity with the primary key getTaskFlowType() and the entityclass TaskFlowType.class, which is managed by em.

Depending on the UpdateMode it will manipulate the entity's configuration map. If the mode is set to 'DELKEYS', all options from entity's configuration map are deleted, which have a valid config option name according to isValidConfigOpionName().

Otherwise it will put all available options (getAllOptionName()) and their chosen values to the configuration map, if they are valid according to isValidConfigOpionName().

Calls genOutput(java.util.Map), with the modified configuration map, returning a result string.

Parameters:
em
writer
Returns:
genOutput(java.util.Map)
                                                                                              {

        Session session = getDao().beginSession();

        try {
            final TaskFlowType taskFlowType = session.findTaskFlowType(  getTaskFlowType() );

            if ( taskFlowType == null )
                throw new IllegalStateException( "No TaskFlow-type named " + getTaskFlowType() );

            final @NotNull Map<String, String> configMap;

            boolean update = false;
            switch (cfgUpdateMode) {
                case DELKEYS:
                    configMap = taskFlowType.getConfigMapData();
                    for (String opt : getAllOptionNames())
                        if (isValidConfigOptionName(opt)) configMap.remove(opt);
                    break;

                case UPDATE:
                    update = true;
                case READ:
                    configMap = taskFlowType.getConfigMapData();
                    break;
                default:
                    configMap = new HashMap<String, String>(8);
                    update = true;
            }

            if (update) {
                for (String name : getAllOptionNames())
                    try {
                        if (isValidConfigOptionName(name)) configMap.put(name, getOption(name));
                    }
                    catch (MandatoryOptionMissingException e) {
                        // shdouldnt happen
                        throw new RuntimeException(e);
                    }
            }

            // write changed map back to the db, neo requires this
            if( ! UpdateMode.READ.equals( cfgUpdateMode ) )
                taskFlowType.setConfigMapData( configMap );

            session.success();
            return genOutput(configMap);
        } finally { session.finish(); }
    }
String de.zib.gndms.logic.model.gorfx.ConfigTaskFlowTypeAction.genOutput ( final Map< String, String >  configMapParam) [private]

Depending on the selected OutFormat, another message is returned.

If OutFormat is set to

  • PRINT_OK, the String "OK()" is returned.
  • NONE, null is returned
  • PROPS, configMapParam is loaded as Properties and props.toString() will be returned.
  • OPTS returns this.allOptionsToString(false)
Parameters:
configMapParama Map containing the config map of an offer type instance.
Returns:
                                                                       {
        switch (cfgOutFormat) {
            case PRINT_OK:
                return "OK()";
            case NONE:
                return null;
            case PROPS:
                Properties props = new Properties();
                props.putAll(configMapParam);
                return props.toString();
            case OPTS:
            default:
                return allOptionsToString(false);
        }
    }
boolean de.zib.gndms.logic.model.gorfx.ConfigTaskFlowTypeAction.isValidConfigOptionName ( final String  name) [private]

Returns true if name does not start with 'cfg' and is not the String 'taskFlowType'.

Parameters:
namea name of an option
Returns:
                                                               {
        return ! name.startsWith("cfg") && ! "taskFlowType".equals(name);
    }

The documentation for this class was generated from the following file:
 All Classes Namespaces Functions Variables