Skip to content

Commit

Permalink
Migrating #8688 changes to release-3.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jgambarios committed Mar 8, 2016
1 parent 8cb68ea commit 2521e19
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 8 deletions.
9 changes: 9 additions & 0 deletions src/com/dotmarketing/cache/ContentTypeCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,13 @@ public abstract List<ContainerStructure> getContainerStructures(

public abstract void removeContainerStructures(String containerIdentifier,
String containerInode);

public abstract String getStructuresByTypeGroup();

public abstract List<Structure> getStructuresByType(int structureType);

public abstract void addStructuresByType(List<Structure> structures, int structureType);

public abstract void removeStructuresByType(int structureType);

}
36 changes: 34 additions & 2 deletions src/com/dotmarketing/cache/ContentTypeCacheImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ public class ContentTypeCacheImpl extends ContentTypeCache {
private DotCacheAdministrator cache;
private final String primaryGroup = "StructureCache";
private final String containerStructureGroup = "ContainerStructureCache";
private final String structuresByTypeGroup = "StructuresByTypeCache";
// region's name for the cache
private final String[] groups = { primaryGroup, containerStructureGroup };
private final String[] groups = { primaryGroup, containerStructureGroup, structuresByTypeGroup };

public ContentTypeCacheImpl() {
cache = CacheLocator.getCacheAdministrator();
Expand All @@ -42,6 +43,7 @@ public void add(Structure st){
cache.put(primaryGroup + velocityVarName, st, primaryGroup);
if (UtilMethods.isSet(velocityVarName))
cache.put(primaryGroup + velocityVarName.toLowerCase(), st, primaryGroup);
removeStructuresByType(st.getStructureType());
}

/*public static Structure getStructureByInode(long inode){
Expand Down Expand Up @@ -179,6 +181,7 @@ public void remove(Structure st) {
cache.remove(primaryGroup + inode,primaryGroup);
cache.remove(primaryGroup + structureName,primaryGroup);
clearURLMasterPattern();
removeStructuresByType(st.getStructureType());
}

public String getURLMasterPattern() throws DotCacheException {
Expand Down Expand Up @@ -217,10 +220,39 @@ public void removeContainerStructures(String containerIdentifier, String contain
cache.remove(containerStructureGroup + containerIdentifier + containerInode, containerStructureGroup);
}

public String getStructuresByTypeGroup() {
return structuresByTypeGroup;
}

@SuppressWarnings("unchecked")
public List<Structure> getStructuresByType(int structureType) {
List<Structure> structuresByType = null;

try{
structuresByType = (List<Structure>) cache.get(structuresByTypeGroup + structureType, structuresByTypeGroup);
return structuresByType;

} catch (DotCacheException e) {
Logger.debug(ContentTypeCacheImpl.class, "Cache Entry not found: ", e);
return null;
}
}

public void addStructuresByType(List<Structure> structures, int structureType){
cache.put(structuresByTypeGroup + structureType, structures, structuresByTypeGroup);
}

public void removeStructuresByType(int structureType) {
cache.remove(structuresByTypeGroup + structureType, structuresByTypeGroup);
}

public void clearCache(){
//clear the cache
cache.flushGroup(primaryGroup);
for (String cacheGroup : getGroups()) {
cache.flushGroup(cacheGroup);
}
}

public String[] getGroups() {
return groups;
}
Expand Down
5 changes: 2 additions & 3 deletions src/com/dotmarketing/portlets/form/business/FormAPIImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,13 @@ public void createBaseFormFields(Structure structure) throws DotDataException,Do
}

public List<Structure> findAll(User user, boolean respectFrontEndPermissions) throws DotDataException, DotSecurityException {
List<Structure> sts = StructureFactory.getStructures();
List<Structure> sts = StructureFactory.getAllStructuresByType(Structure.STRUCTURE_TYPE_FORM);
List<Structure> forms = new ArrayList<Structure>();
for (Structure structure : sts) {
if(structure.getStructureType() == Structure.STRUCTURE_TYPE_FORM){
if (perAPI.doesUserHavePermission(structure, PermissionAPI.PERMISSION_READ, user, respectFrontEndPermissions)) {
forms.add(structure);
}
}
forms = perAPI.filterCollection(forms, PermissionAPI.PERMISSION_READ, respectFrontEndPermissions, user);
return forms;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,43 @@ public static List<Structure> getStructures()
return getStructures(orderBy,limit);
}

/**
* Returns a list of Content Type according to a specific Type
* These could be:
* 1. Contents.
* 2. Widgets.
* 3. Forms.
* 4. File Assets.
* 5. Pages.
* 6. Personas
* @param structureType: Integer type, according to valid content types specified in Structure.java class
* @return structures: List of Structures
*/
public static List<Structure> getAllStructuresByType(int structureType)
{
List<Structure> structures = new ArrayList<Structure>();
if(UtilMethods.isSet(structureType) && structureType <= 0){
//Invalid Type. Return empty list
return structures;
}

structures = CacheLocator.getContentTypeCache().getStructuresByType(structureType);

if(structures == null){
String condition = "structuretype = " + structureType;
String orderBy = "name";
String direction = "asc";
int limit = -1;
structures = InodeFactory.getInodesOfClassByConditionAndOrderBy(Structure.class,condition,orderBy,limit,0,direction);
}

if(structures != null){
CacheLocator.getContentTypeCache().addStructuresByType(structures, structureType);
}

return structures;
}

public static List<Structure> getStructuresByUser(User user, String condition, String orderBy,int limit,int offset,String direction) {

PaginatedArrayList<Structure> structures = new PaginatedArrayList<Structure>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@ public void createBaseWidgetFields(Structure structure) throws DotDataException,
}

public List<Structure> findAll(User user, boolean respectFrontEndPermissions) throws DotDataException, DotSecurityException {
List<Structure> sts = StructureFactory.getStructures();
List<Structure> sts = StructureFactory.getAllStructuresByType(Structure.STRUCTURE_TYPE_WIDGET);
List<Structure> wids = new ArrayList<Structure>();
for (Structure structure : sts) {
if(structure.getStructureType() == Structure.STRUCTURE_TYPE_WIDGET){
if (!structure.isSystem() && perAPI.doesUserHavePermission(structure, PermissionAPI.PERMISSION_READ, user, respectFrontEndPermissions)) {
wids.add(structure);
}
}
wids = perAPI.filterCollection(wids, PermissionAPI.PERMISSION_READ, respectFrontEndPermissions, user);
return wids;
}
}

0 comments on commit 2521e19

Please sign in to comment.