forked from sakaiproject/sakai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LSNBLDR-727 Made LB-CSS folder hidden by default. (sakaiproject#3421)
In SimplePageBean class when LB-CSS folder is added in resources, the PROP_HIDDEN_WITH_ACCESSIBLE_CONTENT property is set to true for the folder. For the existing LB-CSS folders in database a new job(class) - LBCSSFolderHideJob is added. When this job is run , it will hide all the visible LB-CSS folders from access users.
- Loading branch information
Showing
3 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
...ent-shared/src/java/org/sakaiproject/component/app/scheduler/jobs/LBCSSFolderHideJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package org.sakaiproject.component.app.scheduler.jobs; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.quartz.DisallowConcurrentExecution; | ||
import org.quartz.Job; | ||
import org.quartz.JobExecutionContext; | ||
import org.quartz.JobExecutionException; | ||
import org.sakaiproject.content.api.ContentCollectionEdit; | ||
import org.sakaiproject.content.api.ContentHostingService; | ||
import org.sakaiproject.db.api.SqlService; | ||
import org.sakaiproject.entity.api.ResourceProperties; | ||
import org.sakaiproject.entity.api.ResourcePropertiesEdit; | ||
import org.sakaiproject.event.api.UsageSessionService; | ||
import org.sakaiproject.exception.*; | ||
import org.sakaiproject.tool.api.Session; | ||
import org.sakaiproject.tool.api.SessionManager; | ||
|
||
import java.sql.Connection; | ||
import java.sql.PreparedStatement; | ||
import java.util.List; | ||
|
||
/** | ||
* Job to make LB-CSS folder hidden but contents accessible. | ||
* LB-CSS folder should not be visible to access user, this job will hide all existing non-hidden LB-CSS folder. | ||
* @author neelam | ||
* | ||
*/ | ||
@DisallowConcurrentExecution | ||
public class LBCSSFolderHideJob implements Job { | ||
|
||
private SqlService sqlService; | ||
private SessionManager sessionManager; | ||
|
||
private static final Log LOG = LogFactory.getLog(LBCSSFolderHideJob.class); | ||
|
||
private ContentHostingService contentHostingService; | ||
|
||
public void setSqlService(SqlService sqlService) { | ||
this.sqlService = sqlService; | ||
} | ||
|
||
public void setSessionManager(SessionManager sessionManager) { | ||
this.sessionManager = sessionManager; | ||
} | ||
|
||
public void setContentHostingService(ContentHostingService contentHostingService) { | ||
this.contentHostingService = contentHostingService; | ||
} | ||
|
||
public void execute(JobExecutionContext context) throws JobExecutionException { | ||
ContentCollectionEdit contentCollectionEdit; | ||
ResourcePropertiesEdit resourceProperties; | ||
Session session = null; | ||
//sql to get collection ids for all LB-CSS folder | ||
String sql = "SELECT COLLECTION_ID FROM CONTENT_COLLECTION WHERE COLLECTION_ID LIKE \"%LB-CSS/\" "; | ||
LOG.debug("SQL to get collection Id for LB-CSS folder " + sql); | ||
int totalFolders = 0 , foldersUpdated = 0, foldersAlreadySet = 0; | ||
//set current user in session | ||
try { | ||
session = sessionManager.getCurrentSession(); | ||
session.setUserEid("admin"); | ||
session.setUserId("admin"); | ||
List<String> collection_ids = sqlService.dbRead(sql); | ||
totalFolders = collection_ids.size(); | ||
LOG.info("Number of LB-CSS folders found is " + totalFolders); | ||
for (String id : collection_ids) { | ||
try { | ||
contentCollectionEdit = contentHostingService.editCollection(id); | ||
resourceProperties = contentCollectionEdit.getPropertiesEdit(); | ||
//if LB-CSS folder is not hidden, hide it | ||
if (!("true".equals(resourceProperties.getProperty(ResourceProperties.PROP_HIDDEN_WITH_ACCESSIBLE_CONTENT)))) { | ||
resourceProperties.addProperty(ResourceProperties.PROP_HIDDEN_WITH_ACCESSIBLE_CONTENT, "true"); | ||
foldersUpdated++; | ||
LOG.info("Hiding the collection" + id + " from access user "); | ||
contentHostingService.commitCollection(contentCollectionEdit); | ||
} | ||
else { | ||
foldersAlreadySet++; | ||
contentHostingService.cancelCollection(contentCollectionEdit); | ||
LOG.info("The collection " + id +" has already been hidden "); | ||
} | ||
} catch (SakaiException exception) { | ||
LOG.error("Failed to update the LB-CSS folder: " + id, exception); | ||
} | ||
} | ||
} | ||
finally { | ||
LOG.info("Summary of LBCSSFolderHideJob , Total LB-CSS folders: " + totalFolders + " Updated: " + | ||
foldersUpdated + " Collection already hidden: " + foldersAlreadySet); | ||
session.invalidate(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters