summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/CreateNewAgent.java
blob: 45ae445e5c7c0ff17a33cd87438d74102e686d46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**************************************************************************
 * CreateNewAgent.java
 *
 * Copyright (C) 2001 CERN - European Organization for Nuclear Research
 * All rights reserved.
 **************************************************************************/

package com.c2kernel.lifecycle.instance.predefined.server;

import com.c2kernel.common.InvalidDataException;
import com.c2kernel.entity.imports.ImportAgent;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.ItemPath;
import com.c2kernel.process.Gateway;
import com.c2kernel.utils.Logger;

public class CreateNewAgent extends PredefinedStep
{
    public CreateNewAgent()
    {
        super();
		getProperties().put("SchemaType", "Agent");
    }

	//requestdata is xmlstring
    @Override
	protected String runActivityLogic(AgentPath agent, ItemPath item,
			int transitionID, String requestData) throws InvalidDataException {
    	
        String redactedRequestData;
        try {
            ImportAgent newAgent = (ImportAgent)Gateway.getMarshaller().unmarshall(requestData);
            newAgent.create(agent, true);
            newAgent.setPassword("REDACTED");
            redactedRequestData = Gateway.getMarshaller().marshall(newAgent);
            return redactedRequestData;
        } catch (Exception ex) {
            Logger.error(ex);
            throw new InvalidDataException("Error creating agent", "");
        }

    }
}