Project

General

Profile

Download (2.83 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.pages;
10

    
11
import java.net.MalformedURLException;
12
import java.util.ArrayList;
13
import java.util.Collections;
14
import java.util.List;
15
import java.util.UUID;
16

    
17
import org.apache.log4j.Logger;
18
import org.openqa.selenium.By;
19
import org.openqa.selenium.WebDriver;
20
import org.openqa.selenium.WebElement;
21
import org.openqa.selenium.support.CacheLookup;
22
import org.openqa.selenium.support.FindBy;
23

    
24
import eu.etaxonomy.dataportal.DataPortalContext;
25
import eu.etaxonomy.dataportal.elements.TypeDesignationElement;
26

    
27
/**
28
 * @author a.kohlbecker
29
 * @since Feb 4, 2019
30
 *
31
 */
32
public class NamePage extends PortalPage {
33

    
34

    
35
    public static final Logger logger = Logger.getLogger(NamePage.class);
36

    
37
    protected static String drupalPagePathBase = "cdm_dataportal/name";
38

    
39
    @FindBy(className = "typeDesignations")
40
    @CacheLookup
41
    private List<WebElement> typeDesignationContainers;
42

    
43
    private List<List<TypeDesignationElement>> typeDesignationElementsByContainer = null;
44

    
45

    
46
    /**
47
     * @param driver
48
     * @param context
49
     * @throws Exception
50
     */
51
    public NamePage(WebDriver driver, DataPortalContext context) throws Exception {
52
        super(driver, context);
53
    }
54

    
55

    
56
    public NamePage(WebDriver driver, DataPortalContext context, UUID nameUuid) throws MalformedURLException {
57
        super(driver, context, nameUuid.toString());
58
    }
59

    
60
    /**
61
     * {@inheritDoc}
62
     */
63
    @Override
64
    protected String getDrupalPageBase() {
65
        return drupalPagePathBase;
66
    }
67

    
68
    /**
69
     * @return the registrationItem
70
     */
71
    public List<TypeDesignationElement> getTypeDesignations(int typeDesignationsContainerIndex, String enclosingTag) {
72

    
73
        if(typeDesignationElementsByContainer == null){
74
            typeDesignationElementsByContainer = new ArrayList<>(Collections.nCopies(typeDesignationContainers.size(), null));
75
        }
76
        if(typeDesignationElementsByContainer.get(typeDesignationsContainerIndex) == null) {
77
            WebElement container = typeDesignationContainers.get(typeDesignationsContainerIndex);
78
            List<TypeDesignationElement> typeDesignationElements = new ArrayList<>();
79
            List<WebElement> childrenElements = container.findElements(By.cssSelector(":scope > " + enclosingTag)); // direct children
80
            for(WebElement we : childrenElements) {
81
                typeDesignationElements.add(new TypeDesignationElement(we));
82
            }
83
            typeDesignationElementsByContainer.add(typeDesignationsContainerIndex, typeDesignationElements);
84
        }
85
        return typeDesignationElementsByContainer.get(typeDesignationsContainerIndex);
86
    }
87

    
88
}
(2-2/9)