Project

General

Profile

« Previous | Next » 

Revision 38117

updated uoa-web-utils to work with Solr index and DatasourceManager - related to #993

View differences:

modules/uoa-web-utils/trunk/src/main/java/gr/uoa/di/web/utils/DriverStatus.java
1 1
package gr.uoa.di.web.utils;
2 2

  
3 3
import eu.dnetlib.api.data.SearchServiceException;
4
import eu.dnetlib.domain.ActionType;
5 4
import eu.dnetlib.domain.ResourceType;
6 5
import eu.dnetlib.domain.data.Repository;
7 6
import eu.dnetlib.domain.data.RepositorySearchCriteria;
......
47 46
	}
48 47

  
49 48
	public void init() {
50
		serviceImpl.subscribe(ActionType.CREATE, ResourceType.INDEXDSRESOURCETYPE, this);
49
	/*	serviceImpl.subscribe(ActionType.CREATE, ResourceType.INDEXDSRESOURCETYPE, this);
51 50
		serviceImpl.subscribe(ActionType.UPDATE, ResourceType.INDEXDSRESOURCETYPE, this);
52 51
		serviceImpl.subscribe(ActionType.DELETE, ResourceType.INDEXDSRESOURCETYPE, this);
53 52
		serviceImpl.subscribe(ActionType.CREATE, ResourceType.REPOSITORYSERVICERESOURCETYPE, this);
54 53
		serviceImpl.subscribe(ActionType.UPDATE, ResourceType.REPOSITORYSERVICERESOURCETYPE, this);
55 54
		serviceImpl.subscribe(ActionType.DELETE, ResourceType.REPOSITORYSERVICERESOURCETYPE, this);
56
		
55
	*/
57 56
		this.executor = Executors.newSingleThreadScheduledExecutor();
58 57
		this.executor.scheduleWithFixedDelay(new Updater(), 1, 30, TimeUnit.MINUTES);
59 58
	}
