Project

General

Profile

Download (4.56 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2019 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.dataportal.elements;
10

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

    
14
import org.apache.logging.log4j.LogManager;
15
import org.apache.logging.log4j.Logger;
16
import org.openqa.selenium.By;
17
import org.openqa.selenium.WebElement;
18

    
19
/**
20
 * @author a.kohlbecker
21
 * @since Feb 4, 2019
22
 *
23
 */
24
abstract public class RegistrationItem extends BaseElement {
25

    
26
    private static final Logger logger = LogManager.getLogger();
27

    
28
    enum Style {
29
        /**
30
         * style produced by modules/cdm_dataportal/includes/name.inc#compose_registration_dto_full()
31
         */
32
        FULL,
33
        /**
34
         * style produced by modules/cdm_dataportal/includes/name.inc#compose_registration_dto_compact()
35
         */
36
        COMPACT
37
    }
38

    
39
    protected Style style = null;
40
    protected List<BaseElement> specimenTypeDesignations;
41
    protected List<BaseElement> nameTypeDesignations;
42
    protected WebElement citation;
43
    protected WebElement metadata;
44
    protected WebElement identifier;
45
    protected WebElement nameElement;
46
    protected List<BaseElement> nameRelationsipsElements;
47
    protected List<BaseElement> registrationFootnotes;
48
    protected WebElement typifiedNameElement;
49
    protected WebElement summaryElement;
50

    
51

    
52
    protected RegistrationItem(WebElement containerElement) {
53
        super(containerElement);
54

    
55
        try {
56
            summaryElement = containerElement.findElement(By.cssSelector(".registration-summary"));
57
            style = Style.COMPACT;
58
            identifier = containerElement.findElement(By.cssSelector(".identifier"));
59
        } catch (Exception e) {
60
            logger.debug("web element .registration-summary not found, now trying full style elements");
61
        }
62

    
63
        if(style == null){
64
            try {
65
                nameElement = containerElement.findElement(By.cssSelector(".published-name"));
66
            } catch (Exception e) {
67
                try {
68
                    typifiedNameElement = containerElement.findElement(By.cssSelector(".typified-name"));
69
                } catch (Exception e2) {
70
                    // typifiedNameElement must exist when nameElement is not present, so we throw the  Exception in this case:
71
                    throw e2;
72
                }
73
            }
74
            try{
75
                List<WebElement> std = containerElement.findElements(By.cssSelector(".name_relationships .item"));
76
                nameRelationsipsElements = new ArrayList<BaseElement>(std.size());
77
                for(WebElement we : std){
78
                    nameRelationsipsElements.add(new BaseElement(we));
79
                }
80
            } catch (Exception e) { /* IGNORE */}
81
            try{
82
                List<WebElement> std = containerElement.findElements(By.cssSelector(".footnotes-nomenclatural_act .footnote"));
83
                registrationFootnotes = new ArrayList<BaseElement>(std.size());
84
                for(WebElement we : std){
85
                    registrationFootnotes.add(new BaseElement(we));
86
                }
87
            } catch (Exception e) { /* IGNORE */}
88
            try{
89
                List<WebElement> std = containerElement.findElements(By.cssSelector(".cdm\\:SpecimenTypeDesignation"));
90
                specimenTypeDesignations = new ArrayList<BaseElement>(std.size());
91
                for(WebElement we : std){
92
                    specimenTypeDesignations.add(new BaseElement(we));
93
                }
94
            } catch (Exception e) { /* IGNORE */}
95
            try {
96
                List<WebElement> ntd = containerElement.findElements(By.cssSelector(".name_type_designation"));
97
                nameTypeDesignations = new ArrayList<BaseElement>(ntd.size());
98
                for(WebElement we : ntd){
99
                    nameTypeDesignations.add(new BaseElement(we));
100
                }
101
            } catch (Exception e) { /* IGNORE */}
102
            try {
103
                citation = containerElement.findElement(By.cssSelector(".citation"));
104
                style = Style.FULL;
105
            } catch (Exception e) { /* IGNORE */}
106

    
107

    
108
        }
109
        // now the general elements which must exist
110
        metadata = containerElement.findElement(By.cssSelector(".registration-date-and-institute"));
111
    }
112

    
113

    
114
    public Style getStyle() {
115
        return style;
116
    }
117

    
118
    public WebElement getMetadata() {
119
        return metadata;
120
    }
121

    
122
    public WebElement getIdentifier() {
123
        return identifier;
124
    }
125

    
126

    
127

    
128
}
(18-18/27)