Project

General

Profile

Download (4.45 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.openqa.selenium.By;
15
import org.openqa.selenium.WebElement;
16

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

    
24
    enum Style {
25
        /**
26
         * style produced by modules/cdm_dataportal/includes/name.inc#compose_registration_dto_full()
27
         */
28
        FULL,
29
        /**
30
         * style produced by modules/cdm_dataportal/includes/name.inc#compose_registration_dto_compact()
31
         */
32
        COMPACT
33
    }
34

    
35
    protected Style style = null;
36
    protected List<BaseElement> specimenTypeDesignations;
37
    protected List<BaseElement> nameTypeDesignations;
38
    protected WebElement citation;
39
    protected WebElement metadata;
40
    protected WebElement identifier;
41
    protected WebElement nameElement;
42
    protected List<BaseElement> nameRelationsipsElements;
43
    protected List<BaseElement> registrationFootnotes;
44
    protected WebElement typifiedNameElement;
45
    protected WebElement summaryElement;
46

    
47
    /**"
48
     * @param element
49
     */
50
    protected RegistrationItem(WebElement containerElement) {
51
        super(containerElement);
52

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

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

    
105

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

    
111

    
112
    public Style getStyle() {
113
        return style;
114
    }
115

    
116
    public WebElement getMetadata() {
117
        return metadata;
118
    }
119

    
120
    public WebElement getIdentifier() {
121
        return identifier;
122
    }
123

    
124

    
125

    
126
}
(15-15/23)