[Yanel-commits] rev 59534 - in public/yanel/trunk/src/contributions/resources/search: . src/java/org/wyona/yanel/impl/resources src/java/org/wyona/yanel/impl/resources/search
michi at wyona.com
michi at wyona.com
Fri Jul 22 16:38:00 CEST 2011
Author: michi
Date: 2011-07-22 16:37:59 +0200 (Fri, 22 Jul 2011)
New Revision: 59534
Added:
public/yanel/trunk/src/contributions/resources/search/src/java/org/wyona/yanel/impl/resources/search/ReindexResource.java
Removed:
public/yanel/trunk/src/contributions/resources/search/src/java/org/wyona/yanel/impl/resources/reindex/
Modified:
public/yanel/trunk/src/contributions/resources/search/resource-reindexer.xml
Log:
re-indexer moved into search package in order to resolve ambigiuous resolving
Modified: public/yanel/trunk/src/contributions/resources/search/resource-reindexer.xml
===================================================================
--- public/yanel/trunk/src/contributions/resources/search/resource-reindexer.xml 2011-07-22 13:20:36 UTC (rev 59533)
+++ public/yanel/trunk/src/contributions/resources/search/resource-reindexer.xml 2011-07-22 14:37:59 UTC (rev 59534)
@@ -3,7 +3,7 @@
<resource xmlns="http://www.wyona.org/yanel/1.0"
name="reindexer"
namespace="http://www.wyona.org/yanel/resource/1.0"
- class="org.wyona.yanel.impl.resources.reindexer.ReindexResource"
+ class="org.wyona.yanel.impl.resources.search.ReindexResource"
>
<description>
A resource in order to re-index repositories.
Added: public/yanel/trunk/src/contributions/resources/search/src/java/org/wyona/yanel/impl/resources/search/ReindexResource.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/search/src/java/org/wyona/yanel/impl/resources/search/ReindexResource.java (rev 0)
+++ public/yanel/trunk/src/contributions/resources/search/src/java/org/wyona/yanel/impl/resources/search/ReindexResource.java 2011-07-22 14:37:59 UTC (rev 59534)
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2011 Wyona
+ */
+package org.wyona.yanel.impl.resources.search;
+
+import org.wyona.yarep.util.YarepUtil;
+import org.wyona.yarep.core.Repository;
+
+import org.wyona.yanel.core.attributes.viewable.View;
+import org.wyona.yanel.impl.resources.BasicXMLResource;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import org.apache.log4j.Logger;
+
+/**
+ * Re-indexing resource. This resource can be used to start the re-indexing
+ * process of an arbitrary repository from within a browser session. If you
+ * configure this resource in your realm, make sure to protect it because you
+ * most likely don't want your users to start re-indexing processes.
+ */
+public class ReindexResource extends BasicXMLResource {
+ private static Logger log = Logger.getLogger(ReindexResource.class);
+
+ private static String REPO_NAME = "repository";
+ private static String REINDEX_XMLNS = "http://www.wyona.org/yanel/reindex/1.0";
+
+ /**
+ * @see org.wyona.yanel.impl.resources.BasicXMLResource#getContentXML(String)
+ */
+ protected InputStream getContentXML(String viewId) throws Exception {
+ // Build output document
+ StringBuilder sb = new StringBuilder("<?xml version=\"1.0\"?>");
+ sb.append("<r:reindex xmlns:r=\"");
+ sb.append(REINDEX_XMLNS);
+ sb.append("\">");
+
+ // Which repo needs to be re-indexed?
+ String reindexRepo = getEnvironment().getRequest().getParameter(REPO_NAME);
+
+ // Are we allowed to re-index this repository?
+ // Only default repositories and the ones listed in the resource configuration are allowed to be re-indexed
+ boolean allowed = false;
+
+ // List default repositories
+ // Only show them if we're allowed to re-index them
+ String defaultRepos = getResourceConfigProperty("allow-default-repos");
+ if("true".equals(defaultRepos)) {
+ sb.append("<r:repository id=\"yanel_data\">Realm's data repository</r:repository>");
+ sb.append("<r:repository id=\"yanel_ac-identities\">Realm's ac-identities repository</r:repository>");
+ sb.append("<r:repository id=\"yanel_ac-policies\">Realm's ac-policies repository</r:repository>");
+ sb.append("<r:repository id=\"yanel_res-configs\">Realm's res-configs repository</r:repository>");
+ }
+
+ // List extra repositories from repo configuration
+ String[] repoIds = getResourceConfigProperties("repository-id");
+ for(String repoId : repoIds) {
+ if(repoId != null && !"".equals(repoId)) {
+ sb.append("<r:repository id=\"");
+ sb.append(repoId);
+ sb.append("\">Configured repository with id '");
+ sb.append(repoId);
+ sb.append("'</r:repository>");
+ // Check if repo that should be re-indexed is listed in resource configuration (see property 'repository-id')
+ if(!allowed && repoId.equals(reindexRepo)) allowed = true;
+ }
+ }
+
+ // Check if repo that should be re-indexed is default repo
+ if(!allowed && "true".equals(defaultRepos) &&
+ ("yanel_data".equals(reindexRepo) ||
+ "yanel_ac-policies".equals(reindexRepo) ||
+ "yanel_ac-identities".equals(reindexRepo) ||
+ "yanel_res-configs".equals(reindexRepo))) {
+ allowed = true;
+ }
+
+ // If it's an extra repo, allowed needs to be set to true
+ Repository repo = null;
+ if(allowed) {
+ try {
+ repo = getRealm().getRepository(reindexRepo);
+ } catch(Exception e) {
+ sb.append("<r:exception>Opening repo failed with exception: ");
+ sb.append(e.getMessage());
+ sb.append("</r:exception>");
+ }
+ }
+
+ // Perform re-indexing now
+ if(repo != null) {
+ YarepUtil yu = new YarepUtil();
+
+ try {
+ yu.indexRepository(repo);
+ sb.append("<r:message>Re-indexing was successful.</r:message>");
+ } catch(Exception e) {
+ sb.append("<r:exception>Re-indexing failed with exception: ");
+ sb.append(e.getMessage());
+ sb.append("</r:exception>");
+ }
+ } else if(reindexRepo != null) {
+ sb.append("<r:exception>Repository '" + reindexRepo + "' does either not exist or is not configured in order to be re-indexed.</r:exception>");
+ }
+
+ sb.append("</r:reindex>");
+ return new ByteArrayInputStream(sb.toString().getBytes());
+ }
+
+ /**
+ * @see org.wyona.yanel.core.api.attributes.ViewableV2#exists()
+ */
+ public boolean exists() throws Exception {
+ return true;
+ }
+}
More information about the Yanel-commits
mailing list