-
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.
Merged in SHIBUI-660 (pull request #169)
SHIBUI-660 Approved-by: Shibui Jenkins <shibui.jenkins@gmail.com>
- Loading branch information
Showing
14 changed files
with
274 additions
and
53 deletions.
There are no files selected for viewing
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
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
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
19 changes: 19 additions & 0 deletions
19
backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/DirectoryService.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,19 @@ | ||
package edu.internet2.tier.shibboleth.admin.ui.service; | ||
|
||
import org.apache.lucene.store.Directory; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* API component responsible for entity ids search. | ||
*/ | ||
public interface DirectoryService { | ||
/** | ||
* Return a Directory for a given resource id. If one is not found, it will be created. | ||
* @param resourceId the resource to get the Directory for | ||
* @return Directory | ||
*/ | ||
Directory getDirectory(String resourceId); | ||
|
||
List<Directory> getDirectories(); | ||
} |
30 changes: 30 additions & 0 deletions
30
...nd/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/DirectoryServiceImpl.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,30 @@ | ||
package edu.internet2.tier.shibboleth.admin.ui.service; | ||
|
||
import org.apache.lucene.store.Directory; | ||
import org.apache.lucene.store.RAMDirectory; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author Bill Smith (wsmith@unicon.net) | ||
*/ | ||
public class DirectoryServiceImpl implements DirectoryService { | ||
private Map<String, Directory> directoryMap = new HashMap<>(); | ||
|
||
@Override | ||
public Directory getDirectory(String resourceId) { | ||
Directory directory = directoryMap.get(resourceId); | ||
if (directory == null) { | ||
directory = new RAMDirectory(); | ||
directoryMap.put(resourceId, directory); | ||
} | ||
return directory; | ||
} | ||
|
||
@Override | ||
public List<Directory> getDirectories() { | ||
return (List<Directory>) directoryMap.values(); | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/IndexWriterService.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,18 @@ | ||
package edu.internet2.tier.shibboleth.admin.ui.service; | ||
|
||
import org.apache.lucene.index.IndexWriter; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* API component responsible for entity ids search. | ||
*/ | ||
@FunctionalInterface | ||
public interface IndexWriterService { | ||
/** | ||
* Return a (possibly cached) index writer for a given resource id. | ||
* @param resourceId the resource to create the IndexWriter for | ||
* @return IndexWriter | ||
*/ | ||
IndexWriter getIndexWriter(String resourceId) throws IOException; | ||
} |
45 changes: 45 additions & 0 deletions
45
backend/src/main/java/edu/internet2/tier/shibboleth/admin/util/LuceneUtility.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,45 @@ | ||
package edu.internet2.tier.shibboleth.admin.util; | ||
|
||
import edu.internet2.tier.shibboleth.admin.ui.service.DirectoryService; | ||
import org.apache.commons.lang.StringUtils; | ||
import org.apache.lucene.index.DirectoryReader; | ||
import org.apache.lucene.index.IndexReader; | ||
import org.apache.lucene.index.MultiReader; | ||
import org.apache.lucene.store.Directory; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* @author Bill Smith (wsmith@unicon.net) | ||
*/ | ||
public class LuceneUtility { | ||
private static final Logger logger = LoggerFactory.getLogger(LuceneUtility.class); | ||
|
||
@Autowired | ||
private DirectoryService directoryService; | ||
|
||
public IndexReader getIndexReader(String resourceId) throws IOException { | ||
IndexReader indexReader; | ||
if (StringUtils.isBlank(resourceId)) { | ||
List<Directory> directories = directoryService.getDirectories(); | ||
List<IndexReader> indexReaderList = new ArrayList<>(); | ||
directories.forEach(it -> { | ||
try { | ||
indexReaderList.add(DirectoryReader.open(it)); | ||
} catch (IOException e) { | ||
logger.error(e.getMessage(), e); | ||
} | ||
}); | ||
IndexReader[] indexReaders = (IndexReader[]) indexReaderList.toArray(); | ||
indexReader = new MultiReader(indexReaders, true); | ||
} else { | ||
indexReader = DirectoryReader.open(directoryService.getDirectory(resourceId)); | ||
} | ||
return indexReader; | ||
} | ||
} |
Oops, something went wrong.