Project

General

Profile

Revision f852bff0

IDf852bff01fb4b3282c51e209ce5264f6bb09f2ac
Parent fad21775
Child 42002c0a

Added by Patrick Plitzner almost 3 years ago

ref #7095 Add progress monitor to working set service (unstable)

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IWorkingSetService.java
7 7
import java.util.UUID;
8 8

  
9 9
import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
10
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
10 11
import eu.etaxonomy.cdm.model.description.DescriptionBase;
11 12
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
12 13
import eu.etaxonomy.cdm.model.description.DescriptiveSystemRole;
......
42 43
     * Returns a collection of {@link RowWrapperDTO} objects for the given {@link WorkingSet}.<br>
43 44
     * A RowWrapper represents on row in the character matrix.
44 45
     * @param workingSet the working set for which the row wrapper objects should be fetched
45
     * @return a collection of row wrapper objects
46
     * @param the progress monitor
47
     * @return a list of row wrapper objects
46 48
     */
47
    public Collection<RowWrapperDTO> getRowWrapper(WorkingSet workingSet);
49
    public Collection<RowWrapperDTO> getRowWrapper(WorkingSet workingSet, IProgressMonitor monitor);
50

  
51
    /**
52
     * Monitored invocation of {@link IWorkingSetService#getRowWrapper(WorkingSet, IProgressMonitor)}
53
     * @param workingSet the working set for which getRowWrapper() is invoked
54
     * @return the uuid of the monitor
55
     */
56
    public UUID monitGetRowWrapper(WorkingSet workingSet);
48 57

  
49 58
    /**
50 59
     * Loads all avaliable specimens wrapped in a {@link RowWrapperDTO} object for
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/WorkingSetService.java
1 1
package eu.etaxonomy.cdm.api.service;
2 2

  
3
import java.io.Serializable;
3 4
import java.util.ArrayList;
4 5
import java.util.Collection;
5 6
import java.util.List;
6 7
import java.util.Map;
7 8
import java.util.Set;
8 9
import java.util.UUID;
9
import java.util.stream.Collectors;
10 10

  
11 11
import org.apache.log4j.Logger;
12 12
import org.springframework.beans.factory.annotation.Autowired;
......
15 15

  
16 16
import eu.etaxonomy.cdm.api.service.config.FindOccurrencesConfigurator;
17 17
import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
18
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
19
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
20
import eu.etaxonomy.cdm.common.monitor.RemotingProgressMonitorThread;
18 21
import eu.etaxonomy.cdm.filter.TaxonNodeFilter;
19 22
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
20 23
import eu.etaxonomy.cdm.model.description.DescriptionBase;
......
45 48
    @Autowired
46 49
    private ITaxonNodeService taxonNodeService;
47 50

  
51
    @Autowired
52
    private IProgressMonitorService progressMonitorService;
53

  
48 54
	@Override
49 55
	@Autowired
50 56
	protected void setDao(IWorkingSetDao dao) {
......
68 74
        return dao.getWorkingSetUuidAndTitleCache( limitOfInitialElements, pattern);
69 75
    }
70 76

  
77

  
78
    @Override
79
    @Transactional
80
    public UUID monitGetRowWrapper(WorkingSet workingSet) {
81
        RemotingProgressMonitorThread monitorThread = new RemotingProgressMonitorThread() {
82
            @Override
83
            public Serializable doRun(IRemotingProgressMonitor monitor) {
84
                return getRowWrapper(workingSet, monitor);
85
            }
86
        };
87
        UUID uuid = progressMonitorService.registerNewRemotingMonitor(monitorThread);
88
        monitorThread.setPriority(3);
89
        monitorThread.start();
90
        return uuid;
91
    }
92

  
71 93
	@Override
72
	public Collection<RowWrapperDTO> getRowWrapper(WorkingSet workingSet) {
73
	    return workingSet.getDescriptions().stream()
74
	            .map(description->createRowWrapper(null, description, workingSet))
75
	            .collect(Collectors.toList());
94
	public ArrayList<RowWrapperDTO> getRowWrapper(WorkingSet workingSet, IProgressMonitor monitor) {
95
	    ArrayList<RowWrapperDTO> wrappers = new ArrayList<>();
96
	    Set<DescriptionBase> descriptions = workingSet.getDescriptions();
97
	    for (DescriptionBase description : descriptions) {
98
            if(monitor.isCanceled()){
99
                return new ArrayList<>();
100
            }
101
            wrappers.add(createRowWrapper(null, description, workingSet));
102
            monitor.worked(1);
103
        }
104
	    return wrappers;
76 105
	}
77 106

  
78 107
    @Override

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)