Project

General

Profile

« Previous | Next » 

Revision 53031

Parameterize context utils methods with a boolean parameter for productionIndex, add production url
In delete claims method add check for deleting record

View differences:

modules/uoa-claims/trunk/src/test/java/eu/dnetlib/data/claims/migration/parser/DMFParserTest.java
101 101
    public void dmf2ContextTest() throws IOException, SAXException, ParserConfigurationException, XPathExpressionException {
102 102
        DMFParser dmfParser= new DMFParser();
103 103
        DMFContextHandler dmfContextHandler = new DMFContextHandler();
104
        Context context = dmfContextHandler.extractContextFromDMF(contextDmf);
104
        Context context = dmfContextHandler.extractContextFromDMF(contextDmf, false);
105 105

  
106 106
        Assert.assertEquals("egi::country::gr", context.getOpenaireId());
107 107
        Assert.assertEquals("EGI Federation> EGI Countries> Greece", context.getTitle());
modules/uoa-claims/trunk/src/test/java/eu/dnetlib/data/claims/migration/parser/ContextUtilsTest.java
14 14

  
15 15
        String id= "egi::country::gr";
16 16

  
17
        Assert.assertEquals("EGI Federation> EGI Countries> Greece", ContextUtils.extractLabel(id));
17
        Assert.assertEquals("EGI Federation> EGI Countries> Greece", ContextUtils.extractLabel(id, false));
18 18
        id= "egi";
19
        Assert.assertEquals("EGI Federation", ContextUtils.extractLabel(id));
19
        Assert.assertEquals("EGI Federation", ContextUtils.extractLabel(id, false));
20 20
        id="egi::classification";
21
        Assert.assertEquals("EGI Federation> EGI classification scheme", ContextUtils.extractLabel(id));
21
        Assert.assertEquals("EGI Federation> EGI classification scheme", ContextUtils.extractLabel(id, false));
22 22
        id="egi::classification::natsc";
23
        Assert.assertEquals("EGI Federation> EGI classification scheme> Natural Sciences", ContextUtils.extractLabel(id));
23
        Assert.assertEquals("EGI Federation> EGI classification scheme> Natural Sciences", ContextUtils.extractLabel(id, false));
24 24
        id="egi::classification::natsc::math";
25
        Assert.assertEquals("EGI Federation> EGI classification scheme> Mathematics", ContextUtils.extractLabel(id));
25
        Assert.assertEquals("EGI Federation> EGI classification scheme> Mathematics", ContextUtils.extractLabel(id, false));
26 26
        id="egi::classification::natsc::math::applied";
27
        Assert.assertEquals("EGI Federation> EGI classification scheme> Applied Mathematics", ContextUtils.extractLabel(id));
27
        Assert.assertEquals("EGI Federation> EGI classification scheme> Applied Mathematics", ContextUtils.extractLabel(id, false));
28 28
        id="egi::classification::natsc::math::applied";
29
        Assert.assertEquals("EGI Federation> EGI classification scheme> Applied Mathematics", ContextUtils.extractLabel(id));
29
        Assert.assertEquals("EGI Federation> EGI classification scheme> Applied Mathematics", ContextUtils.extractLabel(id, false));
30 30
        id="aginfra::projects";
31
        Assert.assertEquals("AGINFRA> AGINFRA+ Projects", ContextUtils.extractLabel(id));
32
        id="aginfra::projects::1";
33
        Assert.assertEquals("AGINFRA> AGINFRA+ Projects> European Foodbusiness Transfer Laboratory for stimulating entrepreneurial skills, for fostering innovation and for business creation in the Food Sector", ContextUtils.extractLabel(id));
31
        Assert.assertEquals("AGINFRA> AGINFRA+ Projects", ContextUtils.extractLabel(id, false));
32
        id="aginfra::projects::10";
33
        Assert.assertEquals("AGINFRA> AGINFRA+ Projects> Integrated and innovative key actions for mycotoxin management in the food and feed chain", ContextUtils.extractLabel(id, false));
34 34

  
35 35
/*
36 36

  
modules/uoa-claims/trunk/src/main/java/eu/dnetlib/data/claims/migration/Migration.java
79 79
                source= buildProject(relation.getSourceId(),relation.getClaimId());
80 80
                claim.setSourceType(ClaimUtils.PROJECT);
81 81
            } else if (relation.getSourceType().equals(ClaimUtils.CONTEXT)) {
82
                Context context = dmfContextHandler.fetchContextByIdFromDmf(relation.getSourceId());
82
                Context context = dmfContextHandler.fetchContextByIdFromDmf(relation.getSourceId(), false);
83 83
                source = context;
84 84
                claim.setSourceType(ClaimUtils.CONTEXT);
85 85
            } else if (relation.getSourceType().equals(ClaimUtils.DATASET) || relation.getSourceType().equals(ClaimUtils.PUBLICATION)) {
......
144 144
                    source = buildProject(relation.getSourceId(), relation.getClaimId());
145 145
                    claim.setSourceType(ClaimUtils.PROJECT);
146 146
                } else if (relation.getSourceType().equals(ClaimUtils.CONTEXT)) {
147
                    Context context = dmfContextHandler.fetchContextByIdFromDmf(relation.getSourceId());
147
                    Context context = dmfContextHandler.fetchContextByIdFromDmf(relation.getSourceId(), false);
148 148
                    source = context;
149 149
                    claim.setSourceType(ClaimUtils.CONTEXT);
150 150
                } else if (relation.getSourceType().equals(ClaimUtils.DATASET) || relation.getSourceType().equals(ClaimUtils.PUBLICATION)) {
......
228 228
            System.out.println("Claim id:" + claim.getId());
229 229

  
230 230
            //first work with the Source
231
            Context context = dmfContextHandler.extractContextFromDMF(relation.getContextDmf());
231
            Context context = dmfContextHandler.extractContextFromDMF(relation.getContextDmf(), false);
232 232
            claim.setSourceType(ClaimUtils.CONTEXT);
233 233
            claim.setSource(context);
234 234

  
......
276 276
            logger.info("Claim id:" + claim.getId());
277 277

  
278 278
            //first work with the Source
279
            Context context = dmfContextHandler.extractContextFromDMF(relation.getContextDmf());
279
            Context context = dmfContextHandler.extractContextFromDMF(relation.getContextDmf(),false);
280 280
            claim.setSourceType(ClaimUtils.CONTEXT);
281 281
            claim.setSource(context);
282 282

  
modules/uoa-claims/trunk/src/main/java/eu/dnetlib/data/claims/migration/handler/ClaimHandler.java
29 29
    DMFContextHandler dmfContextHandler = null;
30 30
    ProjectHandler projectHandler = null;
31 31
    ClaimValidation claimValidation = null;
32
    Boolean useProductionIndex =  false;
32
    Boolean useProductionIndex =  null;
33 33

  
34 34
    private static final Logger logger = Logger.getLogger(ClaimHandler.class);
35 35

  
......
182 182
     * @throws Exception
183 183
     */
184 184
    private OpenaireEntity buildOpenaireEntity(String id, String type, String collectedFrom, String accessRights, String embargoDate) throws Exception {
185
        logger.info("HEEEEREEE");
186 185
        if(type==null){
187 186
            return null;
188 187
        }
189 188
        else if(type.equals(ClaimUtils.CONTEXT)){
190
            return DMFContextHandler.fetchContextById(id);
189
            return DMFContextHandler.fetchContextById(id, useProductionIndex);
191 190
        }else if (type.equals(ClaimUtils.PROJECT)){
192 191
            Project project = projectHandler.fetchProjectByID(id, false);
193 192
            if(project == null){
......
294 293
    }
295 294

  
296 295
    public void checkRecordFile(String type, String id) throws SQLStoreException, SQLException {
297
        if(type.equals("publication") || type.equals("dataset")){
296
        if(type.equals("publication") || type.equals("dataset")|| type.equals("other")|| type.equals("software")){
298 297
            this.resultHandler.deleteRecordFile(type,id);
299 298
        }
300 299
    }
......
309 308
            String targetType =rs.getString(4);
310 309
            String targetId =rs.getString(5);
311 310
            String user =rs.getString(6);
311
            this.checkRecordFile(sourceType, sourceId);
312
            this.checkRecordFile(targetType, targetId);
312 313
            ArrayList<Object> params2 = new ArrayList<>();
313 314
            String query2 = queryGenerator.generateDeleteFullClaimQuery(claimId,user,sourceType,sourceId,targetType,targetId, params2);
314 315
            sqlDAO.executeUpdateQuery(query2, params2);
modules/uoa-claims/trunk/src/main/java/eu/dnetlib/data/claims/migration/handler/DMFContextHandler.java
24 24
    QueryGenerator queryGenerator = null;
25 25
    DMFParser dmfParser = null;
26 26

  
27

  
27 28
    private String fetchAllDMFContext(String id) throws Exception, SQLStoreException {
28 29
        ResultSet rs = sqlDAO.executePreparedQuery(queryGenerator.generateSelectConceptDMFClaimsQuery(-1));
29 30
        return rs.getString("xml");
......
34 35
        return rs.getString("xml");
35 36
    }
36 37

  
37
    public Context extractContextFromDMF(String xml) throws ParserConfigurationException, SAXException, XPathExpressionException, IOException {
38
        return fetchContextById(dmfParser.getContextIdFromDMF(xml));
38
    public Context extractContextFromDMF(String xml, Boolean production) throws ParserConfigurationException, SAXException, XPathExpressionException, IOException {
39
        return fetchContextById(dmfParser.getContextIdFromDMF(xml),production );
39 40
    }
40 41

  
41
    public Context fetchContextByIdFromDmf(String id) throws Exception, SQLStoreException {
42
        return extractContextFromDMF(fetchDMFContext(id));
42
    public Context fetchContextByIdFromDmf(String id, Boolean production) throws Exception, SQLStoreException {
43
        return extractContextFromDMF(fetchDMFContext(id), production);
43 44
    }
44 45

  
45
    public static Context fetchContextById(String openaireId) {
46
    public static Context fetchContextById(String openaireId, Boolean production) {
46 47
        Context context = new Context();
47 48
        if(openaireId == null ){
48 49
            return null;
49 50
        }
50 51
        context.setOpenaireId(openaireId);
51 52
        try {
52
            context.setTitle(ContextUtils.extractLabel(context.getOpenaireId()));
53
            context.setTitle(ContextUtils.extractLabel(context.getOpenaireId(),production));
53 54

  
54 55
        } catch (Exception e) {
55 56
            log.error("ContextUtils: Couldn't get Egi label for id " + context.getOpenaireId(),e);
modules/uoa-claims/trunk/src/main/java/eu/dnetlib/data/claimsDemo/ContextUtils.java
13 13
    private static final Logger logger = Logger.getLogger(ClaimHandler.class);
14 14
    private SearchUtils searchUtils = new SearchUtils();
15 15

  
16
    public static String extractLabel(String code) throws Exception {
16
    public static String extractLabel(String code, Boolean production) throws Exception {
17 17
        String[] codeParts = code.split("::");
18 18
        String level0 = "";
19 19
        String level1 = "";
20 20
        String level2 = "";
21 21
        String level3 = "";
22 22
        if (codeParts.length >0) {
23
            String json = SearchUtils.fetchContext("s/");
23
            String json = SearchUtils.fetchContext("s/", production);
24 24
            level0 = getLabel(json, codeParts[0]);
25 25
        }
26 26
        if (codeParts.length >1) {
27
            String json = SearchUtils.fetchContext("/"+codeParts[0]);
27
            String json = SearchUtils.fetchContext("/"+codeParts[0], production);
28 28
            level1 = getLabel(json, codeParts[0]+"::"+codeParts[1]);
29 29
        }
30 30
        if (codeParts.length >2) {
31
            String json = SearchUtils.fetchContext("/category/"+codeParts[0]+"::"+codeParts[1]);
31
            String json = SearchUtils.fetchContext("/category/"+codeParts[0]+"::"+codeParts[1], production);
32 32
            level2 = getLabel(json, codeParts[0]+"::"+codeParts[1]+"::"+codeParts[2]);
33 33
        }
34 34
        if (codeParts.length >3) {
35
            String json = SearchUtils.fetchContext("/category/concept/"+codeParts[0]+"::"+codeParts[1]+"::"+codeParts[2]);
35
            String json = SearchUtils.fetchContext("/category/concept/"+codeParts[0]+"::"+codeParts[1]+"::"+codeParts[2], production);
36 36
            level3 = getSubLabel(json, codeParts[0]+"::"+codeParts[1]+"::"+codeParts[2], codeParts[0]+"::"+codeParts[1]+"::"+codeParts[2]+"::"+codeParts[3],((codeParts.length>4)?(codeParts[0]+"::"+codeParts[1]+"::"+codeParts[2]+"::"+codeParts[3]+"::"+codeParts[4]):null));
37 37
        }
38 38

  
......
173 173
        }
174 174

  
175 175
    public static void main(String[] args) throws Exception {
176
        System.out.println(ContextUtils.extractLabel("egi::classification::natsc::math::applied"));
176
//        System.out.println(ContextUtils.extractLabel("egi::classification::natsc::math::applied", false));
177
        System.out.println(ContextUtils.extractLabel("aginfra::projects::10", false));
178

  
177 179
    }
178 180
}
modules/uoa-claims/trunk/src/main/java/eu/dnetlib/data/claimsDemo/TestClass.java
192 192
    }
193 193
    @Test
194 194
    public void testContext(){
195
        System.out.print(DMFContextHandler.fetchContextById("egi::organisation::uom"));
195
        System.out.print(DMFContextHandler.fetchContextById("egi::organisation::uom", false));
196 196
    }
197 197
    @Test
198 198
    public void testInsert() throws Exception, SQLStoreException {
modules/uoa-claims/trunk/src/main/java/eu/dnetlib/data/claimsDemo/SearchUtils.java
46 46
    private static String orcidUrlSuffix="/works";
47 47
//    private static String contextsAPIUrl="https://dev-openaire.d4science.org/openaire/context";
48 48
    private static String contextsAPIUrl="http://beta.services.openaire.eu:8080/openaire/context";
49
    private static String contextsAPIUrlProduction="http://services.openaire.eu:8080/openaire/context";
49 50
    private boolean useApi=true;
50 51
    private ClaimValidation claimValidation = null;
51 52

  
......
118 119

  
119 120
            return getRequest(getOrcidUrl(id));
120 121
    }
121
    public static String fetchContext(String suffix) throws Exception{
122
    public static String fetchContext(String suffix, boolean production) throws Exception{
122 123

  
123
        return getRequest(getContextsAPIUrl()+suffix);
124
        return getRequest(getContextsAPIUrl(production)+suffix);
124 125
    }
125 126

  
126 127
     public static String getProjectApiUrl(String id, boolean production)  {
......
156 157

  
157 158
        return orcidUrlPrefix+id+orcidUrlSuffix;
158 159
    }
159
    private static String getContextsAPIUrl()  {
160
    private static String getContextsAPIUrl( boolean production)  {
160 161

  
161
        return contextsAPIUrl;
162
        return ((production)?contextsAPIUrlProduction:contextsAPIUrl);
162 163
    }
163 164

  
164 165
    /**
modules/uoa-claims/trunk/src/main/resources/eu/dnetlib/data/claims/migration/springContext-claimsDemo.properties
3 3
services.claimsDemo.db.url = jdbc:postgresql://scoobydoo.di.uoa.gr:5432/claims_www_migration
4 4
services.claimsDemo.db.username = postgres
5 5
services.claimsDemo.db.password = snowflakes
6
services.claimsDemo.directClaim.APIURL = http://beta.services.openaire.eu:8280/is/mvc/api/publications
7 6
services.claimsDemo.useProductionIndex = false
8 7

  
9 8
#email properties

Also available in: Unified diff