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
.IClassificationService
;
9 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
10 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
11 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
12 import eu
.etaxonomy
.cdm
.api
.service
.IUserService
;
13 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
14 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.permission
.CdmAuthority
;
16 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.permission
.CdmPermissionClass
;
17 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
19 public class GrantedAuthorityLabelTextProvider
{
21 public static final Logger logger
= Logger
.getLogger(CdmAuthority
.class);
24 public static String
getText(GrantedAuthority grantedAuthority
){
25 String labelText
= grantedAuthority
.getAuthority();
27 CdmAuthority cdmAuthority
= CdmAuthority
.fromGrantedAuthority(grantedAuthority
);
28 String targetLabelText
= getTargetText(cdmAuthority
);
29 if(targetLabelText
.length() > 0){
30 labelText
= grantedAuthority
.getAuthority().replace(cdmAuthority
.getTargetUUID().toString(), targetLabelText
);
32 } catch (Exception e
) {
33 /* will in most cases catch a ParsingException
36 if(!e
.getClass().getSimpleName().equals("ParsingException")){
39 // in case it is a Role
40 labelText
= grantedAuthority
.getAuthority();
45 public static String
getTargetText(GrantedAuthority grantedAuthority
){
46 if(grantedAuthority
instanceof CdmAuthority
){
47 return getCdmAuthorityTargetText((CdmAuthority
)grantedAuthority
);
53 private static String
getCdmAuthorityTargetText(CdmAuthority cdmAuthority
) {
55 UUID uuid
= cdmAuthority
.getTargetUUID();
56 String targetText
= "";
59 targetText
= uuid
.toString();
60 if(cdmAuthority
.getPermissionClass() != null){
62 switch(cdmAuthority
.getPermissionClass()) {
64 targetText
= CdmStore
.getService(IUserService
.class).load(uuid
).getUsername();
67 targetText
= CdmStore
.getService(IDescriptionService
.class).load(uuid
).getTitleCache();
69 case DESCRIPTIONELEMENTBASE
:
70 targetText
= CdmStore
.getService(IDescriptionService
.class).loadDescriptionElement(uuid
, null).toString();
73 targetText
= CdmStore
.getService(ITaxonService
.class).load(uuid
).getTitleCache();
76 // makes not much sense here
79 TaxonNode node
= CdmStore
.getService(ITaxonNodeService
.class).load(uuid
);
80 if(node
.getClassification() != null){
81 targetText
= node
.getClassification().getTitleCache() + " : ";
83 if(node
.getTaxon() != null){
84 targetText
+= node
.getTaxon().getTitleCache();
88 targetText
= CdmStore
.getService(IClassificationService
.class).load(uuid
).getTitleCache();
91 } catch (NullPointerException e
){
92 logger
.warn("Either no service found for " + cdmAuthority
.getPermissionClass() + " or entitiy not found" , e
);