Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' into 'master'
Browse files Browse the repository at this point in the history
Build REST APIs for RepositoryQueryService

See merge request !19
  • Loading branch information
srinivastuta committed Nov 14, 2017
2 parents 3a021e3 + 0cd96d3 commit 4e7c3e1
Show file tree
Hide file tree
Showing 33 changed files with 1,177 additions and 99 deletions.
45 changes: 0 additions & 45 deletions jaffa-core/source/java/org/jaffa/loader/CoreLoaderConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,16 @@
package org.jaffa.loader;

import org.jaffa.components.navigation.NavCache;
import org.jaffa.components.navigation.domain.GlobalMenu;
import org.jaffa.loader.config.ApplicationRulesManager;
import org.jaffa.loader.navigation.NavigationManager;
import org.jaffa.loader.policy.BusinessFunctionManager;
import org.jaffa.loader.policy.RoleManager;
import org.jaffa.security.CheckPolicy;
import org.jaffa.security.PolicyCache;
import org.jaffa.security.businessfunctionsdomain.BusinessFunction;
import org.jaffa.security.securityrolesdomain.Role;
import org.jaffa.session.ContextManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
* Contains all the Beans related to the BusinessFunctionManager and RoleManager Loader Architecture for the Jaffa-SOA
*/
Expand Down Expand Up @@ -92,7 +87,6 @@ public ResourceLoader<RoleManager> roleManagerXmlLoader() {
public RoleManager roleManager() {
RoleManager roleManager = new RoleManager();
PolicyCache.setRoleManager(roleManager);
roleManager.setRoleRepository(roleRepository());
return roleManager;
}

Expand All @@ -113,7 +107,6 @@ public ResourceLoader<BusinessFunctionManager> businessFunctionManagerXmlLoader(
public BusinessFunctionManager businessFunctionManager() {
BusinessFunctionManager businessFunctionManager = new BusinessFunctionManager();
CheckPolicy.setBusinessFunctionManager(businessFunctionManager);
businessFunctionManager.setBusinessFunctionRepository(businessFunctionRepository());
return businessFunctionManager;
}

Expand All @@ -134,7 +127,6 @@ public ResourceLoader<NavigationManager> navigationManagerXmlLoader() {
public NavigationManager navigationManager() {
NavigationManager navigationManager = new NavigationManager();
NavCache.setNavigationManager(navigationManager);
navigationManager.setNavigationRepository(navigationRepository());
return navigationManager;
}

Expand All @@ -155,45 +147,8 @@ public ResourceLoader<ApplicationRulesManager> applicationRulesManagerProperties
public ApplicationRulesManager applicationRulesManager() {
ApplicationRulesManager applicationRulesManager = new ApplicationRulesManager();
ContextManager.setApplicationRulesManager(applicationRulesManager);
applicationRulesManager.setApplicationRulesRepository(applicationRulesRepository());
return applicationRulesManager;
}

/**
* roleRepository() - Returns a repository of Roles
* @return MapRepository<Role>
*/
private MapRepository<Role> roleRepository() {
MapRepository<Role> roleMapRepository = new MapRepository<>();
return roleMapRepository;
}

/**
* businessFunctionRepository - Returns a repository of BusinessFunctions
* @return - MapRepository<BusinessFunction>
*/
private MapRepository<BusinessFunction> businessFunctionRepository() {
MapRepository<BusinessFunction> businessFunctionMapRepository = new MapRepository<>();
return businessFunctionMapRepository;
}

/**
* navigationRepository - Returns a repository of GlobalMenu
* @return MapRepository<GlobalMenu>
*/
private MapRepository<GlobalMenu> navigationRepository() {
MapRepository<GlobalMenu> navCacheMapRepository = new MapRepository<>();
return navCacheMapRepository;
}

/**
* applicationRulesRepository - Returns a repository of application rules
* @return MapRepository<Properties>
*/
private MapRepository<Properties> applicationRulesRepository() {
MapRepository<Properties> applicationRulesRepository = new MapRepository<>();
return applicationRulesRepository;
}

}

14 changes: 14 additions & 0 deletions jaffa-core/source/java/org/jaffa/loader/IManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@

import javax.xml.bind.JAXBException;
import java.io.IOException;
import java.util.Set;

/**
* Interface for xml managers to registerXml and getResourceFileName.
Expand All @@ -76,4 +77,17 @@ public interface IManager {
* @return xml config file name
*/
String getResourceFileName();

/**
* Gets a list of all of the repository names managed by the application
* @return A list of managed repositories
*/
Set getRepositoryNames();

/**
* Gets the data within a specified repository
* @param name The repository to retrieve data from
* @return The repository data, or null if the repository does not exist
*/
IRepository getRepositoryByName(String name);
}
10 changes: 10 additions & 0 deletions jaffa-core/source/java/org/jaffa/loader/IRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,14 @@ public interface IRepository<T> {
* @return
*/
public T queryByVariation(String id, String variation);

/**
* Returns the Name of the repository
*/
public String getName();

/**
* Returns the repository map
*/
public Map getRepositoryMap();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.jaffa.loader;

import java.util.HashMap;
import java.util.Map;

/**
* ManagerRepositoryService - Singleton service to collect all repository managers in the application
*/
public class ManagerRepositoryService {

/**
* The singleton ManagerRepositoryService instance
*/
private static volatile ManagerRepositoryService managerRepositoryService = null;

/**
* HashMap to store repositories. The key is the repository name, and the value is
* the repository instance
*/
private Map<String, IManager> managerMap = new HashMap<>();

/**
* Default constructor for the ManagerRepositoryService class
*/
private ManagerRepositoryService() {
}

/**
* Public method to retrieve the ManagerRepositoryService instance
* @return The ManagerRepositoryService instance
*/
public static ManagerRepositoryService getInstance() {
if (managerRepositoryService == null) {
synchronized (ManagerRepositoryService.class) {
if (managerRepositoryService == null) {
managerRepositoryService = new ManagerRepositoryService();
}
}
}
return managerRepositoryService;
}

/**
* Add managers to the ManagerRepositoryService HashMap
* @param className The class name of the manager to be added
* @param manager The instance of the manager to be added
*/
public void add(String className, IManager manager) {
managerMap.put(className, manager);
}

/**
* Retrieve the manager HashMap
* @return The manager HashMap
*/
public Map<String, IManager> getManagerMap() {
return managerMap;
}

}
29 changes: 29 additions & 0 deletions jaffa-core/source/java/org/jaffa/loader/MapRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ public class MapRepository<T> implements IRepository<T> {
*/
private Map<String, TreeSet<ContextKey>> contextKeyCache = new HashMap<>();

/**
* The name of the repository
*/
private String repositoryName;

/**
* Create a MapRepository object and set its name value
* @param name
*/
public MapRepository(String name) {
repositoryName = name;
}

/**
* {@inheritDoc}
Expand Down Expand Up @@ -136,6 +148,23 @@ public synchronized T queryByVariation(String id, String variation) {
return null;
}

/**
* Retrieve the name of the repository
* @return The name of the repository
*/
@Override
public String getName() {
return repositoryName;
}

/**
* Retrieve the full Repository Map
* @return the Repository Map
*/
public Map getRepositoryMap() {
return repositoryMap;
}

/**
* {@inheritDoc}
*/
Expand Down
16 changes: 14 additions & 2 deletions jaffa-core/source/java/org/jaffa/loader/ResourceLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,20 @@
*/
public class ResourceLoader<T extends IManager> {

/**
* Create a ContextHelper logger
*/
private static Logger logger = Logger.getLogger(ContextHelper.class);

private T manager ;
/**
* Create a ManagerRepositoryService singleton to store managers
*/
private ManagerRepositoryService managerRepositoryService = ManagerRepositoryService.getInstance();

/**
* Create a generic manager
*/
private T manager;

/**
* gets the Manager from the ResourceLoader
Expand Down Expand Up @@ -98,7 +109,8 @@ public void loadXmls() {
try {
manager.registerResource(resource, ContextHelper.getContextSalience(resource.getURI().toString()),
ContextHelper.getVariationSalience(resource.getURI().toString()));
}catch(Exception e){
managerRepositoryService.add(manager.getClass().getSimpleName(), manager);
} catch (Exception e) {
logger.error("Exception occurred while registering XML " + resource.getURI().toString() + " exception " + e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@
import org.jaffa.presentation.portlet.component.ComponentDefinitionException;
import org.jaffa.presentation.portlet.component.componentdomain.Component;
import org.jaffa.presentation.portlet.component.componentdomain.Components;
import org.jaffa.security.VariationContext;
import org.jaffa.util.JAXBHelper;
import org.springframework.core.io.Resource;
import org.xml.sax.SAXException;

import javax.xml.bind.JAXBException;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Set;

/**
* A class that manages various kinds of component object specifications, as
Expand All @@ -86,7 +87,18 @@ public class ComponentManager implements IManager {

/** The ComponentDefinition repository. The key is the component name of
* the value in the ComponentDefinition object. */
private IRepository<ComponentDefinition> componentRepository = new MapRepository<>();
private IRepository<ComponentDefinition> componentRepository = new MapRepository<>("ComponentDefinition");

/**
* The list of repositories managed by this class
*/
private HashMap managedRepositories = new HashMap<String, IRepository>() {
{
put(componentRepository.getName(), componentRepository);
}

};


/**
* Unmarshall the contents of the configuration to create and register
Expand Down Expand Up @@ -164,6 +176,25 @@ public String getResourceFileName() {
return configurationFile;
}

/**
* getRepositoryNames - Retrieve a String list of all the IRepositories managed by this IManager
* @return A list of repository names managed by this manager
*/
@Override
public Set getRepositoryNames() {
return managedRepositories.keySet();
}

/**
* Retrieve an IRepository managed by this IManager via its String name
* @param name The name of the repository to be retrieved
* @return The retrieved repository, or empty if no matching repository was found.
*/
@Override
public IRepository<?> getRepositoryByName(String name) {
return (IRepository<?>) managedRepositories.get(name);
}

public IRepository<ComponentDefinition> getComponentRepository() {
return componentRepository;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@

import javax.xml.bind.JAXBException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/**
* ApplicationRulesManager - ApplicationManager is the managing class for all application rules as defined by the
Expand All @@ -71,7 +73,18 @@ public class ApplicationRulesManager implements IManager {
/**
* Instantiates a new Properties repository
*/
private IRepository<Properties> applicationRulesRepository = new MapRepository<>();
private IRepository<Properties> applicationRulesRepository = new MapRepository<>("Properties");


/**
* The list of repositories managed by this class
*/
private HashMap managedRepositories = new HashMap<String, IRepository>() {
{
put(applicationRulesRepository.getName(), applicationRulesRepository);
}

};

/**
* Provides the pattern to search for ApplicationRules
Expand Down Expand Up @@ -107,6 +120,25 @@ public IRepository<Properties> getApplicationRulesRepository() {
return applicationRulesRepository;
}

/**
* getRepositoryNames - Retrieve a String list of all the IRepositories managed by this IManager
* @return A list of repository names managed by this manager
*/
@Override
public Set getRepositoryNames() {
return managedRepositories.keySet();
}

/**
* Retrieve an IRepository managed by this IManager via its String name
* @param name The name of the repository to be retrieved
* @return The retrieved repository, or empty if no matching repository was found.
*/
@Override
public IRepository<?> getRepositoryByName(String name) {
return (IRepository<?>) managedRepositories.get(name);
}

/**
* setApplicationRulesRepository - Sets the application rules repository
*
Expand Down
Loading

0 comments on commit 4e7c3e1

Please sign in to comment.