......
66 65
		if (enableUpdate) {
67 66
			logger.debug("updating driver status...");
68 67
			try {
69
				int count = searchManager.search("textual", 1, 1)
68
				int count = searchManager.search("*", 1, 1)
70 69
						.getNumberOfDocuments();
71
	
70

  
72 71
				List<Repository> repositories = repositoryLookUp.fetch(new RepositorySearchCriteria());
73 72
				Set<String> countries = new HashSet<String>();
74 73
				
modules/uoa-web-utils/trunk/src/main/java/gr/uoa/di/web/utils/HTMLGenerator.java
2 2

  
3 3
import eu.dnetlib.domain.data.Document;
4 4
import eu.dnetlib.domain.enabling.Vocabulary;
5
import eu.dnetlib.domain.functionality.DisplayType;
6
import eu.dnetlib.domain.functionality.DocumentExternalUrlDisplayType;
7
import eu.dnetlib.domain.functionality.DocumentField;
5
import eu.dnetlib.domain.functionality.*;
8 6
import eu.dnetlib.domain.functionality.DocumentField.Cutpoint;
9
import eu.dnetlib.domain.functionality.ExternalUrlDisplayType;
10
import eu.dnetlib.domain.functionality.InternalUrlDisplayType;
11
import eu.dnetlib.domain.functionality.PlainTextDisplayType;
12
import eu.dnetlib.domain.functionality.SearchDisplayType;
13
import eu.dnetlib.domain.functionality.UrlDisplayType;
14 7
import gr.uoa.di.web.utils.webdocument.StyledValue;
8
import org.apache.log4j.Logger;
15 9

  
16 10
import java.io.UnsupportedEncodingException;
17 11
import java.net.URLEncoder;
18
import java.util.ArrayList;
19
import java.util.HashMap;
20
import java.util.List;
21
import java.util.Locale;
22
import java.util.Map;
12
import java.util.*;
23 13

  
24
import org.apache.log4j.Logger;
25

  
26 14
public class HTMLGenerator {
27 15

  
28 16
	public static Logger logger = Logger.getLogger(HTMLGenerator.class);
......
33 21
		List<StyledValue> htmlValuesList = new ArrayList<StyledValue>();
34 22
		int characterCount = 0;
35 23
		String fieldName = field.getName();
36
		List<String> fieldValues = document.getFieldValues(fieldName);
24
		List<String> fieldValues = document.getFieldValues(fieldName.toLowerCase());
37 25
		generateHTMLValues(fieldName, fieldValues, characterCount, document,
38 26
				htmlValuesList, field, vocabulary, locale);
39 27
		return htmlValuesList;
......
69 57
		for (int i = 0; i < fieldValues.size()
70 58
				&& (characterCount < maxCharacters); i++) {
71 59

  
72
			String fieldValue = document.getFieldValues(fieldName).get(i);
60
			String fieldValue = document.getFieldValues(fieldName.toLowerCase()).get(i);
73 61
			if (vocabulary != null) {
74 62
				String englishName = vocabulary.getEnglishName(fieldValue);
75 63
				if (englishName != null) {
modules/uoa-web-utils/trunk/src/main/java/gr/uoa/di/web/utils/search/SearchManager.java
10 10
import eu.dnetlib.domain.EPR;
11 11
import eu.dnetlib.domain.data.BrowseData;
12 12
import eu.dnetlib.domain.data.Document;
13
import eu.dnetlib.domain.data.SearchResult;
13 14
import eu.dnetlib.domain.functionality.LayoutField;
14 15
import gr.uoa.di.driver.data.browsedata.BrowseDataUtil;
15 16
import gr.uoa.di.driver.enabling.resultset.ResultSet;
......
20 21
import gr.uoa.di.web.utils.search.query.QueryEnhancer;
21 22
import org.apache.log4j.Logger;
22 23

  
23
import java.util.ArrayList;
24
import java.util.HashMap;
25
import java.util.List;
26
import java.util.Map;
24
import java.util.*;
27 25

  
28 26
/**
29 27
 * Manages all searches in the the web interface. All elements in query forms
......
80 78
	 */
81 79
	public DocumentPage search(String query, int pageSize, int pageNumber)
82 80
			throws SearchServiceException {
83
		tLogger.debug("Starting search");
84
		tLogger.debug("Enhancing query");
85
		query = enhancer.enhanceQuery(query);
86
		
81
        tLogger.debug("Starting search");
82
        tLogger.debug("Enhancing query");
83

  
84
        query = enhancer.enhanceQuery(query);
85

  
87 86
		logger.debug("performing search with query = '" + query + "'");
88 87

  
89 88
		try {
90 89
			tLogger.debug("performing search");
91
			EPR epr = null;
92
            //getSearchServiceLocator().getService().search(query);
93
			tLogger.debug("Creating rs");
94
			ResultSet<String> rs = rsFactory.createResultSet(epr);
95 90

  
91
            //TODO fix locale
92
            SearchResult searchResult =
93
                    getSearchServiceLocator().getService().search(query, "simple", Locale.ROOT.toString(), 1, 10);
94

  
95
            //logger.debug("Total search result" + searchResult.getTotal());
96

  
97
			//tLogger.debug("Creating rs");
98

  
96 99
			// update page from result set
97
			tLogger.debug("Creating document page");
98
			DocumentPage page = new DocumentPage(rs, getReader(), pageSize, pageNumber);
100
			//tLogger.debug("Creating document page");
101
			DocumentPage page = new DocumentPage(searchResult.getSearchResults(), getReader(), searchResult.getTotal(), pageSize, pageNumber);
99 102

  
100 103
			return page;
101
		} catch (RuntimeException re) {
104

  
105
		} catch (Throwable re){
102 106
			throw new SearchServiceException(
103 107
					"Error connecting to search service.", re);
104 108
		}
......
112 116
		
113 117
		logger.info("running refine query: '" + query + "' for fields: " + fields);
114 118
		tLogger.debug("performing refine");
115
		EPR epr = null;
116
		//searchServiceLocator.getService().refine(query, fields);
119
		//EPR epr = null;
120
        fields = Arrays.asList(new String[] {"language", "cobjcategory", "repositorynameforbrowsing"});
121
		SearchResult refineResults = searchServiceLocator.getService().refine(query, "simple", Locale.ROOT.toString(), fields);
117 122
		tLogger.debug("Creating rs");
118
		ResultSet<String> rs = rsFactory.createResultSet(epr);
123
        logger.debug("REFINE >> " + refineResults.getBrowseResults());
124
		//ResultSet<String> rs = rsFactory.createResultSet(epr);
119 125

  
120
		if (logger.isDebugEnabled()) {
121
			logger.debug("EPR : " + epr.getEpr());
122
		}
126
		//if (logger.isDebugEnabled()) {
127
		//	logger.debug("EPR : " + epr.getEpr());
128
		//}
123 129

  
124 130
		BrowseData data = new BrowseData();
125
		tLogger.debug("Getting " + (rs.size()) + " elements from rs");
126
		List<String> list = rs.getElements(1, rs.size());
127
		logger.debug("record list size " + list.size());
131
		//tLogger.debug("Getting " + (rs.size()) + " elements from rs");
132
		List<String> list = refineResults.getBrowseResults();
133
		logger.debug("record list size " + list);
128 134
		
129 135
		tLogger.debug("Parsing browse data");
130 136
		if (indexVersion.toLowerCase().equals("new")) {
......
222 228

  
223 229
	public Document retrieveDocument(String id) throws SearchServiceException {
224 230
		try {
225
			PublisherService publisher = getPublisherServiceLocator()
226
					.getService();
227
			return getReader().read(publisher.getResourceById(id, "DMF"));
231
            logger.debug("Getting document with id " + id);
232
            SearchResult searchResult = searchServiceLocator.getService().search("objIdentifier=" + id, "simple", Locale.ROOT.toString(), 1, 1);
228 233

  
234
			return getReader().read(searchResult.getSearchResults().get(0));
235

  
229 236
		} catch (Throwable t) {
230 237
			throw new SearchServiceException(
231 238
					"Cannot retrieve document with id: " + id, t);
......
267 274
			logger.debug("EPR : " + epr.getEpr());
268 275
		}
269 276

  
270
		DocumentPage documentPage = 
271
			new DocumentPage(rs, getReader(), size, page);
277
		DocumentPage documentPage = null;
278
            //TODO
279
			//new DocumentPage(rs, getReader(), size, page);
272 280

  
273 281
		return documentPage;
274 282
	}
modules/uoa-web-utils/trunk/src/main/java/gr/uoa/di/web/utils/search/DocumentReader.java
3 3
 */
4 4
package gr.uoa.di.web.utils.search;
5 5

  
6
import eu.dnetlib.domain.data.Document;
7
import eu.dnetlib.domain.functionality.LayoutField;
8
import org.apache.log4j.Logger;
9
import org.w3c.dom.NodeList;
10
import org.xml.sax.InputSource;
11

  
12
import javax.xml.XMLConstants;
13
import javax.xml.namespace.NamespaceContext;
14
import javax.xml.xpath.*;
6 15
import java.io.StringReader;
7 16
import java.util.ArrayList;
8 17
import java.util.Iterator;
9 18
import java.util.List;
10 19
import java.util.Map;
11 20

  
12
import javax.xml.XMLConstants;
13
import javax.xml.namespace.NamespaceContext;
14
import javax.xml.xpath.XPath;
15
import javax.xml.xpath.XPathConstants;
16
import javax.xml.xpath.XPathExpression;
17
import javax.xml.xpath.XPathExpressionException;
18
import javax.xml.xpath.XPathFactory;
19 21

  
20
import org.apache.log4j.Logger;
21
import org.w3c.dom.NodeList;
22
import org.xml.sax.InputSource;
23

  
24
import eu.dnetlib.domain.data.Document;
25
import eu.dnetlib.domain.functionality.LayoutField;
26

  
27

  
28 22
/**
29 23
 * TODO : add vocabulary support in document reader
30 24
 * 
......
78 72
	
79 73
	public Document read(String xml) {
80 74
		
81
		logger.debug("Got xml " + xml );
75
	//	logger.debug("Got xml " + xml );
82 76
		
83 77
		Document document = new Document();
84
		
85
		for (int i = 0; i < fieldNames.size(); i++) {
78

  
79
        //logger.debug("map keyset" + document.getMap().keySet());
80

  
81
        for (int i = 0; i < fieldNames.size(); i++) {
86 82
			String property = propertyNames.get(i);
87 83
			List<String> values = parseExprValues(xml, fieldPaths.get(i));
88 84

  
89 85
			//logger.debug( propertyNames.get(i) + " - " +values);
90
			
86
            //logger.debug( fieldPaths.get(i) + " - " +values);
91 87
			if (document.getMap().containsKey(property)) {
92 88
				document.getMap().get(property).addAll(values);
93 89
			} else {
......
95 91
			}
96 92
		}	
97 93
		
98
	//	logger.debug("document: " + document.getMap());
94
		//logger.debug("document: " + document.getMap());
99 95
		
100 96
		return document;
101 97
	}
modules/uoa-web-utils/trunk/src/main/java/gr/uoa/di/web/utils/search/DocumentProvider.java
7 7
import gr.uoa.di.web.utils.ep.EPManager;
8 8
import gr.uoa.di.web.utils.ep.EPManagerException;
9 9
import gr.uoa.di.web.utils.ep.domain.Node;
10
import org.apache.log4j.Logger;
10 11

  
11 12
import java.util.ArrayList;
12 13
import java.util.List;
13 14

  
14
import org.apache.log4j.Logger;
15

  
16 15
public class DocumentProvider {
17 16
	
18 17
	private EPManager epManager = null;
......
31 30
	
32 31
			if (xmlDoc != null) {
33 32
				Document doc = getDocumentReader().read(xmlDoc);
34
				if (!doc.getFieldValues("CobjTypology").get(0).toLowerCase().equals("textual")) {
33
				if (!doc.getFieldValues("CobjTypology").get(0).toLowerCase().equals("*")) {
35 34
					logger.debug("Found indexed compound object " + id);
36 35
					logger.debug("Updating indexed compound object from dlms " + id);
37 36
					//TODO: uncomment went dlms is ready!
modules/uoa-web-utils/trunk/src/main/java/gr/uoa/di/web/utils/search/DocumentPage.java
3 3
 */
4 4
package gr.uoa.di.web.utils.search;
5 5

  
6
import java.util.List;
7

  
6
import eu.dnetlib.domain.data.Document;
8 7
import org.apache.log4j.Logger;
9 8

  
10
import eu.dnetlib.domain.data.Document;
11
import gr.uoa.di.driver.enabling.resultset.ResultSet;
9
import java.util.List;
12 10

  
13 11
/**
14 12
 * @author kiatrop
......
33 31
		numberOfDocuments = 0;
34 32
		numberOfPages = 1;
35 33
	}
36
	
34

  
37 35
	public DocumentPage(List<Document> documents, int pageSize,
38 36
			int currentPage, int numberOfDocuments, int numberOfPages) {
39
		
37

  
40 38
		this.documents = documents.toArray(new Document[] {});
41 39
		this.pageSize = pageSize;
42 40
		this.currentPage = currentPage;
43 41
		this.numberOfDocuments = numberOfDocuments;
44 42
		this.numberOfPages = numberOfPages;
45 43
	}
46
	
47
	public DocumentPage(ResultSet<String> resultset, DocumentReader reader,
48
			int pageSize, int page) {
44

  
45
	public DocumentPage(List<String> resultset, DocumentReader reader,
46
                        int numberOfDocuments, int pageSize, int page) {
49 47
		
50 48
		// set sizes
51 49
		this.pageSize = pageSize;
52
		this.numberOfDocuments = resultset.size();
50
        this.numberOfDocuments = numberOfDocuments;
53 51
		
54 52
		if (numberOfDocuments == 0) {
55 53
			currentPage = 0;
......
70 68
			// call result set
71 69
			int from = (currentPage-1)*pageSize+1;
72 70
			int to = (currentPage)*pageSize;
73
			List<String> list = resultset.get(from, to);
74
			
71

  
75 72
			// parse documents in page
76
			this.documents = new Document[list.size()];
77
			for (int i = 0; i < list.size(); i++) {
73
			this.documents = new Document[resultset.size()];
74
			for (int i = 0; i < resultset.size(); i++) {
78 75
				//logger.debug("list element " + i + ": " + list.get(i));
79
				documents[i] = reader.read(list.get(i));
76
				documents[i] = reader.read(resultset.get(i));
80 77
			}
81 78
		}
82 79
	}
modules/uoa-web-utils/trunk/src/main/java/gr/uoa/di/web/utils/search/CriteriaManager.java
1 1
package gr.uoa.di.web.utils.search;
2 2

  
3
import static gr.uoa.di.web.utils.search.criterion.FieldCriterion.Qualifier.ALL;
4
import static gr.uoa.di.web.utils.search.criterion.FieldCriterion.Qualifier.ANY;
5
import static gr.uoa.di.web.utils.search.criterion.FieldCriterion.Qualifier.DATE;
6 3
import eu.dnetlib.domain.enabling.Vocabulary;
7 4
import eu.dnetlib.domain.functionality.SearchableDate;
8
import eu.dnetlib.utils.cql.Cql;
9
import eu.dnetlib.utils.cql.CqlBoolean;
10
import eu.dnetlib.utils.cql.CqlClause;
11
import eu.dnetlib.utils.cql.CqlException;
12
import eu.dnetlib.utils.cql.CqlQuery;
13
import eu.dnetlib.utils.cql.CqlRelation;
14
import eu.dnetlib.utils.cql.CqlTerm;
5
import eu.dnetlib.utils.cql.*;
15 6
import gr.uoa.di.driver.enabling.vocabulary.VocabularyLoader;
16 7
import gr.uoa.di.web.utils.LocaleDescriptionUtil;
17 8
import gr.uoa.di.web.utils.search.criterion.DateCriterion;
18 9
import gr.uoa.di.web.utils.search.criterion.FieldCriterion;
19 10
import gr.uoa.di.web.utils.search.criterion.FieldCriterion.Qualifier;
20 11
import gr.uoa.di.web.utils.search.query.Query;
12
import org.apache.log4j.Logger;
21 13

  
22 14
import java.text.ParseException;
23 15
import java.util.ArrayList;
......
26 18
import java.util.Map;
27 19
import java.util.regex.Pattern;
28 20

  
29
import org.apache.log4j.Logger;
21
import static gr.uoa.di.web.utils.search.criterion.FieldCriterion.Qualifier.*;
30 22

  
31 23
/**
32 24
 * Does all the conversions between criteria, cql, url and description of a
modules/uoa-web-utils/trunk/src/main/java/gr/uoa/di/web/utils/weblayout/WebInterfaceLayoutManagerImpl.java
1 1
package gr.uoa.di.web.utils.weblayout;
2 2

  
3
import eu.dnetlib.domain.functionality.DocumentDescription;
4
import eu.dnetlib.domain.functionality.DocumentField;
5
import eu.dnetlib.domain.functionality.Searchable;
6
import eu.dnetlib.domain.functionality.SwitchDocumentField;
7
import eu.dnetlib.domain.functionality.WebInterfaceLayout;
8
import eu.dnetlib.domain.functionality.WebInterfaceSearchCriteria;
3
import eu.dnetlib.domain.functionality.*;
9 4
import gr.uoa.di.driver.dao.DAOException;
10 5
import gr.uoa.di.web.utils.weblayout.dao.WebInterfaceLayoutDao;
6
import org.apache.log4j.Logger;
11 7

  
12
import java.util.ArrayList;
13
import java.util.Collections;
14
import java.util.Comparator;
15
import java.util.HashMap;
16
import java.util.HashSet;
17
import java.util.List;
18
import java.util.Map;
19
import java.util.Set;
8
import java.util.*;
20 9

  
21
import org.apache.log4j.Logger;
22

  
23 10
public class WebInterfaceLayoutManagerImpl implements WebLayoutManager {
24 11

  
25 12
	// private static boolean USE_CUSTOMISED_LAYOUT = false;
modules/uoa-web-utils/trunk/pom.xml
17 17
                <dependency>
18 18
                        <groupId>eu.dnetlib</groupId>
19 19
                        <artifactId>uoa-commons</artifactId>
20
                        <version>1.0.0</version>
20
                        <version>1.1.0</version>
21 21
                </dependency>
22 22
                <dependency>
23 23
                        <groupId>yadda</groupId>

Also available in: Unified diff