Project

General

Profile

« Previous | Next » 

Revision 7657

Added by Jing Tao over 11 years ago

Add getCollectionName method.

View differences:

metacat-common/src/main/java/edu/ucsb/nceas/metacat/common/SolrServerFactory.java
65 65
	public static Log log = LogFactory.getLog(SolrServerFactory.class);
66 66
	
67 67
	private static CoreContainer coreContainer = null;
68
	private static String collectionName = null;
68 69
	private static SolrServer solrServer = null;
69 70

  
70 71
	public static SolrServer createSolrServer() throws Exception {
71
		
72
		String className = Settings.getConfiguration().getString(SOLR_SERVER_CLASSNAME_PROPERTY_NAME);
73
		if (className != null && className.equals(EMBEDDEDSERVERCLASS)) {
74
		    generateEmbeddedServer();
75
		} else if (className != null && className.equals(HTTPSERVERCLASS)) {
76
		    String solrServerUrl = Settings.getConfiguration().getString(SOLR_ENPOINT_PROPERTY_NAME);
77
		    solrServer = new CommonsHttpSolrServer(solrServerUrl);
78
		} else {
79
		    throw new Exception("SolrServerFactory.createSolrServer - MetacatIndex doesn't support this solr server type: "+className);
80
		}
81

  
82
        
72
	    if(solrServer == null) {
73
	        String className = Settings.getConfiguration().getString(SOLR_SERVER_CLASSNAME_PROPERTY_NAME);
74
	        if (className != null && className.equals(EMBEDDEDSERVERCLASS)) {
75
	            generateEmbeddedServer();
76
	        } else if (className != null && className.equals(HTTPSERVERCLASS)) {
77
	            String solrServerUrl = Settings.getConfiguration().getString(SOLR_ENPOINT_PROPERTY_NAME);
78
	            solrServer = new CommonsHttpSolrServer(solrServerUrl);
79
	        } else {
80
	            throw new Exception("SolrServerFactory.createSolrServer - MetacatIndex doesn't support this solr server type: "+className);
81
	        }
82
	    }
83 83
        return solrServer;
84 84
	}
85 85
	
......
90 90
        File configFile = new File(solrHomeDir, configFileName);
91 91
        coreContainer = new CoreContainer(solrHomeDir, configFile);
92 92
        coreContainer.load(solrHomeDir, configFile);
93
        String collectioname = Settings.getConfiguration().getString(SOLR_COLLECTION_NAME_PROPERTY_NAME);
94
        solrServer = new EmbeddedSolrServer(coreContainer, collectioname);
93
        collectionName = getCollectionName();
94
        solrServer = new EmbeddedSolrServer(coreContainer, collectionName);
95 95
	}
96 96
	
97
	public static CoreContainer getCoreContainer() {
97
	/**
98
	 * Get the the CoreContainer
99
	 * @return it may return null if the solr is configured as the SolrHttpServer
100
	 * @throws Exception 
101
	 */
102
	public static CoreContainer getCoreContainer() throws Exception {
103
	    if(coreContainer == null) {
104
	        createSolrServer();
105
	    }
98 106
	    return coreContainer;
99 107
	}
108
	
109
	public static String getCollectionName() {
110
	    if(collectionName == null) {
111
	        Settings.getConfiguration().getString(SOLR_COLLECTION_NAME_PROPERTY_NAME);
112
	    }
113
	    return collectionName;
114
	}
100 115
}

Also available in: Unified diff