Skip to content

Commit

Permalink
Merge remote branch 'imyousuf/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
smartKaisar committed May 3, 2011
2 parents 0d77c47 + 0dfcfb0 commit b38555f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class ContentSearcherImpl implements ContentSearcher {
@Inject
private SchemaInfoProvider<PersistentContent, ContentId> schemaInfoProvider;
// Injected so that the quartz service starts
@Inject(optional=true)
@Inject(optional = true)
private EventSubscriber subscriber;
@Inject
@Named(REINDEX_LISTENER_NAME)
Expand Down Expand Up @@ -277,52 +277,77 @@ public void reIndex(ContentId contentId) {

@Override
public void reIndex(final WorkspaceId workspaceId) {
if (logger.isInfoEnabled()) {
logger.info("Re-Indexing " + workspaceId);
}
executorService.submit(new Runnable() {

@Override
public void run() {
final QueryParameter param;
if (workspaceId == null) {
param = null;
}
else {
param = QueryParameterFactory.getStringLikePropertyParam("id", new StringBuilder(workspaceId.toString()).
append(':').toString(), MatchMode.START);
}
final QueryParameter<Integer> maxResultsParam = QueryParameterFactory.getMaxResultsParam(100);
boolean hasMore = true;
ContentId lastId = null;
List<QueryParameter> params = new ArrayList<QueryParameter>();
while (hasMore) {
params.clear();
if (param != null) {
params.add(param);
try {
final QueryParameter param;
if (workspaceId == null) {
param = null;
}
params.add(maxResultsParam);
if (lastId != null) {
try {
params.add(QueryParameterFactory.getGreaterThanPropertyParam("id", schemaInfoProvider.getRowIdFromId(
lastId)));
else {
param = QueryParameterFactory.getStringLikePropertyParam("id", new StringBuilder(workspaceId.toString()).
append(':').toString(), MatchMode.START);
}
final QueryParameter<Integer> maxResultsParam = QueryParameterFactory.getMaxResultsParam(100);
boolean hasMore = true;
ContentId lastId = null;
List<QueryParameter> params = new ArrayList<QueryParameter>();
logger.info("Beginning iteration over contents");
while (hasMore) {
if (logger.isInfoEnabled()) {
logger.info("Trying with Last ID " + lastId);
}
catch (Exception ex) {
logger.warn("Could not add last id clause " + lastId.toString(), ex);
params.clear();
if (param != null) {
params.add(param);
}
}
List<PersistentContent> list = readDao.getList(params);
if (list == null || list.isEmpty()) {
hasMore = false;
}
else {
final Content[] contents = new Content[list.size()];
int index = 0;
for (PersistentContent content : list) {
reindexListener.notify(SmartContentAPI.getInstance().getEventRegistrar().<Content>createEvent(
EventType.CREATE, Type.CONTENT, content.getMutableContent()));
params.add(maxResultsParam);
if (lastId != null) {
try {
params.add(QueryParameterFactory.getGreaterThanPropertyParam("id", schemaInfoProvider.getRowIdFromId(
lastId)));
}
catch (Exception ex) {
logger.warn("Could not add last id clause " + lastId.toString(), ex);
}
}
List<PersistentContent> list = readDao.getList(params);
if (logger.isInfoEnabled()) {
logger.info("Has More " + hasMore);
logger.info("Content numbers in current iteration " + (list != null ? list.size() : -1));
}
if (list == null || list.isEmpty()) {
hasMore = false;
}
else {
final PersistentContent[] contents = new PersistentContent[list.size()];
int index = 0;
for (PersistentContent content : list) {
if (logger.isInfoEnabled()) {
logger.info("Attempting to index " + content.getId());
}
reindexListener.notify(SmartContentAPI.getInstance().getEventRegistrar().<Content>createEvent(
EventType.UPDATE, Type.CONTENT, content.getMutableContent()));
contents[index++] = content;
}
lastId = contents[contents.length - 1].getId();
}
if (logger.isInfoEnabled()) {
logger.info("Has More " + hasMore);
logger.info("Content numbers in current iteration " + (list != null ? list.size() : -1));
logger.info("Last ID " + lastId);
logger.info("Going for next iteration " + hasMore);
}

lastId = contents[contents.length - 1].getContentId();
}
}
catch (Exception ex) {
logger.error("Error reindexing", ex);
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,15 @@ public void run() {
hasMore = false;
}
else {
final ContentType[] contents = new ContentType[list.size()];
final PersistentContentType[] contents = new PersistentContentType[list.size()];
int index = 0;
for (PersistentContentType content : list) {
reindexListener.notify(SmartContentAPI.getInstance().getEventRegistrar().<ContentType>createEvent(
EventType.UPDATE, Type.CONTENT_TYPE, content.getMutableContentType()));
contents[index++] = content;
}

lastId = contents[contents.length - 1].getContentTypeID();
lastId = contents[contents.length - 1].getId();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private RootResourceImpl(URI uri) throws IllegalArgumentException,
CONNECTION_CONFIGURED ? ApplicationWideClientFactoryImpl.getClientFactory(SMART_CMS_CONNECTION_CONFIG,
CONFIG_PROCESSOR) : null);
if (logger.isDebugEnabled()) {
logger.debug("Root resource URI for Smart CMS " + uri.toString());
logger.debug("Root resource URI for Smart CMS " + uri);
}
}

Expand Down

0 comments on commit b38555f

Please sign in to comment.