1
|
/**
|
2
|
* Copyright (C) 2020 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.UUID;
|
12
|
import java.util.regex.Matcher;
|
13
|
import java.util.regex.Pattern;
|
14
|
|
15
|
import org.apache.commons.lang3.StringUtils;
|
16
|
import org.openqa.selenium.WebElement;
|
17
|
|
18
|
|
19
|
/**
|
20
|
* @author a.kohlbecker
|
21
|
* @since May 26, 2020
|
22
|
*/
|
23
|
public class EntityReference {
|
24
|
|
25
|
/**
|
26
|
* @return the cdmType
|
27
|
*/
|
28
|
public String getCdmType() {
|
29
|
return cdmType;
|
30
|
}
|
31
|
|
32
|
/**
|
33
|
* @return the uuid
|
34
|
*/
|
35
|
public UUID getUuid() {
|
36
|
return uuid;
|
37
|
}
|
38
|
|
39
|
String cdmType;
|
40
|
UUID uuid;
|
41
|
|
42
|
private static final Pattern pattern = Pattern.compile(".*(?:cdm\\:)([a-zA-Z]+).*(?:uuid\\:)([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}).*");
|
43
|
|
44
|
|
45
|
private EntityReference(String cdmType, UUID uuid) {
|
46
|
this.cdmType = cdmType;
|
47
|
this.uuid = uuid;
|
48
|
}
|
49
|
|
50
|
public static EntityReference from(WebElement webElement) {
|
51
|
String classAttributes = webElement.getAttribute("class");
|
52
|
assert !StringUtils.isEmpty(classAttributes);
|
53
|
Matcher m = pattern.matcher(classAttributes);
|
54
|
assert m.matches();
|
55
|
return new EntityReference(m.group(1), UUID.fromString(m.group(2)));
|
56
|
}
|
57
|
|
58
|
}
|