Project

General

Profile

1
package eu.dnetlib.data.mdstore.modular.action;
2

    
3
import java.util.List;
4
import java.util.Map;
5

    
6
import com.googlecode.sarasvati.GraphProcess;
7
import eu.dnetlib.data.mdstore.MDStoreServiceException;
8
import eu.dnetlib.data.mdstore.modular.MDFormatDescription;
9
import eu.dnetlib.data.mdstore.modular.MDStoreFeeder;
10
import eu.dnetlib.data.mdstore.modular.MDStoreUtils;
11
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
12
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler;
13
import eu.dnetlib.msro.workflows.util.WorkflowsConstants;
14
import org.apache.commons.logging.Log;
15
import org.apache.commons.logging.LogFactory;
16
import org.springframework.beans.factory.annotation.Autowired;
17
import org.springframework.beans.factory.annotation.Required;
18

    
19
public class FeedAction extends AbstractMDStoreAction {
20

    
21
	private static final Log log = LogFactory.getLog(FeedAction.class);
22
    private static final String layoutIndex = "store";
23

    
24
	private MDStoreFeeder feeder;
25

    
26
    @Autowired
27
    private MDStoreUtils mdstoreUtils;
28

    
29

    
30
	@Override
31
	public void executeAsync(final BlackboardServerHandler handler, final BlackboardJob job) throws MDStoreServiceException {
32

    
33
		final String mdId = job.getParameters().get("mdId");
34
		if ((mdId == null) || mdId.isEmpty()) throw new MDStoreServiceException("Blackboard param (mdId) is empty");
35

    
36
		final String epr = job.getParameters().get("epr");
37
		if ((epr == null) || epr.isEmpty()) throw new MDStoreServiceException("Blackboard param (mdId) is empty");
38

    
39
		String storingType = job.getParameters().get("storingType");
40
		if ((storingType == null) || storingType.isEmpty()) {
41
			storingType = "REFRESH";
42
		}
43
        String format = feeder.getDao().getMDStore(mdId).getFormat();
44
        List<MDFormatDescription> mdformats = mdstoreUtils.getField(format, layoutIndex);
45

    
46
        if (mdformats != null) {
47
            for (MDFormatDescription desc : mdformats) {
48
                log.info("name: " + desc.getName());
49
                log.info("xpath: " + desc.getXpath());
50
            }
51
        }
52

    
53
        final String processId = job.getParameters().get(WorkflowsConstants.SYSTEM_WF_PROCESS_ID);
54
		final GraphProcess proc = getGraphProcessRegistry().findProcess(processId);
55

    
56
		log.info(String.format("feeding mdstore %s from workflow process %s", mdId, processId));
57

    
58
        feeder.feed(mdId, epr, storingType, true, mdformats, proc, params -> {
59
			job.getParameters().put("mdstoreSize", "" + params.get("mdstoreSize"));
60
			job.getParameters().put("writeOps", "" + params.get("writeOps"));
61
			completeWithSuccess(handler, job);
62
		}, (e, params) -> {
63
			log.error("Error feeding mdstore: " + mdId, e);
64
			job.getParameters().put("mdstoreSize", "" + params.get("mdstoreSize"));
65
			job.getParameters().put("writeOps", "" + params.get("writeOps"));
66
			completeWithFail(handler, job, e);
67
		});
68
	}
69

    
70
	public MDStoreFeeder getFeeder() {
71
		return feeder;
72
	}
73

    
74
	@Required
75
	public void setFeeder(final MDStoreFeeder feeder) {
76
		this.feeder = feeder;
77
	}
78

    
79
}
(7-7/11)