Project

General

Profile

Download (2.67 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2017 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;
10

    
11
import java.util.Collection;
12
import java.util.UUID;
13

    
14
import org.apache.commons.lang3.StringUtils;
15

    
16
import eu.etaxonomy.cdm.model.CdmSimpleNameTypeFilter;
17
import eu.etaxonomy.cdm.model.CdmTypeScanner;
18
import eu.etaxonomy.cdm.model.common.CdmBase;
19

    
20
/**
21
 * Can parse class attributes created by the php function html_class_attribute_ref()
22
 * in modules/cdm_dataportal/cdm_dataportal.module
23
 *
24
 * Example:
25
 * <code>
26
 * cdm:SpecimenTypeDesignation uuid:35d876b0-8a13-44db-a66d-94acdd319c01
27
 * </code>
28
 *
29
 * @author a.kohlbecker
30
 * @since Oct 10, 2017
31
 *
32
 */
33
public class CdmEntityClassAttributes {
34

    
35
    private Class<? extends CdmBase> cdmType = null;
36

    
37
    private UUID enitytyUuid = null;
38

    
39
    public CdmEntityClassAttributes(String classAttributes) throws Exception{
40
        if(StringUtils.isNotEmpty(classAttributes)){
41
            for(String token : StringUtils.split(classAttributes)){
42
                if(token.startsWith("cdm:")){
43
                    setCdmType(findType(token.substring(4)));
44
                } else if(token.startsWith("uuid:")){
45
                    setEnitytyUuid(UUID.fromString(token.substring(5)));
46
                }
47
            }
48
        }
49
    }
50

    
51
    private Class<? extends CdmBase> findType(String simpleName) throws Exception {
52

    
53
        CdmTypeScanner<CdmBase> scanner = new CdmTypeScanner<CdmBase>(false, false);
54
        //scanner.addIncludeFilter(new AnnotationTypeFilter(Entity.class));
55
        scanner.addIncludeFilter(new CdmSimpleNameTypeFilter(simpleName));
56
        Collection<Class<? extends CdmBase>> classes = scanner.scanTypesIn("eu/etaxonomy/cdm/model");
57
        if(classes.isEmpty()){
58
            return null;
59
        } else if(classes.size() == 1){
60
            return classes.iterator().next();
61
        } else {
62
            throw new Exception("Multiple matching classes found for simple name '" + simpleName + "'");
63
        }
64

    
65
    }
66

    
67
    /**
68
     * @return the cdmType
69
     */
70
    public Class<? extends CdmBase> getCdmType() {
71
        return cdmType;
72
    }
73

    
74
    /**
75
     * @param cdmType the cdmType to set
76
     */
77
    public void setCdmType(Class<? extends CdmBase> cdmType) {
78
        this.cdmType = cdmType;
79
    }
80

    
81
    /**
82
     * @return the enitytyUuid
83
     */
84
    public UUID getEnitytyUuid() {
85
        return enitytyUuid;
86
    }
87

    
88
    /**
89
     * @param enitytyUuid the enitytyUuid to set
90
     */
91
    public void setEnitytyUuid(UUID enitytyUuid) {
92
        this.enitytyUuid = enitytyUuid;
93
    }
94

    
95
}
(2-2/14)