Project

General

Profile

« Previous | Next » 

Revision 42170

fixed download into gridfs

View differences:

CreateObjectStoreAction.java
1 1
package eu.dnetlib.data.objectstore;
2 2

  
3
import java.util.List;
4

  
5
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
3 6
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
4 7
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler;
8
import eu.dnetlib.rmi.enabling.ISLookUpException;
9
import eu.dnetlib.rmi.enabling.ISLookUpService;
10
import org.apache.commons.lang3.BooleanUtils;
11
import org.apache.commons.logging.Log;
12
import org.apache.commons.logging.LogFactory;
13
import org.springframework.beans.factory.annotation.Autowired;
5 14

  
6 15
/**
7 16
 * The Class CreateObjectStoreAction is responsible to execute the blacboard action of type CREATE.
8 17
 */
9 18
public class CreateObjectStoreAction extends AbstractObjectStoreAction {
10 19

  
20
	private static final Log log = LogFactory.getLog(CreateObjectStoreAction.class);
21

  
22
	@Autowired
23
	private UniqueServiceLocator locator;
24

  
25

  
11 26
	/**
12 27
	 * The profile creator.
13 28
	 */
......
36 51
		try {
37 52
			final String interpretation = job.getParameters().get("interpretation");
38 53
			final String basePath = job.getParameters().get("basePath");
54
			final boolean createOnlyIfMissing = BooleanUtils.toBoolean(job.getParameters().get("createOnlyIfMissing"));
55
			if (createOnlyIfMissing) {
56
				final String objID = findObjectStoreByInterpretation(interpretation);
57
				if (objID != null) {
58
					job.getParameters().put("objectStoreId", objID);
59
					completeWithSuccess(handler, job);
60
					return;
61
				}
62
			}
63

  
39 64
			final String objID = profileCreator.registerProfile(interpretation);
40 65
			getDao().createObjectStore(objID, interpretation, basePath);
41 66
			job.getParameters().put("objectStoreId", objID);
......
45 70
		}
46 71

  
47 72
	}
73

  
74
	private String findObjectStoreByInterpretation(final String interpretation) {
75
		final ISLookUpService service = locator.getService(ISLookUpService.class);
76
		final String query =
77
				"for $x in collection('/db/DRIVER/ObjectStoreDSResources/ObjectStoreDSResourceType') where $x//OBJECTSTORE_INTERPRETATION='%s' return $x//RESOURCE_IDENTIFIER/@value/string()";
78
		try {
79
			final List<String> strings = service.quickSearchProfile(String.format(query, interpretation));
80
			if (strings != null && strings.size() > 0)
81
				return strings.get(0);
82
		} catch (ISLookUpException e) {
83
			log.error("error on executing query", e);
84

  
85
		}
86
		return null;
87

  
88
	}
48 89
}

Also available in: Unified diff