Преглед на файлове

Code clean-up and upgrade user properties (#509)

* fix typo

* #506 : add ldap user properties

* code clean-up

* #506 add creating alias
nullpos преди 9 години
родител
ревизия
5e7d09428a

+ 100 - 1
src/main/java/org/codelibs/fess/app/web/admin/upgrade/AdminUpgradeAction.java

@@ -15,6 +15,7 @@
  */
 package org.codelibs.fess.app.web.admin.upgrade;
 
+import java.io.File;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -22,6 +23,9 @@ import java.util.Map;
 
 import javax.annotation.Resource;
 
+import org.codelibs.core.exception.ResourceNotFoundRuntimeException;
+import org.codelibs.core.io.FileUtil;
+import org.codelibs.core.io.ResourceUtil;
 import org.codelibs.fess.app.web.base.FessAdminAction;
 import org.codelibs.fess.es.client.FessEsClient;
 import org.codelibs.fess.es.config.exbhv.DataConfigBhv;
@@ -34,6 +38,8 @@ import org.codelibs.fess.es.config.exbhv.RoleTypeBhv;
 import org.codelibs.fess.es.config.exbhv.WebConfigBhv;
 import org.codelibs.fess.es.config.exbhv.WebConfigToRoleBhv;
 import org.codelibs.fess.mylasta.direction.FessConfig;
+import org.codelibs.fess.util.StreamUtil;
+import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
 import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse;
 import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
 import org.elasticsearch.client.IndicesAdminClient;
@@ -127,6 +133,7 @@ public class AdminUpgradeAction extends FessAdminAction {
     private void upgradeFrom10_0() {
 
         final IndicesAdminClient indicesClient = fessEsClient.admin().indices();
+        final String indexConfigPath = "fess_indices";
         final String configIndex = ".fess_config";
         final String userIndex = ".fess_user";
         final String docIndex = fessConfig.getIndexDocumentUpdateIndex();
@@ -137,7 +144,29 @@ public class AdminUpgradeAction extends FessAdminAction {
             // TODO seunjeon
 
             // alias
-            // TODO .fess_basic_config
+            final String aliasConfigDirPath = indexConfigPath + "/" + configIndex + "/alias";
+            try {
+                final File aliasConfigDir = ResourceUtil.getResourceAsFile(aliasConfigDirPath);
+                if (aliasConfigDir.isDirectory()) {
+                    StreamUtil.of(aliasConfigDir.listFiles((dir, name) -> name.endsWith(".json"))).forEach(
+                            f -> {
+                                final String aliasName = f.getName().replaceFirst(".json$", "");
+                                final String source = FileUtil.readUTF8(f);
+                                final IndicesAliasesResponse response =
+                                        indicesClient.prepareAliases().addAlias(configIndex, aliasName, source).execute()
+                                                .actionGet(fessConfig.getIndexIndicesTimeout());
+                                if (response.isAcknowledged()) {
+                                    logger.info("Created " + aliasName + " alias for " + configIndex);
+                                } else if (logger.isDebugEnabled()) {
+                                    logger.debug("Failed to create " + aliasName + " alias for " + configIndex);
+                                }
+                            });
+                }
+            } catch (final ResourceNotFoundRuntimeException e) {
+                // ignore
+            } catch (final Exception e) {
+                logger.warn(aliasConfigDirPath + " is not found.", e);
+            }
 
             // update mapping
             addFieldMapping(indicesClient, configIndex, "label_type", "permissions",
@@ -149,6 +178,76 @@ public class AdminUpgradeAction extends FessAdminAction {
             addFieldMapping(indicesClient, configIndex, "data_config", "permissions",
                     "{\"properties\":{\"permissions\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
             addFieldMapping(indicesClient, userIndex, "group", "gidNumber", "{\"properties\":{\"gidNumber\":{\"type\":\"long\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "employeeNumber",
+                    "{\"properties\":{\"employeeNumber\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "mail",
+                    "{\"properties\":{\"mail\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "telephoneNumber",
+                    "{\"properties\":{\"telephoneNumber\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "homePhone",
+                    "{\"properties\":{\"homePhone\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "homePostalAddress",
+                    "{\"properties\":{\"homePostalAddress\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "labeledURI",
+                    "{\"properties\":{\"labeledURI\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "roomNumber",
+                    "{\"properties\":{\"roomNumber\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "description",
+                    "{\"properties\":{\"description\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "title",
+                    "{\"properties\":{\"title\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "pager",
+                    "{\"properties\":{\"pager\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "street",
+                    "{\"properties\":{\"street\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "postalCode",
+                    "{\"properties\":{\"postalCode\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "physicalDeliveryOfficeName",
+                    "{\"properties\":{\"physicalDeliveryOfficeName\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "destinationIndicator",
+                    "{\"properties\":{\"destinationIndicator\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "internationaliSDNNumber",
+                    "{\"properties\":{\"internationaliSDNNumber\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "state",
+                    "{\"properties\":{\"state\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "employeeType",
+                    "{\"properties\":{\"employeeType\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "facsimileTelephoneNumber",
+                    "{\"properties\":{\"facsimileTelephoneNumber\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "postOfficeBox",
+                    "{\"properties\":{\"postOfficeBox\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "initials",
+                    "{\"properties\":{\"initials\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "carLicense",
+                    "{\"properties\":{\"carLicense\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "mobile",
+                    "{\"properties\":{\"mobile\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "postalAddress",
+                    "{\"properties\":{\"postalAddress\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "city",
+                    "{\"properties\":{\"city\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "teletexTerminalIdentifier",
+                    "{\"properties\":{\"teletexTerminalIdentifier\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "x121Address",
+                    "{\"properties\":{\"x121Address\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "businessCategory",
+                    "{\"properties\":{\"businessCategory\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "registeredAddress",
+                    "{\"properties\":{\"registeredAddress\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "displayName",
+                    "{\"properties\":{\"displayName\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "preferredLanguage",
+                    "{\"properties\":{\"preferredLanguage\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "departmentNumber",
+                    "{\"properties\":{\"departmentNumber\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "uidNumber",
+                    "{\"properties\":{\"uidNumber\":{\"type\":\"long\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "gidNumber",
+                    "{\"properties\":{\"gidNumber\":{\"type\":\"long\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "homeDirectory",
+                    "{\"properties\":{\"homeDirectory\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
+            addFieldMapping(indicesClient, userIndex, "user", "groups",
+                    "{\"properties\":{\"groups\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
             addFieldMapping(indicesClient, docIndex, docType, "location", "{\"properties\":{\"location\":{\"type\":\"geo_point\"}}}");
 
             // data migration

+ 1 - 1
src/main/webapp/css/style-base.css

@@ -199,7 +199,7 @@ input[type="search"] {
 input[type="search"]::-webkit-search-cancel-button,
 input[type="search"]::-webkit-search-decoration {
   -webkit-appearance: none;
-}     -webkit-appearance: nownw
+}
 
 fieldset {
   padding: .35em .625em .75em;

+ 2 - 2
src/main/webapp/js/search.js

@@ -136,7 +136,7 @@ $(function() {
 							var url = $favorite.attr('href');
 							var found = false;
 							for (var i = 0; i < docIds.length; i++) {
-								if (url == docIds[i]) {
+								if (url === docIds[i]) {
 									found = true;
 									break;
 								}
@@ -158,7 +158,7 @@ $(function() {
 	$result.on('click', '.more a', function(e) {
 		var $moreLink = $(this);
 		var value = $moreLink.attr('href');
-		if (value != '') {
+		if (value !== '') {
 			var $info = $(value + ' .info');
 			if ($info.size() > 0) {
 				$moreLink.fadeOut(500, function() {

+ 23 - 23
src/main/webapp/js/suggestor.js

@@ -124,7 +124,7 @@ $.fn.suggestor = function(setting) {
 
 			listNum = 0;
 			if(typeof hits !== "undefined") {
-				var reslist = new Array();
+				var reslist = [];
 				for(var i=0;i<hits.length;i++) {
 					reslist.push(hits[i].text);
 				}
@@ -139,7 +139,7 @@ $.fn.suggestor = function(setting) {
 
 					var $tmpli = $($olEle.children("li"));
 					for(var j=0;j<$tmpli.size();j++) {
-						if(str == $($tmpli.get(j)).html()) {
+						if(str === $($tmpli.get(j)).html()) {
 							chkCorrectWord = false;
 						}
 					}
@@ -159,7 +159,7 @@ $.fn.suggestor = function(setting) {
 						$liEle.hover(function() {
 							listSelNum = $(this).closest("ol").children("li").index(this) + 1;
 							$(this).closest("ol").children("li").each(function(i){
-								if(i == (listSelNum-1)) {
+								if(i === (listSelNum-1)) {
 									if(typeof listSelectedCssInfo === 'undefined') {
 										$(this).css("background-color", "#e5e5e5");
 									} else {
@@ -178,7 +178,7 @@ $.fn.suggestor = function(setting) {
 								}
 							});
 						}, function() {
-							if( listSelNum == ($(this).closest("ol").children("li").index(this) + 1) ) {
+							if( listSelNum === ($(this).closest("ol").children("li").index(this) + 1) ) {
 								if(typeof listDeselectedCssInfo !== 'undefined') {
 									$(this).css(listDeselectedCssInfo);
 								} else {
@@ -216,13 +216,13 @@ $.fn.suggestor = function(setting) {
 		},
 
 		selectlist: function(direction) {
-			if($boxElement.css("display") == "none") {
+			if($boxElement.css("display") === "none") {
 				return;
 			}
 
-			if(direction == "down") {
+			if(direction === "down") {
 				listSelNum++;
-			} else if(direction == "up") {
+			} else if(direction === "up") {
 				listSelNum--;
 			} else {
 				return;
@@ -238,7 +238,7 @@ $.fn.suggestor = function(setting) {
 
 			var a = $boxElement.children("ol").children("li");
 			$boxElement.children("ol").children("li").each(function(i){
-				if(i == (listSelNum-1)) {
+				if(i === (listSelNum-1)) {
 					if(typeof listSelectedCssInfo === 'undefined') {
 						$(this).css("background-color", "#e5e5e5");
 					} else {
@@ -257,7 +257,7 @@ $.fn.suggestor = function(setting) {
 					}
 				}
 			});
-			if(listSelNum == 0) {
+			if(listSelNum === 0) {
 				$textArea.val(inputText);
 			}
 
@@ -291,24 +291,24 @@ $.fn.suggestor = function(setting) {
 		if( ((e.keyCode >= 48) && (e.keyCode <= 90))
 			 || ((e.keyCode >= 96) && (e.keyCode <= 105))
 			 || ((e.keyCode >= 186) && (e.keyCode <= 226))
-			 || e.keyCode == 8
-			 || e.keyCode == 32
-			 || e.keyCode == 46
+			 || e.keyCode === 8
+			 || e.keyCode === 32
+			 || e.keyCode === 46
 			 ) {
 			started = true;
 			isFocusList = false;
-		} else if(e.keyCode == 38) {
-			if($boxElement.css("display") != "none") {
+		} else if(e.keyCode === 38) {
+			if($boxElement.css("display") !== "none") {
 				e.preventDefault();
 			}
 			suggestor.selectlist("up");
-		} else if(e.keyCode == 40) {
-			if($boxElement.css("display") == "none") {
+		} else if(e.keyCode === 40) {
+			if($boxElement.css("display") === "none") {
 				suggestor.suggest();
 			} else {
 				suggestor.selectlist("down");
 			}
-		} else if(e.keyCode == 13) {
+		} else if(e.keyCode === 13) {
 			if(isFocusList) {
 				suggestor.fixList();
 			}
@@ -318,14 +318,14 @@ $.fn.suggestor = function(setting) {
 		if( ((e.keyCode >= 48) && (e.keyCode <= 90))
 			 || ((e.keyCode >= 96) && (e.keyCode <= 105))
 			 || ((e.keyCode >= 186) && (e.keyCode <= 226))
-			 || e.keyCode == 8
-			 || e.keyCode == 32
-			 || e.keyCode == 46
+			 || e.keyCode === 8
+			 || e.keyCode === 32
+			 || e.keyCode === 46
 			 ) {
 			started = true;
 			isFocusList = false;
-		} else if(e.keyCode == 38) {
-/*			if($boxElement.css("display") != "none") {
+		} else if(e.keyCode === 38) {
+/*			if($boxElement.css("display") !== "none") {
 				var strTmp = $textArea.val();
 				$textArea.val("");
 				$textArea.focus();
@@ -344,7 +344,7 @@ $.fn.suggestor = function(setting) {
 		if(interval < 5) {
 			interval = interval + 1;
 		} else {
-			if($textArea.val() != inputText) {
+			if($textArea.val() !== inputText) {
 				if(!isFocusList && started && !suggestingSts) {
 					//リスト選択中でなければ更新
 					suggestor.suggest();