Skip to content

Commit

Permalink
#10 merged with master
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Tesser committed Apr 11, 2012
2 parents 1f7b0d9 + fa8bbc8 commit 17457f8
Show file tree
Hide file tree
Showing 15 changed files with 1,211 additions and 1,128 deletions.
1,848 changes: 939 additions & 909 deletions build.xml

Large diffs are not rendered by default.

20 changes: 6 additions & 14 deletions dotCMS/WEB-INF/web.xml
Expand Up @@ -561,18 +561,9 @@
<!-- Don't ever delete the following comment tags, it will break the plugin system -->
<!-- BEGIN SERVLETS -->
<!-- END SERVLETS -->
<!-- TEST FRAMEWORK SERVLETS -->
<!--
<servlet>
<servlet-name>ServletRedirector</servlet-name>
<servlet-class>org.apache.cactus.server.ServletTestRedirector</servlet-class>
</servlet>
<servlet>
<servlet-name>ServletTestRunner</servlet-name>
<servlet-class>org.apache.cactus.server.runner.ServletTestRunner</servlet-class>
</servlet>
-->
<!--

<!-- TEST FRAMEWORK SERVLETS
<servlet>
<servlet-name>ServletTestRunner</servlet-name>
<servlet-class>com.dotmarketing.servlets.test.ServletTestRunner</servlet-class>
Expand All @@ -582,8 +573,9 @@
<servlet-name>ServletTestRunner</servlet-name>
<url-pattern>/servlet/test</url-pattern>
</servlet-mapping>
-->
<!-- END OF TEST FRAMEWORK SERVLETS -->
END OF TEST FRAMEWORK SERVLETS -->

<!-- DOTCMS SERVLET-MAPPINGS -->
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
Expand Down
3 changes: 2 additions & 1 deletion dotCMS/html/portlet/ext/workflows/schemes/workflow_js.jsp
Expand Up @@ -11,6 +11,7 @@ dojo.require("dojo.dnd.Source");
dojo.require("dojox.layout.ContentPane");
dojo.require("dijit.TooltipDialog");
dojo.require("dojox.data.QueryReadStore");
dojo.require("dojo.NodeList-manipulate");
// refresh page when the hash has changed
dojo.subscribe("/dojo/hashchange", this, function(hash){mainAdmin.refresh();});

