2 * Copyright (C) 2014 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.service
;
11 import java
.util
.List
;
12 import java
.util
.UUID
;
14 import org
.springframework
.stereotype
.Component
;
16 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationState
;
17 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
18 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySession
;
25 public class CachedCommonServiceImpl
implements ICachedCommonService
{
27 private static boolean cacheEnabled
= true;
29 public static boolean isCacheEnabled() {
33 public static void setCacheEnabled(boolean cacheEnabled
) {
34 CachedCommonServiceImpl
.cacheEnabled
= cacheEnabled
;
38 public CdmBase
find(Class
<?
extends CdmBase
> clazz
, int id
) {
39 CdmBase cdmEntity
= CdmApplicationState
.getCurrentAppConfig().getCommonService().find(clazz
, id
, getPropertyPaths(clazz
));
40 if(cdmEntity
== null) {
41 throw new NullPointerException("CDM Entity of type " + clazz
.getName() + " with id " + id
+ " is null.");
46 private List
<String
> getPropertyPaths(Object obj
) {
47 List
<String
> propertyPaths
= null;
48 ICdmEntitySession cdmEntitySession
=
49 CdmApplicationState
.getCurrentAppConfig().getCdmEntitySessionManager().getActiveSession();
50 if(cdmEntitySession
!= null) {
51 propertyPaths
= cdmEntitySession
.getPropertyPaths(obj
);
57 public Object
initializeCollection(UUID ownerUuid
, String fieldName
) {
58 return CdmApplicationState
.getCurrentAppConfig().getCommonService().initializeCollection(ownerUuid
, fieldName
, getPropertyPaths(fieldName
));
62 public boolean isEmpty(UUID ownerUuid
, String fieldName
) {
63 return CdmApplicationState
.getCurrentAppConfig().getCommonService().isEmpty(ownerUuid
, fieldName
);
67 public int size(UUID ownerUuid
, String fieldName
) {
68 return CdmApplicationState
.getCurrentAppConfig().getCommonService().size(ownerUuid
, fieldName
);
72 public boolean contains(UUID ownerUuid
, String fieldName
, Object element
) {
73 return CdmApplicationState
.getCurrentAppConfig().getCommonService().contains(ownerUuid
, fieldName
, element
);
77 public boolean containsKey(UUID ownerUuid
, String fieldName
, Object key
) {
78 return CdmApplicationState
.getCurrentAppConfig().getCommonService().containsKey(ownerUuid
, fieldName
, key
);
82 public boolean containsValue(UUID ownerUuid
, String fieldName
, Object element
) {
83 return CdmApplicationState
.getCurrentAppConfig().getCommonService().containsValue(ownerUuid
, fieldName
, element
);