1 package eu
.etaxonomy
.taxeditor
.ui
.section
.grantedAuthority
;
5 import org
.apache
.log4j
.Logger
;
6 import org
.springframework
.security
.core
.GrantedAuthority
;
8 import eu
.etaxonomy
.cdm
.api
.service
.IAgentService
;
9 import eu
.etaxonomy
.cdm
.api
.service
.IClassificationService
;
10 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
11 import eu
.etaxonomy
.cdm
.api
.service
.INameService
;
12 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
13 import eu
.etaxonomy
.cdm
.api
.service
.IReferenceService
;
14 import eu
.etaxonomy
.cdm
.api
.service
.IRegistrationService
;
15 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
16 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
17 import eu
.etaxonomy
.cdm
.api
.service
.IUserService
;
18 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
19 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.permission
.CdmAuthority
;
20 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
22 public class GrantedAuthorityLabelTextProvider
{
24 public static final Logger logger
= Logger
.getLogger(CdmAuthority
.class);
27 public static String
getText(GrantedAuthority grantedAuthority
){
28 String labelText
= grantedAuthority
.getAuthority();
30 CdmAuthority cdmAuthority
= CdmAuthority
.fromGrantedAuthority(grantedAuthority
);
31 String targetLabelText
= getTargetText(cdmAuthority
);
32 if(targetLabelText
.length() > 0){
33 labelText
= grantedAuthority
.getAuthority().replace(cdmAuthority
.getTargetUUID().toString(), targetLabelText
);
35 } catch (Exception e
) {
36 /* will in most cases catch a ParsingException
39 if(!e
.getClass().getSimpleName().equals("ParsingException")){
42 // in case it is a Role
43 labelText
= grantedAuthority
.getAuthority();
48 public static String
getTargetText(GrantedAuthority grantedAuthority
){
49 if(grantedAuthority
instanceof CdmAuthority
){
50 return getCdmAuthorityTargetText((CdmAuthority
)grantedAuthority
);
56 private static String
getCdmAuthorityTargetText(CdmAuthority cdmAuthority
) {
58 UUID uuid
= cdmAuthority
.getTargetUUID();
59 String targetText
= "";
62 targetText
= uuid
.toString();
63 if(cdmAuthority
.getPermissionClass() != null){
65 switch(cdmAuthority
.getPermissionClass()) {
67 targetText
= CdmStore
.getService(IUserService
.class).load(uuid
).getUsername();
70 targetText
= CdmStore
.getService(IDescriptionService
.class).load(uuid
).getTitleCache();
72 case DESCRIPTIONELEMENTBASE
:
73 targetText
= CdmStore
.getService(IDescriptionService
.class).loadDescriptionElement(uuid
, null).toString();
76 targetText
= CdmStore
.getService(ITaxonService
.class).load(uuid
).getTitleCache();
79 // makes not much sense here
82 TaxonNode node
= CdmStore
.getService(ITaxonNodeService
.class).load(uuid
);
83 if(node
.getClassification() != null){
84 targetText
= node
.getClassification().getTitleCache() + " : ";
86 if(node
.getTaxon() != null){
87 targetText
+= node
.getTaxon().getTitleCache();
89 uuid
= node
.getClassification().getUuid();
90 targetText
= CdmStore
.getService(IClassificationService
.class).load(uuid
).getTitleCache();
94 targetText
= CdmStore
.getService(IClassificationService
.class).load(uuid
).getTitleCache();
97 targetText
= CdmStore
.getService(IReferenceService
.class).load(uuid
).getTitleCache();
100 targetText
= CdmStore
.getService(INameService
.class).load(uuid
).getTitleCache();
102 case TEAMORPERSONBASE
:
103 targetText
= CdmStore
.getService(IAgentService
.class).load(uuid
).getTitleCache();
106 targetText
= CdmStore
.getService(IRegistrationService
.class).load(uuid
).getIdentifier();
108 case SPECIMENOROBSERVATIONBASE
:
109 targetText
= CdmStore
.getService(IOccurrenceService
.class).load(uuid
).getTitleCache();
115 } catch (NullPointerException e
){
116 logger
.warn("Either no service found for " + cdmAuthority
.getPermissionClass() + " or entitiy not found" , e
);