Expand Down Expand Up @@ -646,7 +647,7 @@ dojo.declare("dotcms.dijit.workflows.ActionAdmin", null, {
dojo.create("td", { innerHTML: this.whoCanUse[i].name + what}, tr);

}
dojo.byId("whoCanUse").value = x;
dojo.query('#whoCanUse').val(x);

},
doChange: function(){
Expand Down
Expand Up @@ -20,8 +20,10 @@
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.CustomScoreQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.QueryStringQueryBuilder;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.internal.InternalSearchHits;
Expand Down Expand Up @@ -85,7 +87,7 @@ public ESContentFactoryImpl() {
client = new ESClient();

}

@Override
protected Object loadField(String inode, String fieldContentlet) throws DotDataException {
String sql="SELECT "+fieldContentlet+" FROM contentlet WHERE inode=?";
Expand Down Expand Up @@ -568,7 +570,7 @@ protected void delete(List<Contentlet> contentlets) throws DotDataException {
//Checking contentlet exists inode > 0
if(InodeUtils.isSet(c.getInode())){
APILocator.getPermissionAPI().removePermissions(c);

ContentletVersionInfo verInfo=APILocator.getVersionableAPI().getContentletVersionInfo(c.getIdentifier(), c.getLanguageId());
if(verInfo!=null && UtilMethods.isSet(verInfo.getIdentifier())) {
if(UtilMethods.isSet(verInfo.getLiveInode()) && verInfo.getLiveInode().equals(c.getInode()))
Expand All @@ -580,7 +582,7 @@ protected void delete(List<Contentlet> contentlets) throws DotDataException {
if(verInfo.getWorkingInode().equals(c.getInode()))
APILocator.getVersionableAPI().deleteContentletVersionInfo(c.getIdentifier(), c.getLanguageId());
}

HibernateUtil.delete(c);
//db.setSQL("delete from inode where identifier like '6050'");
//try{
Expand Down Expand Up @@ -630,9 +632,8 @@ protected int deleteOldContent(Date deleteFrom, int offset) throws DotDataExcept
List<Map<String, String>> result = dc.loadResults();
int before = Integer.parseInt(result.get(0).get("count"));

String deleteContentletSQL = "delete from contentlet where mod_date < ? and inode not in " +
" ((select working_inode from contentlet_version_info) " +
" union (select live_inode from contentlet_version_info)) ";
String deleteContentletSQL = "delete from contentlet where identifier<>'SYSTEM_HOST' and mod_date < ? " +
"and not exists (select * from contentlet_version_info where working_inode=contentlet.inode or live_inode=contentlet.inode)";
dc.setSQL(deleteContentletSQL);
dc.addParam(date);
dc.loadResult();
Expand All @@ -642,7 +643,13 @@ protected int deleteOldContent(Date deleteFrom, int offset) throws DotDataExcept
dc.setSQL(countSQL);
result = dc.loadResults();
int after = Integer.parseInt(result.get(0).get("count"));
return before - after;

int deleted=before - after;

if(deleted>0)
cc.clearCache();

return deleted;
}

@Override
Expand Down Expand Up @@ -759,7 +766,7 @@ protected List<Contentlet> findAllUserVersions(Identifier identifier) throws Dot
protected List<Contentlet> findAllVersions(Identifier identifier) throws DotDataException, DotStateException, DotSecurityException {
if(!InodeUtils.isSet(identifier.getInode()))
return new ArrayList<Contentlet>();

DotConnect dc = new DotConnect();
dc.setSQL("SELECT inode FROM contentlet WHERE identifier=? order by mod_date desc");
dc.addObject(identifier.getId());
Expand Down Expand Up @@ -968,7 +975,7 @@ protected List<Contentlet> findContentletsByIdentifier(String identifier, Boolea
.append("from contentlet, inode contentlet_1_, contentlet_version_info contentvi ")
.append("where contentlet_1_.type = 'contentlet' and contentlet.inode = contentlet_1_.inode and ")
.append("contentvi.identifier=contentlet.identifier and ")
.append(((live!=null && live.booleanValue()) ?
.append(((live!=null && live.booleanValue()) ?
"contentvi.live_inode":"contentvi.working_inode"))
.append(" = contentlet_1_.inode ");

Expand Down Expand Up @@ -1101,10 +1108,10 @@ protected List<Contentlet> getContentletsByIdentifier(String identifier) throws
protected List<Contentlet> getContentletsByIdentifier(String identifier, Boolean live) throws DotDataException, DotStateException, DotSecurityException {
StringBuilder queryBuffer = new StringBuilder();
queryBuffer.append("SELECT {contentlet.*} ")
.append(" FROM contentlet JOIN inode contentlet_1_ ON (contentlet.inode = contentlet_1_.inode) ")
.append(" FROM contentlet JOIN inode contentlet_1_ ON (contentlet.inode = contentlet_1_.inode) ")
.append(" JOIN contentlet_version_info contentletvi ON (contentlet.identifier=contentletvi.identifier) ")
.append(" WHERE ")
.append((live!=null && live.booleanValue() ?
.append((live!=null && live.booleanValue() ?
"contentletvi.live_inode" : "contentletvi.working_inode"))
.append(" = contentlet.inode and contentlet.identifier = ? ");
HibernateUtil hu = new HibernateUtil(com.dotmarketing.portlets.contentlet.business.Contentlet.class);
Expand Down Expand Up @@ -1213,16 +1220,25 @@ protected SearchHits indexSearch(String query, int limit, int offset, String sor
Client client=new ESClient().getClient();
SearchResponse resp = null;
try {
SearchRequestBuilder srb = client.prepareSearch()
.setQuery(QueryBuilders.queryString(qq))
.setIndices(indexToHit);
QueryStringQueryBuilder qb = QueryBuilders.queryString(qq);
SearchRequestBuilder srb = client.prepareSearch();

if(UtilMethods.isSet(sortBy) && sortBy.equals("random")) {
CustomScoreQueryBuilder cs = new CustomScoreQueryBuilder(qb);
cs.script("random()");
srb.setQuery(cs);
} else {
srb.setQuery(qb);
}

srb.setIndices(indexToHit);

if(limit>0)
srb.setSize(limit);
if(offset>0)
srb.setFrom(offset);

if(UtilMethods.isSet(sortBy) && !sortBy.startsWith("undefined") && !sortBy.startsWith("undefined_dotraw")) {
if(UtilMethods.isSet(sortBy) && !sortBy.startsWith("undefined") && !sortBy.startsWith("undefined_dotraw") && !sortBy.equals("random")) {
String[] sortbyArr=sortBy.split(",");
for (String sort : sortbyArr) {
String[] x=sort.trim().split(" ");
Expand Down Expand Up @@ -1251,7 +1267,7 @@ protected SearchHits indexSearch(String query, int limit, int offset, String sor
}
return resp.getHits();
}


@Override
protected void removeUserReferences(String userId) throws DotDataException, DotStateException, ElasticSearchException, DotSecurityException {
Expand Down Expand Up @@ -1320,7 +1336,7 @@ protected void UpdateContentWithSystemHost(String hostIdentifier) throws DotData
int offset = i * 1000;
List<Contentlet> cons = findContentletsByHost(hostIdentifier, 1000, offset);
List<String> ids = new ArrayList<String>();
for (Contentlet con : cons)
for (Contentlet con : cons)
con.setHost(systemHost.getIdentifier());
}
}
Expand Down
Expand Up @@ -156,7 +156,7 @@ public ESContentletAPIImpl () {
public Object loadField(String inode, Field f) throws DotDataException {
return conFac.loadField(inode, f.getFieldContentlet());
}

public List<Contentlet> findAllContent(int offset, int limit) throws DotDataException{
return conFac.findAllCurrent(offset, limit);
}
Expand Down Expand Up @@ -220,7 +220,7 @@ public Contentlet findContentletByIdentifier(String identifier, boolean live, lo
if(languageId<=0) {
languageId=APILocator.getLanguageAPI().getDefaultLanguage().getId();
}

try {
ContentletVersionInfo clvi = APILocator.getVersionableAPI().getContentletVersionInfo(identifier, languageId);
if(clvi ==null){
Expand Down Expand Up @@ -2271,15 +2271,16 @@ private Contentlet checkin(Contentlet contentlet, ContentletRelationships conten
if(createNewVersion && workingContentlet!= null && UtilMethods.isSet(workingContentlet.getInode())){
APILocator.getVersionableAPI().setWorking(workingContentlet);
}
Logger.error(this, e.getMessage());
Logger.error(this, e.getMessage());
Logger.error(this, e.toString());
if(e instanceof DotDataException)
throw (DotDataException)e;
if(e instanceof DotSecurityException)
throw (DotSecurityException)e;
if(e instanceof DotContentletStateException)
throw (DotContentletStateException)e;
if(e instanceof DotContentletValidationException)
throw (DotContentletValidationException)e;
if(e instanceof DotContentletStateException)
throw (DotContentletStateException)e;
if(e instanceof DotWorkflowException)
throw (DotWorkflowException)e;
if(e instanceof DotRuntimeException)
Expand Down Expand Up @@ -2753,7 +2754,7 @@ public void validateContentlet(Contentlet contentlet,List<Category> cats)throws
}
Structure st = StructureCache.getStructureByInode(contentlet.getStructureInode());
if(Structure.STRUCTURE_TYPE_FILEASSET==st.getStructureType()){
if(contentlet.getHost().equals(Host.SYSTEM_HOST) && (!UtilMethods.isSet(contentlet.getFolder()) || contentlet.getFolder().equals(FolderAPI.SYSTEM_FOLDER))){
if(contentlet.getHost()!=null && contentlet.getHost().equals(Host.SYSTEM_HOST) && (!UtilMethods.isSet(contentlet.getFolder()) || contentlet.getFolder().equals(FolderAPI.SYSTEM_FOLDER))){
DotContentletValidationException cve = new FileAssetValidationException("message.contentlet.fileasset.invalid.hostfolder");
cve.addBadTypeField(st.getFieldVar(FileAssetAPI.HOST_FOLDER_FIELD));
throw cve;
Expand Down Expand Up @@ -3530,24 +3531,24 @@ public Contentlet copyContentlet(Contentlet contentlet, Folder folder, User user
public Contentlet copyContentlet(Contentlet contentlet, Folder folder, User user, boolean appendCopyToFileName, boolean respectFrontendRoles) throws DotDataException, DotSecurityException, DotContentletStateException {
return copyContentlet(contentlet, null, folder, user, appendCopyToFileName, respectFrontendRoles);
}

private boolean needAppendCopy(Contentlet contentlet, Host host, Folder folder) throws DotDataException {
if(host!=null && contentlet.getHost()!=null && !contentlet.getHost().equals(host.getIdentifier()))
// if different host we really don't need to
// if different host we really don't need to
return false;

String sourcef=null;
if(UtilMethods.isSet(contentlet.getFolder()))
sourcef=contentlet.getFolder();
else
sourcef=APILocator.getFolderAPI().findSystemFolder().getInode();

String destf=null;
if(UtilMethods.isSet(folder))
destf=folder.getInode();
else
destf=APILocator.getFolderAPI().findSystemFolder().getInode();

return sourcef.equals(destf);
}

Expand Down
15 changes: 9 additions & 6 deletions src/com/dotmarketing/business/CacheLocator.java
Expand Up @@ -77,13 +77,16 @@ private static class CommitListenerCacheWrapper implements DotCacheAdministrator
public List<Map<String, Object>> getCacheStatsList() { return dotcache.getCacheStatsList(); }
public Class getImplementationClass() { return dotcache.getClass(); }
public void put(final String key, final Object content, final String group) {
dotcache.put(key, content, group);
try {
HibernateUtil.addCommitListener(new Runnable() {
public void run() {
dotcache.put(key, content, group);
}
});
} catch (DotHibernateException e) {
if(!HibernateUtil.getSession().connection().getAutoCommit()) {
HibernateUtil.addRollbackListener(new Runnable() {
public void run() {
dotcache.remove(key, group);
}
});
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/com/dotmarketing/business/PermissionBitFactoryImpl.java
Expand Up @@ -37,6 +37,7 @@
import com.dotmarketing.portlets.contentlet.business.ContentletAPI;
import com.dotmarketing.portlets.contentlet.business.HostAPI;
import com.dotmarketing.portlets.contentlet.model.Contentlet;
import com.dotmarketing.portlets.fileassets.business.FileAsset;
import com.dotmarketing.portlets.files.business.FileAPI;
import com.dotmarketing.portlets.files.model.File;
import com.dotmarketing.portlets.folders.business.FolderAPI;
Expand Down Expand Up @@ -2397,6 +2398,10 @@ private List<Permission> loadPermissions(Permissionable permissionable) throws D
((Contentlet)permissionable).getStructure().getVelocityVarName() != null &&
((Contentlet)permissionable).getStructure().getVelocityVarName().equals("Host"))){
type = Host.class.getCanonicalName();
}else if(permissionable instanceof FileAsset ||
(permissionable instanceof Contentlet &&
((Contentlet)permissionable).getStructure().getStructureType()==Structure.STRUCTURE_TYPE_FILEASSET)){
type = File.class.getCanonicalName();
}else if(permissionable instanceof Event){
type = Contentlet.class.getCanonicalName();
}else if(permissionable instanceof Identifier){
Expand Down
18 changes: 9 additions & 9 deletions src/com/dotmarketing/business/VersionableAPIImpl.java
Expand Up @@ -176,7 +176,7 @@ public boolean isLive(Versionable versionable) throws DotDataException, DotState
if(!UtilMethods.isSet(info.getIdentifier()))
throw new DotStateException("No version info. Call setWorking first");
liveInode=info.getLiveInode();
}
}
return liveInode!=null && liveInode.equals(versionable.getInode());
}

Expand All @@ -190,7 +190,7 @@ public boolean isLocked(Versionable ver) throws DotDataException, DotStateExcept
if(!UtilMethods.isSet(info.getIdentifier()))
throw new DotStateException("No version info. Call setWorking first");
return info.isLocked();
}
}
else {
VersionInfo info = vfac.getVersionInfo(ver.getVersionId());
if(!UtilMethods.isSet(info.getIdentifier()))
Expand All @@ -216,7 +216,7 @@ public boolean isWorking(Versionable versionable) throws DotDataException, DotSt
if(!UtilMethods.isSet(info.getIdentifier()))
throw new DotStateException("No version info. Call setWorking first");
workingInode=info.getWorkingInode();
}
}
return workingInode.equals(versionable.getInode());
}

Expand All @@ -229,7 +229,7 @@ public void removeLive(String identifier) throws DotDataException, DotStateExcep
ver.setLiveInode(null);
vfac.saveVersionInfo(ver);
}

public void removeLive(String identifier, long lang) throws DotDataException, DotStateException, DotSecurityException {
if(!UtilMethods.isSet(identifier))
throw new DotStateException("invalid identifier");
Expand Down Expand Up @@ -351,7 +351,7 @@ public String getLockedBy(Versionable ver) throws DotDataException, DotStateExce
VersionInfo vinfo=vfac.getVersionInfo(ver.getVersionId());
userId=vinfo.getLockedBy();
}
if(userId==null)
if(userId==null)
throw new DotStateException("asset is not locked");
return userId;
}
Expand All @@ -370,27 +370,27 @@ public Date getLockedOn(Versionable ver) throws DotDataException, DotStateExcept
VersionInfo vinfo=vfac.getVersionInfo(ident.getId());
date=vinfo.getLockedOn();
}
if(date==null)
if(date==null)
throw new DotStateException("asset is not locked");
return date;
}

public VersionInfo getVersionInfo(String identifier) throws DotDataException, DotStateException{
return vfac.getVersionInfo(identifier);
}

public ContentletVersionInfo getContentletVersionInfo(String identifier, long lang) throws DotDataException, DotStateException {
return vfac.getContentletVersionInfo(identifier, lang);
}

public void deleteVersionInfo(String identifier)throws DotDataException {
vfac.deleteVersionInfo(identifier);
}

public void deleteContentletVersionInfo(String identifier, long lang) throws DotDataException {
vfac.deleteContentletVersionInfo(identifier, lang);
}

public boolean hasLiveVersion(Versionable ver) throws DotDataException, DotStateException{
if(ver instanceof Contentlet) {
ContentletVersionInfo vi = this.getContentletVersionInfo(ver.getVersionId(), ((Contentlet) ver).getLanguageId());
Expand Down

0 comments on commit 17457f8

Please sign in to comment.