Revision 41416
Added by Alessia Bardi about 8 years ago
modules/dnet-openaire-blacklist/branches/prod/src/test/java/eu/dnetlib/openaire/blacklist/OpenaireIdResolverTest.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.blacklist; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
|
6 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
7 |
import junit.framework.Assert; |
|
8 |
import org.apache.commons.logging.Log; |
|
9 |
import org.apache.commons.logging.LogFactory; |
|
10 |
import org.junit.Before; |
|
11 |
import org.junit.Ignore; |
|
12 |
import org.junit.Test; |
|
13 |
import org.junit.runner.RunWith; |
|
14 |
import org.mockito.Mock; |
|
15 |
import org.mockito.Mockito; |
|
16 |
import org.mockito.runners.MockitoJUnitRunner; |
|
17 |
|
|
18 |
@RunWith(MockitoJUnitRunner.class) |
|
19 |
public class OpenaireIdResolverTest { |
|
20 |
|
|
21 |
private static final Log log = LogFactory.getLog(OpenaireIdResolverTest.class); |
|
22 |
private final String id = "dedup_wf_001::00066fdc65f1e21677c69d976a8e852d"; |
|
23 |
private OpenaireIdResolver resolver; |
|
24 |
@Mock |
|
25 |
private ISLookUpService isLookupService; |
|
26 |
@Mock |
|
27 |
private UniqueServiceLocator serviceLocator; |
|
28 |
|
|
29 |
@Before |
|
30 |
public void setUp() throws Exception { |
|
31 |
resolver = new OpenaireIdResolver(); |
|
32 |
Mockito.when(serviceLocator.getService(ISLookUpService.class)).thenReturn(isLookupService); |
|
33 |
Mockito.when(isLookupService.getResourceProfile(Mockito.startsWith("for $x in collection('/db/DRIVER/ServiceResources/IndexServiceResourceType')"))) |
|
34 |
.thenReturn("beta.solr.openaire.eu:9983"); |
|
35 |
Mockito.when(isLookupService.getResourceProfile(Mockito.startsWith("for $x in collection('/db/DRIVER/ServiceResources/SearchServiceResourceType')"))) |
|
36 |
.thenReturn("DMF"); |
|
37 |
resolver.setServiceLocator(serviceLocator); |
|
38 |
|
|
39 |
} |
|
40 |
|
|
41 |
@Ignore |
|
42 |
@Test |
|
43 |
public void testFindOriginalIds() throws Exception { |
|
44 |
log.debug("Testing for " + id); |
|
45 |
List<String> originals = resolver.findOriginalIds(id); |
|
46 |
Assert.assertTrue(originals.contains("od_______165::deb6d865011c09f228af41a30e0ff1a4")); |
|
47 |
Assert.assertTrue(originals.contains("od_______165::00066fdc65f1e21677c69d976a8e852d")); |
|
48 |
Assert.assertTrue(originals.size() == 2); |
|
49 |
|
|
50 |
} |
|
51 |
} |
modules/dnet-openaire-blacklist/branches/prod/src/test/java/eu/dnetlib/openaire/blacklist/BlacklistManagerTest.java | ||
---|---|---|
15 | 15 |
@Before |
16 | 16 |
public void setUp() throws Exception { |
17 | 17 |
input.add( |
18 |
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<ROW><FIELD name=\"iis_module\">iis::document_referencedProjects</FIELD><FIELD name=\"ticket_id\">1245</FIELD><FIELD name=\"last_update_time\">2015-09-18 12:39:11.781532</FIELD><FIELD name=\"status\">accepted</FIELD><FIELD name=\"userid\">unknown</FIELD><FIELD name=\"iis_module_profile\" isNull=\"true\"/><FIELD name=\"original_target_objects\" isNull=\"true\"/><FIELD name=\"relationship\">resultProject_outcome_isProducedBy</FIELD><FIELD name=\"id\">1</FIELD><FIELD name=\"provenance\">iis</FIELD><FIELD name=\"iis_status\">unsolved</FIELD><FIELD name=\"original_source_objects\" isNull=\"true\"/><FIELD name=\"creation_time\">2015-09-18 12:39:11.781532</FIELD><FIELD name=\"target_object\">corda_______::fda6a1c19dac47508b6fb619518328c7</FIELD><FIELD name=\"note\" isNull=\"true\"/><FIELD name=\"source_object\">od_______908::a47e1c3ede9a21ee5278a2e5c338d69b</FIELD></ROW>"); |
|
18 |
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<ROW><FIELD name=\"iis_module\">iis::document_referencedProjects</FIELD><FIELD name=\"ticket_id\">1245</FIELD><FIELD name=\"last_update_time\">2015-09-18 12:39:11.781532</FIELD><FIELD name=\"status\">accepted</FIELD><FIELD name=\"userid\">unknown</FIELD><FIELD name=\"iis_module_profile\" isNull=\"true\"/><FIELD name=\"original_target_objects\" isNull=\"true\"/><FIELD name=\"relationship\">resultProject_outcome_isProducedBy</FIELD><FIELD name=\"id\">1</FIELD><FIELD name=\"provenance\">iis</FIELD><FIELD name=\"iis_status\">unsolved</FIELD><FIELD name=\"original_source_objects\" isNull=\"true\"/><FIELD name=\"creation_time\">2015-09-18 12:39:11.781532</FIELD><FIELD name=\"target_object\">corda_______::fda6a1c19dac47508b6fb619518328c7</FIELD><FIELD name=\"note\" isNull=\"true\"/><FIELD name=\"source_object\">od_______908::a47e1c3ede9a21ee5278a2e5c338d69b</FIELD><FIELD name=\"source_type\">result</FIELD><FIELD name=\"target_type\">project</FIELD></ROW>");
|
|
19 | 19 |
input.add( |
20 |
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<ROW><FIELD name=\"iis_module\">iis::document_referencedProjects</FIELD><FIELD name=\"ticket_id\">1245</FIELD><FIELD name=\"last_update_time\">2015-09-18 12:39:11.789433</FIELD><FIELD name=\"status\">accepted</FIELD><FIELD name=\"userid\">unknown</FIELD><FIELD name=\"iis_module_profile\" isNull=\"true\"/><FIELD name=\"original_target_objects\" isNull=\"true\"/><FIELD name=\"relationship\">resultProject_outcome_isProducedBy</FIELD><FIELD name=\"id\">2</FIELD><FIELD name=\"provenance\">iis</FIELD><FIELD name=\"iis_status\">unsolved</FIELD><FIELD name=\"original_source_objects\" isNull=\"true\"/><FIELD name=\"creation_time\">2015-09-18 12:39:11.789433</FIELD><FIELD name=\"target_object\">corda_______::189ff31d637eaaeaf4d3584dc490b1cf</FIELD><FIELD name=\"note\" isNull=\"true\"/><FIELD name=\"source_object\">od_______908::a47e1c3ede9a21ee5278a2e5c338d69b</FIELD></ROW>"); |
|
20 |
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<ROW><FIELD name=\"iis_module\">iis::document_referencedProjects</FIELD><FIELD name=\"ticket_id\">1245</FIELD><FIELD name=\"last_update_time\">2015-09-18 12:39:11.789433</FIELD><FIELD name=\"status\">accepted</FIELD><FIELD name=\"userid\">unknown</FIELD><FIELD name=\"iis_module_profile\" isNull=\"true\"/><FIELD name=\"original_target_objects\" isNull=\"true\"/><FIELD name=\"relationship\">resultProject_outcome_isProducedBy</FIELD><FIELD name=\"id\">2</FIELD><FIELD name=\"provenance\">iis</FIELD><FIELD name=\"iis_status\">unsolved</FIELD><FIELD name=\"original_source_objects\" isNull=\"true\"/><FIELD name=\"creation_time\">2015-09-18 12:39:11.789433</FIELD><FIELD name=\"target_object\">corda_______::189ff31d637eaaeaf4d3584dc490b1cf</FIELD><FIELD name=\"note\" isNull=\"true\"/><FIELD name=\"source_object\">od_______908::a47e1c3ede9a21ee5278a2e5c338d69b</FIELD><FIELD name=\"source_type\">result</FIELD><FIELD name=\"target_type\">project</FIELD></ROW>");
|
|
21 | 21 |
input.add( |
22 |
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<ROW><FIELD name=\"iis_module\">iis::document_referencedProjects</FIELD><FIELD name=\"ticket_id\">1297</FIELD><FIELD name=\"last_update_time\">2015-09-18 12:39:11.854513</FIELD><FIELD name=\"status\">accepted</FIELD><FIELD name=\"userid\">unknown</FIELD><FIELD name=\"iis_module_profile\" isNull=\"true\"/><FIELD name=\"original_target_objects\" isNull=\"true\"/><FIELD name=\"relationship\">resultProject_outcome_isProducedBy</FIELD><FIELD name=\"id\">12</FIELD><FIELD name=\"provenance\">iis</FIELD><FIELD name=\"iis_status\">unsolved</FIELD><FIELD name=\"original_source_objects\" isNull=\"true\"/><FIELD name=\"creation_time\">2015-09-18 12:39:11.854513</FIELD><FIELD name=\"target_object\">corda_______::35695c955c51f0bb39482ce5477047c7</FIELD><FIELD name=\"note\" isNull=\"true\"/><FIELD name=\"source_object\">webcrawl____::ae0ae3ea5641ac24fa148ac38397dfcd</FIELD></ROW>"); |
|
22 |
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<ROW><FIELD name=\"iis_module\">iis::document_referencedProjects</FIELD><FIELD name=\"ticket_id\">1297</FIELD><FIELD name=\"last_update_time\">2015-09-18 12:39:11.854513</FIELD><FIELD name=\"status\">accepted</FIELD><FIELD name=\"userid\">unknown</FIELD><FIELD name=\"iis_module_profile\" isNull=\"true\"/><FIELD name=\"original_target_objects\" isNull=\"true\"/><FIELD name=\"relationship\">resultProject_outcome_isProducedBy</FIELD><FIELD name=\"id\">12</FIELD><FIELD name=\"provenance\">iis</FIELD><FIELD name=\"iis_status\">unsolved</FIELD><FIELD name=\"original_source_objects\" isNull=\"true\"/><FIELD name=\"creation_time\">2015-09-18 12:39:11.854513</FIELD><FIELD name=\"target_object\">corda_______::35695c955c51f0bb39482ce5477047c7</FIELD><FIELD name=\"note\" isNull=\"true\"/><FIELD name=\"source_object\">webcrawl____::ae0ae3ea5641ac24fa148ac38397dfcd</FIELD><FIELD name=\"source_type\">result</FIELD><FIELD name=\"target_type\">project</FIELD></ROW>");
|
|
23 | 23 |
input.add( |
24 |
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<ROW><FIELD name=\"iis_module\">iis::document_referencedProjects</FIELD><FIELD name=\"ticket_id\">1297</FIELD><FIELD name=\"last_update_time\">2015-09-18 12:39:11.895653</FIELD><FIELD name=\"status\">accepted</FIELD><FIELD name=\"userid\">unknown</FIELD><FIELD name=\"iis_module_profile\" isNull=\"true\"/><FIELD name=\"original_target_objects\" isNull=\"true\"/><FIELD name=\"relationship\">resultProject_outcome_isProducedBy</FIELD><FIELD name=\"id\">17</FIELD><FIELD name=\"provenance\">iis</FIELD><FIELD name=\"iis_status\">unsolved</FIELD><FIELD name=\"original_source_objects\" isNull=\"true\"/><FIELD name=\"creation_time\">2015-09-18 12:39:11.895653</FIELD><FIELD name=\"target_object\">corda_______::35695c955c51f0bb39482ce5477047c7</FIELD><FIELD name=\"note\" isNull=\"true\"/><FIELD name=\"source_object\">webcrawl____::6ce2789da52c6036501533ed5613d71a</FIELD></ROW>"); |
|
24 |
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<ROW><FIELD name=\"iis_module\">iis::document_referencedProjects</FIELD><FIELD name=\"ticket_id\">1297</FIELD><FIELD name=\"last_update_time\">2015-09-18 12:39:11.895653</FIELD><FIELD name=\"status\">accepted</FIELD><FIELD name=\"userid\">unknown</FIELD><FIELD name=\"iis_module_profile\" isNull=\"true\"/><FIELD name=\"original_target_objects\" isNull=\"true\"/><FIELD name=\"relationship\">resultProject_outcome_isProducedBy</FIELD><FIELD name=\"id\">17</FIELD><FIELD name=\"provenance\">iis</FIELD><FIELD name=\"iis_status\">unsolved</FIELD><FIELD name=\"original_source_objects\" isNull=\"true\"/><FIELD name=\"creation_time\">2015-09-18 12:39:11.895653</FIELD><FIELD name=\"target_object\">corda_______::35695c955c51f0bb39482ce5477047c7</FIELD><FIELD name=\"note\" isNull=\"true\"/><FIELD name=\"source_object\">webcrawl____::6ce2789da52c6036501533ed5613d71a</FIELD><FIELD name=\"source_type\">result</FIELD><FIELD name=\"target_type\">project</FIELD></ROW>");
|
|
25 | 25 |
input.add( |
26 |
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<ROW><FIELD name=\"iis_module\">iis::document_referencedProjects</FIELD><FIELD name=\"ticket_id\">1360</FIELD><FIELD name=\"last_update_time\">2015-09-18 12:39:11.955417</FIELD><FIELD name=\"status\">accepted</FIELD><FIELD name=\"userid\">unknown</FIELD><FIELD name=\"iis_module_profile\" isNull=\"true\"/><FIELD name=\"original_target_objects\" isNull=\"true\"/><FIELD name=\"relationship\">resultProject_outcome_isProducedBy</FIELD><FIELD name=\"id\">23</FIELD><FIELD name=\"provenance\">iis</FIELD><FIELD name=\"iis_status\">unsolved</FIELD><FIELD name=\"original_source_objects\" isNull=\"true\"/><FIELD name=\"creation_time\">2015-09-18 12:39:11.955417</FIELD><FIELD name=\"target_object\">corda_______::800e636c0a24ac3767701a789a96ba89</FIELD><FIELD name=\"note\" isNull=\"true\"/><FIELD name=\"source_object\">od______2367::eb76f733498920166d4ce77ec37d487c</FIELD></ROW>"); |
|
26 |
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<ROW><FIELD name=\"iis_module\">iis::document_referencedProjects</FIELD><FIELD name=\"ticket_id\">1360</FIELD><FIELD name=\"last_update_time\">2015-09-18 12:39:11.955417</FIELD><FIELD name=\"status\">accepted</FIELD><FIELD name=\"userid\">unknown</FIELD><FIELD name=\"iis_module_profile\" isNull=\"true\"/><FIELD name=\"original_target_objects\" isNull=\"true\"/><FIELD name=\"relationship\">resultProject_outcome_isProducedBy</FIELD><FIELD name=\"id\">23</FIELD><FIELD name=\"provenance\">iis</FIELD><FIELD name=\"iis_status\">unsolved</FIELD><FIELD name=\"original_source_objects\" isNull=\"true\"/><FIELD name=\"creation_time\">2015-09-18 12:39:11.955417</FIELD><FIELD name=\"target_object\">corda_______::800e636c0a24ac3767701a789a96ba89</FIELD><FIELD name=\"note\" isNull=\"true\"/><FIELD name=\"source_object\">od______2367::eb76f733498920166d4ce77ec37d487c</FIELD><FIELD name=\"source_type\">result</FIELD><FIELD name=\"target_type\">project</FIELD></ROW>");
|
|
27 | 27 |
|
28 | 28 |
blManager = new BlacklistManager(); |
29 | 29 |
} |
modules/dnet-openaire-blacklist/branches/prod/src/test/resources/log4j.properties | ||
---|---|---|
1 |
### Root Level ### |
|
2 |
log4j.rootLogger=WARN, CONSOLE |
|
3 |
|
|
4 |
|
|
5 |
### Configuration for the CONSOLE appender ### |
|
6 |
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender |
|
7 |
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout |
|
8 |
log4j.appender.CONSOLE.layout.ConversionPattern=[%-5p] %d %c - %m%n |
|
9 |
|
|
10 |
org.apache.cxf.Logger=org.apache.cxf.common.logging.Log4jLogger |
|
11 |
|
|
12 |
### Application Level ### |
|
13 |
log4j.logger.eu.dnetlib=INFO |
|
14 |
log4j.logger.eu.dnetlib.openaire.blacklist=DEBUG |
|
15 |
|
|
16 |
|
modules/dnet-openaire-blacklist/branches/prod/src/main/java/eu/dnetlib/openaire/blacklist/OpenaireIdResolver.java | ||
---|---|---|
1 |
package eu.dnetlib.openaire.blacklist; |
|
2 |
|
|
3 |
import java.io.StringReader; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
import com.google.common.base.Function; |
|
7 |
import com.google.common.collect.Iterables; |
|
8 |
import com.google.common.collect.Lists; |
|
9 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException; |
|
10 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
|
11 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
12 |
import org.apache.commons.lang.StringUtils; |
|
13 |
import org.apache.commons.logging.Log; |
|
14 |
import org.apache.commons.logging.LogFactory; |
|
15 |
import org.apache.solr.client.solrj.SolrQuery; |
|
16 |
import org.apache.solr.client.solrj.impl.CloudSolrServer; |
|
17 |
import org.apache.solr.client.solrj.response.QueryResponse; |
|
18 |
import org.apache.solr.common.SolrDocument; |
|
19 |
import org.apache.solr.common.SolrDocumentList; |
|
20 |
import org.dom4j.Attribute; |
|
21 |
import org.dom4j.Document; |
|
22 |
import org.dom4j.DocumentException; |
|
23 |
import org.dom4j.io.SAXReader; |
|
24 |
import org.springframework.beans.factory.annotation.Autowired; |
|
25 |
|
|
26 |
/** |
|
27 |
* The goal of this task is to return the original identifiers of objects merged in a representative object by deduplication. |
|
28 |
* Created by alessia on 09/02/16. |
|
29 |
*/ |
|
30 |
public class OpenaireIdResolver { |
|
31 |
|
|
32 |
public final static String SOLR_COLLECTION_POSTFIX = "-index-openaire"; |
|
33 |
private static final Log log = LogFactory.getLog(OpenaireIdResolver.class); |
|
34 |
private final static String RESULT_FIELD = "__result"; |
|
35 |
private final static String XPATH_TO_MERGED = "//*[local-name()='entity']/*//children/result/@objidentifier"; |
|
36 |
private final SAXReader saxReader = new SAXReader(); |
|
37 |
@Autowired |
|
38 |
private UniqueServiceLocator serviceLocator; |
|
39 |
|
|
40 |
public List<String> resolveIdentifier(final String id) { |
|
41 |
if (StringUtils.isBlank(id)) return Lists.newArrayList(); |
|
42 |
else { |
|
43 |
return findOriginalIds(id); |
|
44 |
} |
|
45 |
} |
|
46 |
|
|
47 |
protected List<String> findOriginalIds(final String id) { |
|
48 |
CloudSolrServer solrCore = null; |
|
49 |
SolrQuery q = new SolrQuery("objidentifier:\"" + id + "\""); |
|
50 |
QueryResponse response = null; |
|
51 |
try { |
|
52 |
solrCore = new CloudSolrServer(getIndexEndpoint()); |
|
53 |
solrCore.setDefaultCollection(getPublicIndexCollection() + SOLR_COLLECTION_POSTFIX); |
|
54 |
response = solrCore.query(q); |
|
55 |
SolrDocumentList results = response.getResults(); |
|
56 |
if (results.isEmpty()) { |
|
57 |
log.debug("Query " + q + " returned 0 documents"); |
|
58 |
return Lists.newArrayList(); |
|
59 |
} |
|
60 |
//my results contain the document with the given identifier |
|
61 |
SolrDocument solrDoc = results.get(0); |
|
62 |
return extractMergedIdentifiers(solrDoc); |
|
63 |
} catch (Exception e) { |
|
64 |
log.error(e); |
|
65 |
throw new RuntimeException("Can't get original ids for " + id + "\n " + e); |
|
66 |
} finally { |
|
67 |
solrCore.shutdown(); |
|
68 |
} |
|
69 |
} |
|
70 |
|
|
71 |
protected List<String> extractMergedIdentifiers(final SolrDocument doc) throws DocumentException { |
|
72 |
List<String> originals = Lists.newArrayList(); |
|
73 |
String xmlRecord = (String) doc.getFirstValue(RESULT_FIELD); |
|
74 |
Document xmlDoc = this.saxReader.read(new StringReader(xmlRecord)); |
|
75 |
return Lists.newArrayList(Iterables.transform(xmlDoc.selectNodes(XPATH_TO_MERGED), new Function<Attribute, String>() { |
|
76 |
@Override |
|
77 |
public String apply(final Attribute a) { |
|
78 |
return a.getStringValue(); |
|
79 |
} |
|
80 |
})); |
|
81 |
} |
|
82 |
|
|
83 |
protected String getIndexEndpoint() throws ISLookUpException { |
|
84 |
return this.serviceLocator.getService(ISLookUpService.class).getResourceProfile( |
|
85 |
"for $x in collection('/db/DRIVER/ServiceResources/IndexServiceResourceType') return $x//PROTOCOL[./@name='solr']/@address/string()"); |
|
86 |
} |
|
87 |
|
|
88 |
protected String getPublicIndexCollection() throws ISLookUpException { |
|
89 |
return this.serviceLocator.getService(ISLookUpService.class).getResourceProfile( |
|
90 |
"for $x in collection('/db/DRIVER/ServiceResources/SearchServiceResourceType') return $x[.//PROPERTY[@key='infrastructure']/@value='public']//PROPERTY[@key='mdformat']/@value/string()"); |
|
91 |
} |
|
92 |
|
|
93 |
public UniqueServiceLocator getServiceLocator() { |
|
94 |
return serviceLocator; |
|
95 |
} |
|
96 |
|
|
97 |
public void setServiceLocator(final UniqueServiceLocator serviceLocator) { |
|
98 |
this.serviceLocator = serviceLocator; |
|
99 |
} |
|
100 |
|
|
101 |
} |
modules/dnet-openaire-blacklist/branches/prod/src/main/java/eu/dnetlib/openaire/blacklist/BlacklistManager.java | ||
---|---|---|
33 | 33 |
private UniqueServiceLocator serviceLocator; |
34 | 34 |
@Autowired |
35 | 35 |
private ResultSetClientFactory resultSetClientFactory; |
36 |
@Autowired |
|
37 |
private OpenaireIdResolver openaireIdResolver; |
|
36 | 38 |
|
39 |
private List<String> getOriginalIds(String id, String entityType) { |
|
40 |
List<String> originalIds = Lists.newArrayList(); |
|
41 |
//We need to find original ids only for entities that are deduplicated: result, organization, person. |
|
42 |
if (entityType.equals("result") || entityType.equals("organization") || entityType.equals("person")) { |
|
43 |
originalIds = openaireIdResolver.resolveIdentifier(id); |
|
44 |
} |
|
45 |
return originalIds; |
|
46 |
} |
|
47 |
|
|
37 | 48 |
public boolean addToBlacklist(final BlacklistEntry entry) throws Exception { |
49 |
List<String> sourceIds = getOriginalIds(entry.getSourceObject(), entry.getSourceType()); |
|
50 |
List<String> targetIds = getOriginalIds(entry.getTargetObject(), entry.getTargetType()); |
|
51 |
entry.setOriginalSourceObjects(sourceIds); |
|
52 |
entry.setOriginalTargetObjects(targetIds); |
|
53 |
|
|
38 | 54 |
DatabaseService dbService = serviceLocator.getService(DatabaseService.class); |
39 |
|
|
55 |
String addQuery = String.format( |
|
56 |
"INSERT INTO blacklist(userid, relationship, provenance, iis_module, iis_status, status, source_object, source_type, target_object, target_type, " |
|
57 |
+ "ticket_id, original_source_objects, original_target_objects, note) " |
|
58 |
+ " VALUES('%1$s', '%2$s', '%3$s', '%4$s', '%5$s', '%6$s', '%7$s', '%8$s', '%9$s', '%10$s', '%11$s', '%12$s', '%13$s', '%14$s') ", |
|
59 |
entry.getUser(), |
|
60 |
entry.getRelationship(), |
|
61 |
entry.getProvenance(), |
|
62 |
entry.getIisModule(), |
|
63 |
entry.getIisStatus(), |
|
64 |
entry.getStatus(), |
|
65 |
entry.getSourceObject(), |
|
66 |
entry.getSourceType(), |
|
67 |
entry.getTargetObject(), |
|
68 |
entry.getTargetType(), |
|
69 |
entry.getTicketId(), |
|
70 |
joinCollectionForSQL(sourceIds.isEmpty() ? |
|
71 |
Lists.newArrayList(entry.getSourceObject()) : |
|
72 |
sourceIds), |
|
73 |
joinCollectionForSQL(targetIds.isEmpty() ? |
|
74 |
Lists.newArrayList(entry.getTargetObject()) : |
|
75 |
targetIds), |
|
76 |
entry.getNote()); |
|
77 |
log.debug("Adding new blacklist entry"); |
|
40 | 78 |
return this |
41 | 79 |
.safeUpdateSql( |
42 | 80 |
dbService, |
43 |
blacklistDatabaseName, |
|
44 |
String.format( |
|
45 |
"INSERT INTO blacklist(userid, relationship, provenance, iis_module, iis_status, status, source_object, source_type, target_object, target_type, ticket_id, original_source_objects, original_target_objects, note) " |
|
46 |
+ " VALUES('%1$s', '%2$s', '%3$s', '%4$s', '%5$s', '%6$s', '%7$s', '%8$s', '%9$s', '%10$s', '%11$s', '%12$s', '%13$s', '%14$s') ", |
|
47 |
entry.getUser(), |
|
48 |
entry.getRelationship(), |
|
49 |
entry.getProvenance(), |
|
50 |
entry.getIisModule(), |
|
51 |
entry.getIisStatus(), |
|
52 |
entry.getStatus(), |
|
53 |
entry.getSourceObject(), |
|
54 |
entry.getSourceType(), |
|
55 |
entry.getTargetObject(), |
|
56 |
entry.getTargetType(), |
|
57 |
entry.getTicketId(), |
|
58 |
joinCollectionForSQL(entry.getOriginalSourceObjects().isEmpty() ? |
|
59 |
Lists.newArrayList(entry.getSourceObject()) : |
|
60 |
entry.getOriginalSourceObjects()), |
|
61 |
joinCollectionForSQL(entry.getOriginalTargetObjects().isEmpty() ? |
|
62 |
Lists.newArrayList(entry.getTargetObject()) : |
|
63 |
entry.getOriginalTargetObjects()), |
|
64 |
entry.getNote())); |
|
81 |
blacklistDatabaseName, addQuery); |
|
65 | 82 |
} |
66 | 83 |
|
67 | 84 |
private String joinCollectionForSQL(final Collection<String> coll) { |
... | ... | |
69 | 86 |
} |
70 | 87 |
|
71 | 88 |
public boolean editBlacklistEntry(BlacklistEntry entry) throws Exception { |
72 |
DatabaseService dbService = serviceLocator.getService(DatabaseService.class); |
|
89 |
List<String> sourceIds = getOriginalIds(entry.getSourceObject(), entry.getSourceType()); |
|
90 |
List<String> targetIds = getOriginalIds(entry.getTargetObject(), entry.getTargetType()); |
|
91 |
entry.setOriginalSourceObjects(sourceIds); |
|
92 |
entry.setOriginalTargetObjects(targetIds); |
|
93 |
DatabaseService dbService = serviceLocator.getService(DatabaseService.class); |
|
94 |
String editQuery = String.format( |
|
95 |
"UPDATE blacklist SET userid='%s', relationship='%s', provenance='%s', iis_module='%s', iis_status='%s', status='%s', source_object='%s', source_type='%s', " |
|
96 |
+ "target_object='%s', target_type='%s', ticket_id='%s', original_source_objects='%s', original_target_objects='%s', note='%s' WHERE id='%s' ", |
|
97 |
entry.getUser(), |
|
98 |
entry.getRelationship(), |
|
99 |
entry.getProvenance(), |
|
100 |
entry.getIisModule(), |
|
101 |
entry.getIisStatus(), |
|
102 |
entry.getStatus(), |
|
103 |
entry.getSourceObject(), |
|
104 |
entry.getSourceType(), |
|
105 |
entry.getTargetObject(), |
|
106 |
entry.getTargetType(), |
|
107 |
entry.getTicketId(), |
|
108 |
joinCollectionForSQL(sourceIds.isEmpty() ? |
|
109 |
Lists.newArrayList(entry.getSourceObject()) : |
|
110 |
sourceIds), |
|
111 |
joinCollectionForSQL(targetIds.isEmpty() ? |
|
112 |
Lists.newArrayList(entry.getTargetObject()) : |
|
113 |
targetIds), |
|
114 |
entry.getNote(), |
|
115 |
entry.getId()); |
|
116 |
log.debug("Editing blacklist entry: " + entry.getId()); |
|
73 | 117 |
return this |
74 | 118 |
.safeUpdateSql( |
75 | 119 |
dbService, |
76 |
blacklistDatabaseName, |
|
77 |
String.format( |
|
78 |
"UPDATE blacklist SET userid='%s', iis_status='%s', status='%s', source_object='%s', source_type='%s', relationship='%s', target_object='%s', target_type='%s', ticket_id='%s', note='%s', original_source_objects='%s', original_target_objects='%s' WHERE id='%s' ", |
|
79 |
entry.getUser(), |
|
80 |
entry.getIisStatus(), |
|
81 |
entry.getStatus(), |
|
82 |
entry.getSourceObject(), |
|
83 |
entry.getSourceType(), |
|
84 |
entry.getRelationship(), |
|
85 |
entry.getTargetObject(), |
|
86 |
entry.getTargetType(), |
|
87 |
entry.getTicketId(), |
|
88 |
entry.getNote(), |
|
89 |
joinCollectionForSQL(entry.getOriginalSourceObjects().isEmpty() ? |
|
90 |
Lists.newArrayList(entry.getSourceObject()) : |
|
91 |
entry.getOriginalSourceObjects()), |
|
92 |
joinCollectionForSQL(entry.getOriginalTargetObjects().isEmpty() ? |
|
93 |
Lists.newArrayList(entry.getTargetObject()) : |
|
94 |
entry.getOriginalTargetObjects()), |
|
95 |
entry.getId())); |
|
120 |
blacklistDatabaseName, editQuery); |
|
96 | 121 |
|
97 | 122 |
} |
98 | 123 |
|
99 | 124 |
public boolean deleteFromBlacklist(int entryId) throws Exception { |
100 | 125 |
DatabaseService dbService = serviceLocator.getService(DatabaseService.class); |
101 |
return this |
|
102 |
.safeUpdateSql( |
|
103 |
dbService, |
|
104 |
blacklistDatabaseName, |
|
105 |
String.format( |
|
106 |
"DELETE FROM blacklist WHERE id='%s' ", entryId)); |
|
126 |
log.debug("Deleting entry " + entryId + " from blacklist"); |
|
127 |
return this |
|
128 |
.safeUpdateSql( |
|
129 |
dbService, |
|
130 |
blacklistDatabaseName, |
|
131 |
String.format( |
|
132 |
"DELETE FROM blacklist WHERE id='%s' ", entryId)); |
|
107 | 133 |
} |
108 | 134 |
|
109 | 135 |
public Iterable<BlacklistEntry> getBlacklist() { |
... | ... | |
144 | 170 |
be.setTicketId(doc.selectSingleNode("//FIELD[./@name='ticket_id']").getText()); |
145 | 171 |
be.setUser(doc.selectSingleNode("//FIELD[./@name='userid']").getText()); |
146 | 172 |
be.setSourceObject(doc.selectSingleNode("//FIELD[./@name='source_object']").getText()); |
173 |
be.setSourceType(doc.selectSingleNode("//FIELD[./@name='source_type']").getText()); |
|
147 | 174 |
be.setTargetObject(doc.selectSingleNode("//FIELD[./@name='target_object']").getText()); |
175 |
be.setTargetType(doc.selectSingleNode("//FIELD[./@name='target_type']").getText()); |
|
148 | 176 |
String provenance = doc.selectSingleNode("//FIELD[./@name='provenance']").getText(); |
149 | 177 |
be.setProvenance(provenance); |
150 | 178 |
if (provenance.equalsIgnoreCase("iis")) { |
... | ... | |
179 | 207 |
} |
180 | 208 |
|
181 | 209 |
public enum IIS_STATUS { |
182 |
UNSOLVED, SOLVED;
|
|
210 |
UNSOLVED, SOLVED |
|
183 | 211 |
} |
184 | 212 |
|
185 | 213 |
public enum STATUS { |
186 |
PENDING, ACCEPTED, REFUSED, DELETED;
|
|
214 |
PENDING, ACCEPTED, REFUSED, DELETED
|
|
187 | 215 |
} |
188 | 216 |
|
189 | 217 |
} |
modules/dnet-openaire-blacklist/branches/prod/src/main/java/eu/dnetlib/openaire/blacklist/BlacklistEntry.java | ||
---|---|---|
18 | 18 |
/** |
19 | 19 |
* A note regarding the reported 'wrong' relationship |
20 | 20 |
**/ |
21 |
private String note = "";
|
|
21 |
private String note; |
|
22 | 22 |
/** |
23 | 23 |
* The id of the ticket associated to this entry |
24 | 24 |
**/ |
25 |
private String ticketId = "";
|
|
25 |
private String ticketId; |
|
26 | 26 |
/** |
27 |
* Provenance of the relationship. 'iis' when the relationship is inferred |
|
27 |
* Provenance of the relationship. 'iis' when the relationship is inferred. 'crosswalk' if it is aggregated. 'claim' if it is a claim.
|
|
28 | 28 |
**/ |
29 |
private String provenance = "iis"; |
|
29 |
private String provenance; |
|
30 |
/** |
|
31 |
* Relationship label: 'resultProject_outcome_isProducedBy' for result-project relationships. |
|
32 |
*/ |
|
33 |
private String relationship; |
|
30 | 34 |
|
31 |
private String relationship = "resultProject_outcome_isProducedBy"; |
|
32 |
|
|
33 | 35 |
/** |
34 |
* The inference module that generated the relationship. Blank if provenance is not 'iis'. |
|
36 |
* The inference module that generated the relationship. 'iis::document_referencedProjects' for result-project relationships. Blank if provenance is not 'iis'.
|
|
35 | 37 |
**/ |
36 |
private String iisModule = "iis::document_referencedProjects";
|
|
38 |
private String iisModule = ""; |
|
37 | 39 |
|
38 | 40 |
/** |
39 | 41 |
* Status of the report |
... | ... | |
42 | 44 |
/** |
43 | 45 |
* Status of the issue from the pov of IIS. Blank if provenance is not 'iis'. |
44 | 46 |
**/ |
45 |
private IIS_STATUS iisStatus = IIS_STATUS.UNSOLVED;
|
|
47 |
private IIS_STATUS iisStatus = null;
|
|
46 | 48 |
|
47 |
// using String instead of date because the datasource manager forgets the types. |
|
48 | 49 |
private String creationDate, lastUpdateDate; |
49 | 50 |
|
50 | 51 |
/** |
modules/dnet-openaire-blacklist/branches/prod/src/main/resources/eu/dnetlib/applicationContext-dnet-openaire-blacklist.xml | ||
---|---|---|
1 | 1 |
<?xml version="1.0" encoding="UTF-8"?> |
2 |
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
3 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
2 |
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
3 |
xmlns="http://www.springframework.org/schema/beans"
|
|
4 | 4 |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> |
5 | 5 |
|
6 | 6 |
<bean id="blacklistManager" class="eu.dnetlib.openaire.blacklist.BlacklistManager" /> |
7 | 7 |
|
8 |
<bean id="openaireIdResolver" class="eu.dnetlib.openaire.blacklist.OpenaireIdResolver"/> |
|
9 |
|
|
8 | 10 |
<bean id="wfNodeApplyBlacklistJob" class="eu.dnetlib.msro.workflows.blacklist.ApplyBlacklistJobNode" |
9 | 11 |
scope="prototype" /> |
10 | 12 |
|
modules/dnet-openaire-blacklist/branches/prod/src/main/resources/eu/dnetlib/web/resources/html/blacklist/blacklistEntryForm.html | ||
---|---|---|
9 | 9 |
<label for="sourceTypeSelect">Source object type</label> |
10 | 10 |
|
11 | 11 |
<div> |
12 |
<select name="sourceTypeSelect" id="sourceTypeSelect" ng-model="entry.sourceType">
|
|
12 |
<select class="form-control" id="sourceTypeSelect" ng-model="entry.sourceType">
|
|
13 | 13 |
<option ng-repeat="entityType in entityTypes" value="{{entityType}}">{{entityType}}</option> |
14 | 14 |
</select> |
15 | 15 |
</div> |
... | ... | |
18 | 18 |
<label for="sourceObject">Source object id</label> |
19 | 19 |
|
20 | 20 |
<div> |
21 |
<input id="sourceObject" class="form-control" ng-model="entry.sourceObject"
|
|
21 |
<input class="form-control" id="sourceObject" ng-model="entry.sourceObject"
|
|
22 | 22 |
type="text"/> |
23 | 23 |
</div> |
24 | 24 |
</div> |
25 |
<div class="form-group"> |
|
26 |
<label for="originalSourceObjects">Source object original ids</label> |
|
27 | 25 |
|
28 |
<div id="originalSourceObjects"> |
|
29 |
<ul class="list-group"> |
|
30 |
<li class="list-group-item"> |
|
31 |
<input class="form-control" ng-model="newSourceId"> |
|
32 |
<button class="btn btn-success btn-xs" type="button" ng-click="addSourceId(newSourceId)"><span |
|
33 |
class="glyphicon glyphicon-plus" |
|
34 |
aria-hidden="true"></span></button> |
|
35 |
</li> |
|
36 |
<li class="list-group-item" ng-repeat="origId in entry.originalSourceObjects"> |
|
37 |
<button class="btn btn-xs btn-danger" type="button" ng-click="removeOriginalSourceId(origId)"><span |
|
38 |
class="glyphicon glyphicon-remove" |
|
39 |
aria-hidden="true"></span></button> |
|
40 |
{{origId}} |
|
41 |
</li> |
|
42 |
|
|
43 |
</ul> |
|
44 |
</div> |
|
45 |
</div> |
|
46 |
|
|
47 | 26 |
<div class="form-group"> |
48 | 27 |
<label for="relationType">Relationship</label> |
49 | 28 |
|
50 | 29 |
<div> |
51 |
<select name="relationType" id="relationType" ng-model="entry.relationship">
|
|
30 |
<select class="form-control" id="relationType" ng-model="entry.relationship">
|
|
52 | 31 |
<option ng-repeat="relType in relationTypes" value="{{relType}}">{{relType}}</option> |
53 | 32 |
</select> |
54 | 33 |
</div> |
... | ... | |
57 | 36 |
<label for="targetTypeSelect">Target object type</label> |
58 | 37 |
|
59 | 38 |
<div> |
60 |
<select name="targetTypeSelect" id="targetTypeSelect" ng-model="entry.targetType">
|
|
39 |
<select class="form-control" required id="targetTypeSelect" ng-model="entry.targetType">
|
|
61 | 40 |
<option ng-repeat="entityType in entityTypes" value="{{entityType}}">{{entityType}}</option> |
62 | 41 |
</select> |
63 | 42 |
</div> |
... | ... | |
66 | 45 |
<label for="targetObject">Target object id</label> |
67 | 46 |
|
68 | 47 |
<div> |
69 |
<input id="targetObject" class="form-control" ng-model="entry.targetObject"
|
|
48 |
<input class="form-control" id="targetObject" ng-model="entry.targetObject"
|
|
70 | 49 |
type="text"/> |
71 | 50 |
</div> |
72 | 51 |
</div> |
73 |
<div class="form-group"> |
|
74 |
<label for="originalTargetObjects">Target object original ids</label> |
|
75 | 52 |
|
76 |
<div id="originalTargetObjects"> |
|
77 |
<ul class="list-group"> |
|
78 |
<li class="list-group-item"> |
|
79 |
<input class="form-control" ng-model="newTargetId"> |
|
80 |
<button class="btn btn-xs btn-success" type="button" ng-click="addTargetId(newTargetId)"><span |
|
81 |
class="glyphicon glyphicon-plus" |
|
82 |
aria-hidden="true"></span></button> |
|
83 |
</li> |
|
84 |
<li class="list-group-item" ng-repeat="origId in entry.originalTargetObjects"> |
|
85 |
<button class="btn btn-xs btn-danger" type="button" ng-click="removeOriginalTargetId(origId)"><span |
|
86 |
class="glyphicon glyphicon-remove" |
|
87 |
aria-hidden="true"></span></button> |
|
88 |
{{origId}} |
|
89 |
</li> |
|
53 |
<div class="form-group"> |
|
54 |
<label for="provenanceSelect">Provenance</label> |
|
90 | 55 |
|
91 |
</ul> |
|
92 |
</div> |
|
93 |
</div> |
|
94 |
|
|
56 |
<div><select class="form-control" id="provenanceSelect" ng-model="entry.provenance"> |
|
57 |
<option>iis</option> |
|
58 |
<option>crosswalk</option> |
|
59 |
<option>claim</option> |
|
60 |
<option>unknown</option> |
|
61 |
</select></div> |
|
62 |
</div> |
|
63 |
<!-- |
|
95 | 64 |
<div class="form-group"> |
96 | 65 |
<label for="provenance">Provenance</label> |
97 | 66 |
|
98 | 67 |
<div> |
99 | 68 |
<input id="provenance" class="form-control" ng-model="entry.provenance" |
100 |
type="text" placeholder="E.g. iis or crosswalk"/>
|
|
69 |
type="text" placeholder="E.g. iis, crosswalk, claim"/>
|
|
101 | 70 |
</div> |
102 | 71 |
</div> |
72 |
--> |
|
103 | 73 |
<div class="form-group"> |
104 | 74 |
<label for="iisModule">IIS module</label> |
105 | 75 |
|
... | ... | |
130 | 100 |
<div class="form-group"> |
131 | 101 |
<label for="note">Note</label> |
132 | 102 |
|
133 |
<div><textarea class="form-control" rows="3" ng-model="entry.note" |
|
134 |
id="note"></textarea> |
|
103 |
<div><textarea class="form-control" rows="3" ng-model="entry.note" id="note"></textarea> |
|
135 | 104 |
</div> |
136 | 105 |
</div> |
137 | 106 |
</form> |
modules/dnet-openaire-blacklist/branches/prod/src/main/resources/eu/dnetlib/web/resources/js/blacklist.js | ||
---|---|---|
22 | 22 |
$scope.entityTypes = ['result', 'project', 'datasource', 'organization', 'person']; |
23 | 23 |
$scope.relationTypes = []; |
24 | 24 |
|
25 |
$scope.removeOriginalSourceId = function (id) { |
|
26 |
$scope.entry.originalSourceObjects = $filter('filter')($scope.entry.originalSourceObjects, '!' + id); |
|
27 |
}; |
|
28 |
|
|
29 |
$scope.removeOriginalTargetId = function (id) { |
|
30 |
$scope.entry.originalTargetObjects = $filter('filter')($scope.entry.originalTargetObjects, '!' + id); |
|
31 |
}; |
|
32 |
|
|
33 |
$scope.addSourceId = function (id) { |
|
34 |
if ($scope.entry.originalSourceObjects == undefined) $scope.entry.originalSourceObjects = []; |
|
35 |
$scope.entry.originalSourceObjects.push(id); |
|
36 |
$scope.newSourceId = null; |
|
37 |
}; |
|
38 |
|
|
39 |
$scope.addTargetId = function (id) { |
|
40 |
if ($scope.entry.originalTargetObjects == undefined) $scope.entry.originalTargetObjects = []; |
|
41 |
$scope.entry.originalTargetObjects.push(id); |
|
42 |
$scope.newTargetId = null; |
|
43 |
}; |
|
44 |
|
|
45 | 25 |
$scope.getListOfRelationships = function () { |
46 | 26 |
$http.get('blacklist/getListOfRelationships.do').success(function (data) { |
47 | 27 |
$scope.relationTypes = data; |
modules/dnet-openaire-blacklist/branches/prod/pom.xml | ||
---|---|---|
1 | 1 |
<?xml version="1.0" encoding="UTF-8"?> |
2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
|
2 |
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
|
3 | 3 |
<parent> |
4 | 4 |
<groupId>eu.dnetlib</groupId> |
5 | 5 |
<artifactId>dnet-parent</artifactId> |
... | ... | |
10 | 10 |
<groupId>eu.dnetlib</groupId> |
11 | 11 |
<artifactId>dnet-openaire-blacklist</artifactId> |
12 | 12 |
<packaging>jar</packaging> |
13 |
<version>0.0.6-SNAPSHOT</version> |
|
13 |
<version>0.0.6-PROD-SNAPSHOT</version>
|
|
14 | 14 |
<scm> |
15 | 15 |
<developerConnection> |
16 | 16 |
scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/dnet-openaire-blacklist/branches/prod |
... | ... | |
59 | 59 |
<version>${junit.version}</version> |
60 | 60 |
<scope>test</scope> |
61 | 61 |
</dependency> |
62 |
<dependency> |
|
63 |
<groupId>org.mockito</groupId> |
|
64 |
<artifactId>mockito-core</artifactId> |
|
65 |
<version>1.9.5</version> |
|
66 |
</dependency> |
|
62 | 67 |
|
63 | 68 |
</dependencies> |
64 | 69 |
</project> |
Also available in: Unified diff
merged revision 41193, 41194, 41256-41258, 41311 from trunk to include the functionality of automatically resolved identifiers and little improvement in the UI