import static org.onap.so.aai.simulator.utils.Constants.PROJECT_CACHE;
import static org.onap.so.aai.simulator.utils.Constants.SERVICE_RESOURCE_TYPE;
import java.util.Optional;
-import java.util.concurrent.ConcurrentHashMap;
import org.onap.aai.domain.yang.Project;
import org.onap.aai.domain.yang.Relationship;
import org.onap.aai.domain.yang.RelationshipList;
*
*/
@Service
-public class ProjectCacheServiceProviderImpl implements ProjectCacheServiceProvider {
+public class ProjectCacheServiceProviderImpl extends AbstractCacheServiceProvider
+ implements ProjectCacheServiceProvider {
private static final String RELATIONSHIPS_LABEL = "org.onap.relationships.inventory.Uses";
private static final Logger LOGGER = LoggerFactory.getLogger(ProjectCacheServiceProviderImpl.class);
- public final CacheManager cacheManager;
@Autowired
public ProjectCacheServiceProviderImpl(final CacheManager cacheManager) {
- this.cacheManager = cacheManager;
+ super(cacheManager);
}
@Override
public void putProject(final String projectName, final Project project) {
LOGGER.info("Adding project: {} with name to cache", project, projectName);
- final Cache cache = cacheManager.getCache(PROJECT_CACHE);
+ final Cache cache = getCache(PROJECT_CACHE);
cache.put(projectName, project);
}
@Override
public Optional<Project> getProject(final String projectName) {
LOGGER.info("getting project from cache using key: {}", projectName);
- final Cache cache = cacheManager.getCache(PROJECT_CACHE);
+ final Cache cache = getCache(PROJECT_CACHE);
final Project value = cache.get(projectName, Project.class);
if (value != null) {
return Optional.of(value);
@Override
public boolean putProjectRelationShip(final String projectName, final Relationship relationship) {
- final Cache cache = cacheManager.getCache(PROJECT_CACHE);
+ final Cache cache = getCache(PROJECT_CACHE);
final Project value = cache.get(projectName, Project.class);
if (value != null) {
RelationshipList relationshipList = value.getRelationshipList();
return relationshipList.getRelationship().add(relationship);
}
+ LOGGER.error("Project not found in cache for {}", projectName);
return false;
}
@Override
public void clearAll() {
- final Cache cache = cacheManager.getCache(PROJECT_CACHE);
- final ConcurrentHashMap<?, ?> nativeCache = (ConcurrentHashMap<?, ?>) cache.getNativeCache();
- LOGGER.info("Clear all entries from cahce: {}", cache.getName());
- nativeCache.clear();
+ clearCahce(PROJECT_CACHE);
}
}