Project

General

Profile

1
package eu.dnetlib.data.objectstore.modular;
2

    
3
import eu.dnetlib.data.objectstore.rmi.ObjectStoreServiceException;
4
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
5
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler;
6
import org.apache.commons.lang3.StringUtils;
7
import org.apache.commons.logging.Log;
8
import org.apache.commons.logging.LogFactory;
9

    
10
/**
11
 * The Class CreateObjectStoreAction is responsible to execute the blacboard action of type CREATE.
12
 */
13
public class CreateObjectStoreAction extends AbstractObjectStoreAction {
14

    
15
	private static final Log log = LogFactory.getLog(CreateObjectStoreAction.class);
16

    
17
	/** The profile creator. */
18
	private ObjectStoreProfileCreator profileCreator;
19

    
20
	/**
21
	 * Gets the profile creator.
22
	 *
23
	 * @return the profile creator
24
	 */
25
	public ObjectStoreProfileCreator getProfileCreator() {
26
		return profileCreator;
27
	}
28

    
29
	/**
30
	 * Sets the profile creator.
31
	 *
32
	 * @param profileCreator the new profile creator
33
	 */
34
	public void setProfileCreator(final ObjectStoreProfileCreator profileCreator) {
35
		this.profileCreator = profileCreator;
36
	}
37

    
38
	@Override
39
	protected void executeAsync(final BlackboardServerHandler handler, final BlackboardJob job) {
40
		try {
41
			final String interpretation = job.getParameters().get("interpretation");
42
//			final String basePath = job.getParameters().get("basePath");
43
//			if (StringUtils.isBlank(basePath)) {
44
//				throw new ObjectStoreServiceException("missing basePath param");
45
//			}
46

    
47
			final String objID = profileCreator.registerProfile(interpretation);
48
			try {
49
				getDao().createObjectStore(objID, interpretation, null);
50
			} catch (Throwable e) {
51
				log.warn("cannot created objectStore, deleting profile");
52
				profileCreator.deleteProfile(objID);
53
				throw new ObjectStoreServiceException(e);
54
			}
55
			job.getParameters().put("objectStoreId", objID);
56
			completeWithSuccess(handler, job);
57
		} catch (Exception e) {
58
			completeWithFail(handler, job, e);
59
		}
60

    
61
	}
62
}
(2-2/15)