http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/catalog/src/main/java/org/apache/oodt/cas/catalog/struct/impl/index/WorkflowManagerDataSourceIndex.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/oodt/cas/catalog/struct/impl/index/WorkflowManagerDataSourceIndex.java b/catalog/src/main/java/org/apache/oodt/cas/catalog/struct/impl/index/WorkflowManagerDataSourceIndex.java deleted file mode 100644 index cc329dc..0000000 --- a/catalog/src/main/java/org/apache/oodt/cas/catalog/struct/impl/index/WorkflowManagerDataSourceIndex.java +++ /dev/null @@ -1,323 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.oodt.cas.catalog.struct.impl.index; - -//JDK imports - -import org.apache.oodt.cas.catalog.exception.CatalogIndexException; -import org.apache.oodt.cas.catalog.exception.QueryServiceException; -import org.apache.oodt.cas.catalog.page.IndexPager; -import org.apache.oodt.cas.catalog.page.IngestReceipt; -import org.apache.oodt.cas.catalog.query.ComparisonQueryExpression; -import org.apache.oodt.cas.catalog.query.NotQueryExpression; -import org.apache.oodt.cas.catalog.query.QueryExpression; -import org.apache.oodt.cas.catalog.query.QueryLogicalGroup; -import org.apache.oodt.cas.catalog.query.StdQueryExpression; -import org.apache.oodt.cas.catalog.struct.Index; -import org.apache.oodt.cas.catalog.struct.QueryService; -import org.apache.oodt.cas.catalog.struct.TransactionId; -import org.apache.oodt.cas.catalog.struct.TransactionIdFactory; -import org.apache.oodt.cas.catalog.struct.impl.transaction.LongTransactionIdFactory; -import org.apache.oodt.cas.catalog.term.Term; -import org.apache.oodt.cas.catalog.term.TermBucket; -import org.apache.oodt.commons.database.DatabaseConnectionBuilder; -import org.apache.oodt.commons.util.DateConvert; - -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.net.URLEncoder; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.Statement; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Vector; -import java.util.concurrent.ConcurrentHashMap; -import java.util.logging.Level; -import java.util.logging.Logger; - -import javax.sql.DataSource; - -//SQL imports -//OODT imports -//EDA imports - -/** - * @author bfoster - * @version $Revision$ - * - * <p> - * A queriable index for querying for original cas-workflow instance metadata (not for cas-workflow2) - * <p> - */ -public class WorkflowManagerDataSourceIndex implements Index, QueryService { - - private static final Logger LOG = Logger.getLogger(WorkflowManagerDataSourceIndex.class.getName()); - - protected DataSource dataSource; - - public WorkflowManagerDataSourceIndex(String user, String pass, String driver, String jdbcUrl) { - this.dataSource = DatabaseConnectionBuilder.buildDataSource(user, pass, driver, jdbcUrl); - } - - public List<TransactionId<?>> getPage(IndexPager indexPage) { - // TODO Auto-generated method stub - return null; - } - - public Properties getProperties() { - return new Properties(); - } - - public String getProperty(String key) { - return null; - } - - public TransactionIdFactory getTransactionIdFactory() { - return new LongTransactionIdFactory(); - } - - public boolean hasTransactionId(TransactionId<?> transactionId) - throws CatalogIndexException { - Connection conn = null; - Statement stmt = null; - ResultSet rs = null; - try { - conn = this.dataSource.getConnection(); - stmt = conn.createStatement(); - rs = stmt.executeQuery("SELECT DISTINCT workflow_instance_id FROM workflow_instance_metadata WHERE workflow_instance_id = '" + transactionId + "'"); - return rs.next(); - }catch (Exception e) { - throw new CatalogIndexException("Failed to check for workflow id '" + transactionId + "' : " + e.getMessage(), e); - }finally { - try { - conn.close(); - }catch(Exception ignored) {} - try { - stmt.close(); - }catch(Exception ignored) {} - try { - rs.close(); - }catch(Exception ignored) {} - } - } - - public List<TermBucket> getBuckets(TransactionId<?> transactionId) - throws QueryServiceException { - Connection conn = null; - Statement stmt = null; - ResultSet rs = null; - try { - conn = this.dataSource.getConnection(); - stmt = conn.createStatement(); - rs = stmt.executeQuery("SELECT * FROM workflow_instance_metadata WHERE workflow_instance_id = '" + transactionId + "'"); - - TermBucket tb = new TermBucket("Workflows"); - while (rs.next()) { - String key = rs.getString("workflow_met_key"); - String value = URLDecoder.decode(rs.getString("workflow_met_val"), "UTF-8"); - tb.addTerm(new Term(key, Collections.singletonList(value))); - } - return Collections.singletonList(tb); - }catch (Exception e) { - throw new QueryServiceException("Failed to get Workflow Instance Metadata for workflow id '" + transactionId + "' : " + e.getMessage(), e); - }finally { - try { - conn.close(); - }catch(Exception ignored) {} - try { - stmt.close(); - }catch(Exception ignored) {} - try { - rs.close(); - }catch(Exception ignored) {} - } - } - - public Map<TransactionId<?>, List<TermBucket>> getBuckets( - List<TransactionId<?>> transactionIds) throws QueryServiceException { - Map<TransactionId<?>, List<TermBucket>> returnMap = new ConcurrentHashMap<TransactionId<?>, List<TermBucket>>(); - for (TransactionId<?> transactionId : transactionIds) { - returnMap.put(transactionId, this.getBuckets(transactionId)); - } - return returnMap; - } - - public List<IngestReceipt> query(QueryExpression queryExpression) - throws QueryServiceException { - Connection conn = null; - Statement stmt = null; - ResultSet rs = null; - try { - conn = this.dataSource.getConnection(); - stmt = conn.createStatement(); - String sqlQuery = "SELECT workflow_instance_id,start_date_time FROM workflow_instances WHERE workflow_instance_id IN (" + this.getSqlQuery(queryExpression) + ")"; - LOG.log(Level.INFO, "Performing Query: " + sqlQuery); - rs = stmt.executeQuery(sqlQuery); - - List<IngestReceipt> receipts = new Vector<IngestReceipt>(); - while (rs.next()) { - receipts.add(new IngestReceipt( - new LongTransactionIdFactory().createTransactionId(rs.getString("workflow_instance_id")), - DateConvert.isoParse(rs.getString("start_date_time")))); - } - return receipts; - }catch (Exception e) { - throw new QueryServiceException("Failed to query Workflow Instances Database : " + e.getMessage(), e); - }finally { - try { - conn.close(); - }catch(Exception ignored) {} - try { - stmt.close(); - }catch(Exception ignored) {} - try { - rs.close(); - }catch(Exception ignored) {} - } - } - - public List<IngestReceipt> query(QueryExpression queryExpression, int startIndex, int endIndex) throws QueryServiceException { - Connection conn = null; - Statement stmt = null; - ResultSet rs = null; - try { - conn = this.dataSource.getConnection(); - stmt = conn.createStatement(); - String sqlQuery = "SELECT workflow_instance_id,start_date_time FROM workflow_instances WHERE workflow_instance_id IN (" + this.getSqlQuery(queryExpression) + ")"; - LOG.log(Level.INFO, "Performing Query: " + sqlQuery); - rs = stmt.executeQuery(sqlQuery); - - List<IngestReceipt> receipts = new Vector<IngestReceipt>(); - int index = 0; - while (startIndex > index && rs.next()) { - index++; - } - while (rs.next() && index++ <= endIndex) { - receipts.add(new IngestReceipt( - new LongTransactionIdFactory().createTransactionId(rs.getString("workflow_instance_id")), - DateConvert.isoParse(rs.getString("start_date_time")))); - } - return receipts; - }catch (Exception e) { - throw new QueryServiceException("Failed to query Workflow Instances Database : " + e.getMessage(), e); - }finally { - try { - conn.close(); - }catch(Exception ignored) {} - try { - stmt.close(); - }catch(Exception ignored) {} - try { - rs.close(); - }catch(Exception ignored) {} - } - } - - public int sizeOf(QueryExpression queryExpression) - throws QueryServiceException { - Connection conn = null; - Statement stmt = null; - ResultSet rs = null; - try { - conn = this.dataSource.getConnection(); - stmt = conn.createStatement(); - String sqlQuery = "SELECT COUNT(workflow_instance_id) AS numInstances FROM workflow_instances WHERE workflow_instance_id IN (" + this.getSqlQuery(queryExpression) + ")"; - LOG.log(Level.INFO, "Performing Query: " + sqlQuery); - rs = stmt.executeQuery(sqlQuery); - - int numInstances = 0; - while (rs.next()) { - numInstances = rs.getInt("numInstances"); - } - - return numInstances; - } catch (Exception e) { - throw new QueryServiceException( - "Failed to get size of query in Workflow Instances Database : " - + e.getMessage(), e); - } finally { - try { - conn.close(); - } catch (Exception ignored) { - } - try { - stmt.close(); - } catch (Exception ignored) { - } - try { - rs.close(); - } catch (Exception ignored) { - } - } - } - - private String getSqlQuery(QueryExpression queryExpression) throws QueryServiceException, UnsupportedEncodingException { - StringBuilder sqlQuery = new StringBuilder(); - if (queryExpression instanceof QueryLogicalGroup) { - QueryLogicalGroup qlg = (QueryLogicalGroup) queryExpression; - sqlQuery.append("(").append(this.getSqlQuery(qlg.getExpressions().get(0))); - String op = qlg.getOperator() == QueryLogicalGroup.Operator.AND ? "INTERSECT" : "UNION"; - for (int i = 1; i < qlg.getExpressions().size(); i++) { - sqlQuery.append(") ").append(op).append(" (").append(this.getSqlQuery(qlg.getExpressions().get(i))); - } - sqlQuery.append(")"); - }else if (queryExpression instanceof ComparisonQueryExpression){ - ComparisonQueryExpression cqe = (ComparisonQueryExpression) queryExpression; - String operator; - if (cqe.getOperator().equals(ComparisonQueryExpression.Operator.EQUAL_TO)) { - operator = "="; - } else if (cqe.getOperator().equals(ComparisonQueryExpression.Operator.GREATER_THAN)) { - operator = ">"; - } else if (cqe.getOperator().equals(ComparisonQueryExpression.Operator.GREATER_THAN_EQUAL_TO)) { - operator = ">="; - } else if (cqe.getOperator().equals(ComparisonQueryExpression.Operator.LESS_THAN)) { - operator = "<"; - } else if (cqe.getOperator().equals(ComparisonQueryExpression.Operator.LESS_THAN_EQUAL_TO)) { - operator = "<="; - } else { - throw new QueryServiceException("Invalid ComparisonQueryExpression Operator '" + cqe.getOperator() + "'"); - } - - sqlQuery.append( - "SELECT DISTINCT workflow_instance_id FROM workflow_instance_metadata WHERE " + "workflow_met_key = '") - .append(cqe.getTerm().getName()).append("' AND ("); - for (int i = 0; i < cqe.getTerm().getValues().size(); i++) { - String value = cqe.getTerm().getValues().get(i); - sqlQuery.append("workflow_met_val ").append(operator).append(" '") - .append(URLEncoder.encode(value, "UTF-8")).append("'"); - if ((i + 1) < cqe.getTerm().getValues().size()) { - sqlQuery.append("OR"); - } - } - sqlQuery.append(")"); - }else if (queryExpression instanceof NotQueryExpression) { - NotQueryExpression nqe = (NotQueryExpression) queryExpression; - sqlQuery.append("SELECT DISTINCT workflow_instance_id FROM workflow_instance_metadata WHERE NOT (") - .append(this - .getSqlQuery(nqe.getQueryExpression())).append(")"); - }else if (queryExpression instanceof StdQueryExpression) { - sqlQuery.append("SELECT DISTINCT workflow_instance_id FROM workflow_instance_metadata"); - }else { - throw new QueryServiceException("Invalid QueryExpression '" + queryExpression.getClass().getCanonicalName() + "'"); - } - return sqlQuery.toString(); - } - -}
http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/catalog/src/main/java/org/apache/oodt/cas/catalog/struct/impl/index/WorkflowManagerDataSourceIndexFactory.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/oodt/cas/catalog/struct/impl/index/WorkflowManagerDataSourceIndexFactory.java b/catalog/src/main/java/org/apache/oodt/cas/catalog/struct/impl/index/WorkflowManagerDataSourceIndexFactory.java deleted file mode 100644 index b7abe3c..0000000 --- a/catalog/src/main/java/org/apache/oodt/cas/catalog/struct/impl/index/WorkflowManagerDataSourceIndexFactory.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.oodt.cas.catalog.struct.impl.index; - -//OODT imports -import org.apache.oodt.cas.catalog.struct.IndexFactory; - -/** - * @author bfoster - * @version $Revision$ - * - */ -public class WorkflowManagerDataSourceIndexFactory implements IndexFactory { - - protected String jdbcUrl; - protected String user; - protected String pass; - protected String driver; - - public WorkflowManagerDataSourceIndex createIndex() { - try { - return new WorkflowManagerDataSourceIndex(this.user, this.pass, this.driver, this.jdbcUrl); - }catch (Exception e) { - //log - return null; - } - } - - public void setJdbcUrl(String jdbcUrl) { - this.jdbcUrl = jdbcUrl; - } - - public void setUser(String user) { - this.user = user; - } - - public void setPass(String pass) { - this.pass = pass; - } - - public void setDriver(String driver) { - this.driver = driver; - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/catalog/src/main/java/org/apache/oodt/cas/catalog/struct/impl/transaction/LongTransactionIdFactory.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/oodt/cas/catalog/struct/impl/transaction/LongTransactionIdFactory.java b/catalog/src/main/java/org/apache/oodt/cas/catalog/struct/impl/transaction/LongTransactionIdFactory.java deleted file mode 100644 index 1d8a573..0000000 --- a/catalog/src/main/java/org/apache/oodt/cas/catalog/struct/impl/transaction/LongTransactionIdFactory.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.oodt.cas.catalog.struct.impl.transaction; - -//OODT imports -import org.apache.oodt.cas.catalog.struct.TransactionId; -import org.apache.oodt.cas.catalog.struct.TransactionIdFactory; - -/** - * @author bfoster - * @version $Revision$ - * - */ -public class LongTransactionIdFactory implements TransactionIdFactory { - - public TransactionId<?> createNewTransactionId() { - return new TransactionId<Long>(System.currentTimeMillis()) { - - @Override - protected Long fromString(String stringId) { - return Long.parseLong(stringId); - } - - }; - } - - public TransactionId<?> createTransactionId(String transactionIdString) { - return new TransactionId<Long>(transactionIdString) { - - @Override - protected Long fromString(String stringId) { - return Long.parseLong(stringId); - } - - }; - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/catalog/src/main/java/org/apache/oodt/cas/catalog/struct/impl/transaction/StringTransactionIdFactory.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/oodt/cas/catalog/struct/impl/transaction/StringTransactionIdFactory.java b/catalog/src/main/java/org/apache/oodt/cas/catalog/struct/impl/transaction/StringTransactionIdFactory.java deleted file mode 100644 index 8e1bc18..0000000 --- a/catalog/src/main/java/org/apache/oodt/cas/catalog/struct/impl/transaction/StringTransactionIdFactory.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.oodt.cas.catalog.struct.impl.transaction; - -//OODT imports -import org.apache.oodt.cas.catalog.struct.TransactionId; -import org.apache.oodt.cas.catalog.struct.TransactionIdFactory; - -/** - * @author bfoster - * @version $Revision$ - * - */ -public class StringTransactionIdFactory implements TransactionIdFactory { - - public TransactionId<String> createNewTransactionId() { - return new StringTransactionId(Long.toString(System.currentTimeMillis())); - } - - public TransactionId<?> createTransactionId(String transactionIdString) { - return new StringTransactionId(transactionIdString); - } - - private class StringTransactionId extends TransactionId<String> { - - public StringTransactionId(String stringValue) { - this.nativeId = stringValue; - } - - @Override - protected String fromString(String stringId) { - return stringId; - } - - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/catalog/src/main/java/org/apache/oodt/cas/catalog/struct/impl/transaction/UuidTransactionIdFactory.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/oodt/cas/catalog/struct/impl/transaction/UuidTransactionIdFactory.java b/catalog/src/main/java/org/apache/oodt/cas/catalog/struct/impl/transaction/UuidTransactionIdFactory.java deleted file mode 100644 index 96aeda8..0000000 --- a/catalog/src/main/java/org/apache/oodt/cas/catalog/struct/impl/transaction/UuidTransactionIdFactory.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.oodt.cas.catalog.struct.impl.transaction; - -//JDK imports -import java.util.UUID; - -//OODT imports -import org.apache.oodt.cas.catalog.struct.TransactionId; -import org.apache.oodt.cas.catalog.struct.TransactionIdFactory; - -/** - * @author bfoster - * @version $Revision$ - * - */ -public class UuidTransactionIdFactory implements TransactionIdFactory { - - public TransactionId<?> createNewTransactionId() { - return new TransactionId<UUID>(UUID.randomUUID()) { - - @Override - protected UUID fromString(String stringId) { - return UUID.fromString(stringId); - } - - }; - } - - public TransactionId<?> createTransactionId(String transactionIdString) { - return new TransactionId<UUID>(transactionIdString) { - - @Override - protected UUID fromString(String stringId) { - return UUID.fromString(stringId); - } - - }; - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/catalog/src/main/java/org/apache/oodt/cas/catalog/system/Catalog.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/oodt/cas/catalog/system/Catalog.java b/catalog/src/main/java/org/apache/oodt/cas/catalog/system/Catalog.java deleted file mode 100644 index c292672..0000000 --- a/catalog/src/main/java/org/apache/oodt/cas/catalog/system/Catalog.java +++ /dev/null @@ -1,399 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.oodt.cas.catalog.system; - -//OODT imports -import org.apache.oodt.cas.catalog.exception.CatalogException; -import org.apache.oodt.cas.catalog.exception.CatalogIndexException; -import org.apache.oodt.cas.catalog.page.CatalogReceipt; -import org.apache.oodt.cas.catalog.page.IndexPager; -import org.apache.oodt.cas.catalog.page.IngestReceipt; -import org.apache.oodt.cas.catalog.query.QueryExpression; -import org.apache.oodt.cas.catalog.struct.Dictionary; -import org.apache.oodt.cas.catalog.struct.Index; -import org.apache.oodt.cas.catalog.struct.IngestService; -import org.apache.oodt.cas.catalog.struct.QueryService; -import org.apache.oodt.cas.catalog.struct.TransactionId; -import org.apache.oodt.cas.catalog.struct.TransactionIdFactory; -import org.apache.oodt.cas.catalog.term.Term; -import org.apache.oodt.cas.catalog.term.TermBucket; -import org.apache.oodt.cas.metadata.Metadata; - -import java.util.Collections; -import java.util.concurrent.ConcurrentHashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Vector; -import java.util.logging.Level; -import java.util.logging.Logger; - -//JDK imports - - -/** - * @author bfoster - * @version $Revision$ - * - * <p> - * A Calatog is a communication interface between the CatalogService and an underlying - * database or index service - * <p> - */ -public class Catalog { - - private static Logger LOG = Logger.getLogger(Catalog.class.getName()); - - protected Vector<Dictionary> dictionaries; - protected Index index; - protected String id; - protected boolean restrictQueryPermissions = true; - protected boolean restrictIngestPermissions = true; - - public Catalog(String id, Index index, List<Dictionary> dictionaries, boolean restrictQueryPermissions, boolean restrictIngestPermissions) { - this.id = id; - this.index = index; - if (dictionaries != null) { - this.dictionaries = new Vector<Dictionary>(dictionaries); - } - this.restrictQueryPermissions = restrictQueryPermissions; - this.restrictIngestPermissions = restrictIngestPermissions; - } - - public String getId() { - return this.id; - } - - public TransactionIdFactory getTransactionIdFactory() { - return this.index.getTransactionIdFactory(); - } - - public void setIndex(Index index) { - this.index = index; - } - - public void setDictionaries(List<Dictionary> dictionaries) { - this.dictionaries = new Vector<Dictionary>(dictionaries); - } - - public List<Dictionary> getDictionaries() { - return Collections.unmodifiableList(this.dictionaries); - } - - public void addDictionary(Dictionary dictionary) { - if (this.dictionaries == null) { - this.dictionaries = new Vector<Dictionary>(); - } - this.dictionaries.add(dictionary); - } - - public void setRestrictQueryPermissions(boolean restrictQueryPermissions) { - this.restrictQueryPermissions = restrictQueryPermissions; - } - - public void setRestrictIngestPermissions(boolean restrictIngestPermissions) { - this.restrictIngestPermissions = restrictIngestPermissions; - } - - public boolean isQueriable() { - return this.index instanceof QueryService && !this.restrictQueryPermissions; - } - - public boolean isIngestable() { - return this.index instanceof IngestService && !this.restrictIngestPermissions; - } - - public List<TransactionId<?>> getPage(IndexPager indexPage) { - return this.index.getPage(indexPage); - } - - public TransactionId<?> getTransactionIdFromString(String catalogTransactionId) throws IllegalArgumentException, SecurityException, - CatalogIndexException { - return this.getTransactionIdFactory().createTransactionId(catalogTransactionId); - } - - public boolean hasTransactionId(TransactionId<?> catalogTransactionid) throws CatalogIndexException { - return this.index.hasTransactionId(catalogTransactionid); - } - - public String getProperty(String key) throws CatalogException { - try { - return this.index.getProperty(key); - }catch (Exception e) { - throw new CatalogException("Failed to get property '" + key + "' : " + e.getMessage(), e); - } - } - - public Properties getProperties() throws CatalogException { - try { - return this.index.getProperties(); - }catch (Exception e) { - throw new CatalogException("Failed to get properties : " + e.getMessage(), e); - } - } - - /** - * - * @param metadata - * @return TransactionId param if used by underlying catalog, otherwise - * the TransactionId generated and used by underlying catalog. if no - * TermBuckets where created from the Metadata then null is returned - * @throws CatalogException - */ - public CatalogReceipt ingest(Metadata metadata) throws CatalogException { - try { - if (this.isIngestable()) { - List<TermBucket> termBuckets = this.getTermBuckets(metadata); - if (termBuckets.size() > 0) { - LOG.log(Level.INFO, "Catalog '" + this + "' attemping ingest metadata"); - return new CatalogReceipt(((IngestService) this.index).ingest(termBuckets), this.getId()); - }else { - LOG.log(Level.WARNING, "Catalog '" + this + "' dictionaries did not generate any TermBuckets from Metadata"); - return null; - } - }else { - LOG.log(Level.WARNING, "Catalog '" + this + "' is not ingestable"); - return null; - } - }catch (Exception e) { - throw new CatalogException(e.getMessage(), e); - } - } - - public CatalogReceipt update(TransactionId<?> transactionId, Metadata metadata) throws CatalogException { - try { - if (this.isIngestable()) { - List<TermBucket> termBuckets = this.getTermBuckets(metadata); - if (termBuckets.size() > 0) { - LOG.log(Level.INFO, "Catalog '" + this + "' attemping update metadata for catalog TransactionId [id = '" + transactionId + "']"); - IngestReceipt ingestReceipt = ((IngestService) this.index).update(transactionId, termBuckets); - if (ingestReceipt != null) { - return new CatalogReceipt(ingestReceipt, this.getId()); - } else { - return null; - } - }else { - LOG.log(Level.WARNING, "Catalog '" + this + "' did not generate any TermBuckets from Metadata for catalog TransactionId [id = '" + transactionId + "']"); - return null; - } - }else { - LOG.log(Level.WARNING, "Catalog '" + this + "' is not ingestable"); - return null; - } - }catch (Exception e) { - throw new CatalogException(e.getMessage(), e); - } - } - - public boolean delete(TransactionId<?> transactionId) throws CatalogException { - try { - if (this.isIngestable()) { - LOG.log(Level.INFO, "Catalog '" + this + "' attemping to delete all TermBuckets associated with catalog TransactionId [id = '" + transactionId + "']"); - return ((IngestService) this.index).delete(transactionId); - }else { - LOG.log(Level.WARNING, "Catalog '" + this + "' is not ingestable"); - return false; - } - }catch (Exception e) { - throw new CatalogException(e.getMessage(), e); - } - } - - public boolean reduce(TransactionId<?> transactionId, Metadata metadata) throws CatalogException { - try { - if (this.isIngestable()) { - List<TermBucket> termBuckets = this.getTermBuckets(metadata); - if (termBuckets.size() > 0) { - LOG.log(Level.INFO, "Catalog '" + this + "' attemping reduce metadata for catalog TransactionId [id = '" + transactionId + "']"); - return ((IngestService) this.index).reduce(transactionId, termBuckets); - }else { - LOG.log(Level.WARNING, "Catalog '" + this + "' did not generate any TermBuckets from Metadata for catalog TransactionId [id = '" + transactionId + "'] -- no metadata reduction took place"); - return false; - } - }else { - LOG.log(Level.WARNING, "Catalog '" + this + "' is not ingestable"); - return false; - } - }catch(Exception e) { - throw new CatalogException(e.getMessage(), e); - } - } - - public List<CatalogReceipt> query(QueryExpression queryExpression) throws CatalogException { - try { - if (this.isQueriable()) { - QueryService queryService = (QueryService) this.index; - List<CatalogReceipt> catalogReceipts = new Vector<CatalogReceipt>(); - for (IngestReceipt ingestReceipt : queryService.query(queryExpression)) { - catalogReceipts.add(new CatalogReceipt(ingestReceipt, this.getId())); - } - return Collections.unmodifiableList(catalogReceipts); - }else { - LOG.log(Level.WARNING, "Catalog '" + this + "' is not queriable"); - return Collections.emptyList(); - } - }catch (Exception e) { - throw new CatalogException(e.getMessage(), e); - } - } - - - public List<CatalogReceipt> query(QueryExpression queryExpression, int startIndex, int endIndex) throws CatalogException { - try { - if (this.isQueriable()) { - QueryService queryService = (QueryService) this.index; - List<CatalogReceipt> catalogReceipts = new Vector<CatalogReceipt>(); - for (IngestReceipt ingestReceipt : queryService.query(queryExpression, startIndex, endIndex)) { - catalogReceipts.add(new CatalogReceipt(ingestReceipt, this.getId())); - } - return Collections.unmodifiableList(catalogReceipts); - }else { - LOG.log(Level.WARNING, "Catalog '" + this + "' is not queriable"); - return Collections.emptyList(); - } - }catch (Exception e) { - throw new CatalogException(e.getMessage(), e); - } - } - - public int sizeOf(QueryExpression queryExpression) throws CatalogException { - try { - if (this.isQueriable()) { - QueryService queryService = (QueryService) this.index; - return queryService.sizeOf(queryExpression); - }else { - LOG.log(Level.WARNING, "Catalog '" + this + "' is not queriable"); - return 0; - } - }catch (Exception e) { - throw new CatalogException(e.getMessage(), e); - } - } - - public Metadata getMetadata(TransactionId<?> transactionId) throws CatalogException { - try { - if (this.isQueriable()) { - QueryService queryService = (QueryService) this.index; - return this.getMetadataFromBuckets(queryService.getBuckets(transactionId)); - }else { - LOG.log(Level.WARNING, "Catalog '" + this + "' is not queriable"); - return new Metadata(); - } - }catch(Exception e) { - throw new CatalogException(e.getMessage(), e); - } - } - - public Map<TransactionId<?>, Metadata> getMetadata(List<TransactionId<?>> transactionIds) throws CatalogException { - try { - Map<TransactionId<?>, Metadata> metadataMap = new ConcurrentHashMap<TransactionId<?>, Metadata>(); - if (this.isQueriable()) { - QueryService queryService = (QueryService) this.index; - Map<TransactionId<?>, List<TermBucket>> termBucketMap = queryService.getBuckets(transactionIds); - - for(Map.Entry<TransactionId<?>, List<TermBucket>> entry : termBucketMap.entrySet()){ - metadataMap.put(entry.getKey(), this.getMetadataFromBuckets(entry.getValue())); - } - }else { - LOG.log(Level.WARNING, "Catalog '" + this + "' is not queriable"); - } - return metadataMap; - }catch(Exception e) { - throw new CatalogException(e.getMessage(), e); - } - } - - public boolean isInterested(QueryExpression queryExpression) throws CatalogException { - try { - if (this.dictionaries != null) { - for (Dictionary dictionary : this.dictionaries) { - if (dictionary.understands(queryExpression)) { - return true; - } - } - return false; - }else { - return true; - } - }catch(Exception e) { - throw new CatalogException(e.getMessage(), e); - } - } - - protected Metadata getMetadataFromBuckets(List<TermBucket> termBuckets) { - Metadata metadata = new Metadata(); - for (TermBucket termBucket : termBuckets) { - if (this.dictionaries != null) { - for (Dictionary dictionary : this.dictionaries) { - metadata.addMetadata(dictionary.reverseLookup(termBucket)); - } - }else { - metadata.addMetadata(this.asMetadata(termBuckets)); - } - } - return metadata; - } - - protected Metadata asMetadata(List<TermBucket> termBuckets) { - Metadata m = new Metadata(); - for (TermBucket bucket : termBuckets) { - for (Term term : bucket.getTerms()) { - m.addMetadata(term.getName(), term.getValues()); - } - } - return m; - } - - protected List<TermBucket> getTermBuckets(Metadata metadata) { - List<TermBucket> termBuckets = new Vector<TermBucket>(); - if (this.dictionaries != null) { - for (Dictionary dictionary : this.dictionaries) { - TermBucket termBucket = dictionary.lookup(metadata); - if (termBucket != null) { - termBuckets.add(termBucket); - } - } - }else { - LOG.log(Level.WARNING, "Catalog '" + this + "' has no dictionaries defined, attempting to send all Metadata in a default TermBucket"); - TermBucket bucket = new TermBucket(); - for (String key : metadata.getAllKeys()) { - bucket.addTerm(new Term(key, metadata.getAllMetadata(key))); - } - termBuckets.add(bucket); - } - return termBuckets; - } - - public int hashCode() { - return this.toString().hashCode(); - } - - public boolean equals(Object obj) { - if (obj instanceof Catalog) { - return ((Catalog) obj).getId().equals(this.getId()); - } else if (obj instanceof String) { - return this.getId().equals((String) obj); - } else { - return false; - } - } - - public String toString() { - return this.getId(); - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/catalog/src/main/java/org/apache/oodt/cas/catalog/system/CatalogFactory.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/oodt/cas/catalog/system/CatalogFactory.java b/catalog/src/main/java/org/apache/oodt/cas/catalog/system/CatalogFactory.java deleted file mode 100644 index f540239..0000000 --- a/catalog/src/main/java/org/apache/oodt/cas/catalog/system/CatalogFactory.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.oodt.cas.catalog.system; - -//JDK imports -import java.util.List; -import java.util.Vector; - -//OOD imports -import org.apache.oodt.cas.catalog.struct.Dictionary; -import org.apache.oodt.cas.catalog.struct.DictionaryFactory; -import org.apache.oodt.cas.catalog.struct.IndexFactory; - -//Spring imports -import org.springframework.beans.factory.annotation.Required; - -/** - * @author bfoster - * @version $Revision$ - * - */ -public class CatalogFactory { - - protected String catalogId; - protected IndexFactory indexFactory; - protected List<DictionaryFactory> dictionaryFactories; - protected boolean restrictQueryPermissions; - protected boolean restrictIngestPermissions; - - public Catalog createCatalog() { - Vector<Dictionary> dictionaries = null; - if (this.dictionaryFactories != null) { - dictionaries = new Vector<Dictionary>(); - for (DictionaryFactory dictionaryFactory : this.dictionaryFactories) { - dictionaries.add(dictionaryFactory.createDictionary()); - } - } - return new Catalog(this.catalogId, this.indexFactory.createIndex(), dictionaries, this.restrictQueryPermissions, this.restrictIngestPermissions); - } - - @Required - public void setCatalogId(String catalogId) { - this.catalogId = catalogId; - } - - @Required - public void setIndexFactory(IndexFactory indexFactory) { - this.indexFactory = indexFactory; - } - - @Required - public void setDictionaryFactories(List<DictionaryFactory> dictionaryFactories) { - this.dictionaryFactories = dictionaryFactories; - } - - @Required - public void setRestrictQueryPermissions(boolean restrictQueryPermissions) { - this.restrictQueryPermissions = restrictQueryPermissions; - } - - @Required - public void setRestrictIngestPermissions(boolean restrictIngestPermissions) { - this.restrictIngestPermissions = restrictIngestPermissions; - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/catalog/src/main/java/org/apache/oodt/cas/catalog/system/CatalogService.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/oodt/cas/catalog/system/CatalogService.java b/catalog/src/main/java/org/apache/oodt/cas/catalog/system/CatalogService.java deleted file mode 100644 index 28d8ebb..0000000 --- a/catalog/src/main/java/org/apache/oodt/cas/catalog/system/CatalogService.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.oodt.cas.catalog.system; - -//JDK imports -import java.net.URL; -import java.util.List; -import java.util.Properties; -import java.util.Set; - -//OODT imports -import org.apache.oodt.cas.catalog.exception.CatalogServiceException; -import org.apache.oodt.cas.catalog.metadata.TransactionalMetadata; -import org.apache.oodt.cas.catalog.page.CatalogReceipt; -import org.apache.oodt.cas.catalog.page.Page; -import org.apache.oodt.cas.catalog.page.PageInfo; -import org.apache.oodt.cas.catalog.page.QueryPager; -import org.apache.oodt.cas.catalog.page.TransactionReceipt; -import org.apache.oodt.cas.catalog.query.QueryExpression; -import org.apache.oodt.cas.catalog.struct.Dictionary; -import org.apache.oodt.cas.catalog.struct.Index; -import org.apache.oodt.cas.catalog.struct.TransactionId; -import org.apache.oodt.cas.catalog.util.PluginURL; -import org.apache.oodt.cas.metadata.Metadata; - -/** - * @author bfoster - * @version $Revision$ - * - * <p> - * An interface for a Metadata Catalog Manager Service - * <p> - */ -public interface CatalogService { - - String CATALOG_SERVICE_TRANSACTION_ID_MET_KEY = "urn:CatalogService:TransactionId"; - String CATALOG_IDS_MET_KEY = "urn:CatalogService:CatalogIds"; - String ENABLE_UPDATE_MET_KEY = "urn:CatalogService:EnableUpdate"; - String CATALOG_TRANSACTION_ID_MET_KEY = "urn:Catalog:TransactionId"; - String CATALOG_ID_MET_KEY = "urn:Catalog:Id"; - - void shutdown() throws CatalogServiceException; - - boolean isRestrictQueryPermissions() throws CatalogServiceException; - - boolean isRestrictIngestPermissions() throws CatalogServiceException; - - void addCatalog(Catalog catalog) throws CatalogServiceException; - - void replaceCatalog(Catalog catalog) throws CatalogServiceException; - - void addCatalog(String catalogId, Index index) throws CatalogServiceException; - - void addCatalog(String catalogId, Index index, List<Dictionary> dictionaries) throws CatalogServiceException; - - void addCatalog(String catalogId, Index index, List<Dictionary> dictionaries, boolean restrictQueryPermission, - boolean restrictIngestPermission) throws CatalogServiceException; - - void addDictionary(String catalogId, Dictionary dictionary) throws CatalogServiceException; - - void replaceDictionaries(String catalogId, List<Dictionary> dictionaries) throws CatalogServiceException; - - void replaceIndex(String catalogId, Index index) throws CatalogServiceException; - - void modifyIngestPermission(String catalogId, boolean restrictIngestPermission) throws CatalogServiceException; - - void modifyQueryPermission(String catalogId, boolean restrictQueryPermission) throws CatalogServiceException; - - void removeCatalog(String catalogId) throws CatalogServiceException; - - URL getPluginStorageDir() throws CatalogServiceException; - - List<PluginURL> getPluginUrls() throws CatalogServiceException; - - void addPluginUrls(List<PluginURL> pluginURLs) throws CatalogServiceException; - - Set<String> getCurrentCatalogIds() throws CatalogServiceException; - - TransactionReceipt ingest(Metadata metadata) throws CatalogServiceException; - - void delete(Metadata metadata) throws CatalogServiceException; - - List<String> getProperty(String key) throws CatalogServiceException; - - Properties getCalalogProperties() throws CatalogServiceException; - - Properties getCalalogProperties(String catalogUrn) throws CatalogServiceException; - - Page getNextPage(Page page) throws CatalogServiceException; - - Page getPage(PageInfo pageInfo, QueryExpression queryExpression) throws CatalogServiceException; - - Page getPage(PageInfo pageInfo, QueryExpression queryExpression, Set<String> catalogIds) throws CatalogServiceException; - - List<TransactionalMetadata> getMetadata(Page page) throws CatalogServiceException; - - QueryPager query(QueryExpression queryExpression) throws CatalogServiceException; - - QueryPager query(QueryExpression queryExpression, Set<String> catalogIds) throws CatalogServiceException; - - List<TransactionalMetadata> getNextPage(QueryPager queryPager) throws CatalogServiceException; - - List<TransactionalMetadata> getAllPages(QueryPager queryPager) throws CatalogServiceException; - - List<TransactionalMetadata> getMetadataFromTransactionIdStrings(List<String> catalogServiceTransactionIdStrings) throws CatalogServiceException; - - List<TransactionalMetadata> getMetadataFromTransactionIds(List<TransactionId<?>> catalogServiceTransactionIds) throws CatalogServiceException; - - List<TransactionId<?>> getCatalogServiceTransactionIds(List<TransactionId<?>> catalogTransactionIds, - String catalogUrn) throws CatalogServiceException; - - TransactionId<?> getCatalogServiceTransactionId(TransactionId<?> catalogTransactionId, String catalogUrn) throws CatalogServiceException; - - TransactionId<?> getCatalogServiceTransactionId(CatalogReceipt catalogReceipt, boolean generateNew) throws CatalogServiceException; - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/catalog/src/main/java/org/apache/oodt/cas/catalog/system/CatalogServiceFactory.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/oodt/cas/catalog/system/CatalogServiceFactory.java b/catalog/src/main/java/org/apache/oodt/cas/catalog/system/CatalogServiceFactory.java deleted file mode 100644 index 360e098..0000000 --- a/catalog/src/main/java/org/apache/oodt/cas/catalog/system/CatalogServiceFactory.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.oodt.cas.catalog.system; - -/** - * @author bfoster - * @version $Revision$ - * - * <p> - * A Factory for CatalogService - * <p> - */ -public interface CatalogServiceFactory { - - CatalogService createCatalogService(); - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/catalog/src/main/java/org/apache/oodt/cas/catalog/system/impl/CatalogServiceClient.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/oodt/cas/catalog/system/impl/CatalogServiceClient.java b/catalog/src/main/java/org/apache/oodt/cas/catalog/system/impl/CatalogServiceClient.java deleted file mode 100644 index 623d8b0..0000000 --- a/catalog/src/main/java/org/apache/oodt/cas/catalog/system/impl/CatalogServiceClient.java +++ /dev/null @@ -1,407 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.oodt.cas.catalog.system.impl; - -//JDK imports -import java.io.File; -import java.net.URL; -import java.util.List; -import java.util.Properties; -import java.util.Set; -import java.util.Vector; - -//OODT imports -import org.apache.oodt.cas.catalog.exception.CatalogServiceException; -import org.apache.oodt.cas.catalog.metadata.TransactionalMetadata; -import org.apache.oodt.cas.catalog.page.CatalogReceipt; -import org.apache.oodt.cas.catalog.page.Page; -import org.apache.oodt.cas.catalog.page.PageInfo; -import org.apache.oodt.cas.catalog.page.QueryPager; -import org.apache.oodt.cas.catalog.page.TransactionReceipt; -import org.apache.oodt.cas.catalog.query.QueryExpression; -import org.apache.oodt.cas.catalog.server.channel.CommunicationChannelClient; -import org.apache.oodt.cas.catalog.struct.Dictionary; -import org.apache.oodt.cas.catalog.struct.Index; -import org.apache.oodt.cas.catalog.struct.TransactionId; -import org.apache.oodt.cas.catalog.system.Catalog; -import org.apache.oodt.cas.catalog.system.CatalogService; -import org.apache.oodt.cas.catalog.util.PluginURL; -import org.apache.oodt.cas.metadata.Metadata; - -/** - * @author bfoster - * @version $Revision$ - * - * <p> - * A Client that appears to be a CatalogService, but communicates with a CatalogService Server - * <p> - */ -public class CatalogServiceClient implements CatalogService { - - protected CommunicationChannelClient communicationChannelClient; - protected int autoPagerSize; - - public CatalogServiceClient(CommunicationChannelClient communicationChannelClient, int autoPagerSize) { - this.communicationChannelClient = communicationChannelClient; - this.autoPagerSize = autoPagerSize; - } - - public void shutdown() throws CatalogServiceException { - try { - this.communicationChannelClient.shutdown(); - }catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - protected List<PluginURL> transferToServerSide(List<PluginURL> clientSideUrls) throws CatalogServiceException { - try { - URL customUrlStorageDir = this.communicationChannelClient.getPluginStorageDir(); - System.out.println("Got Tmp dir : " + customUrlStorageDir); - Vector<PluginURL> serverSideUrls = new Vector<PluginURL>(); - for (PluginURL pluginURL : clientSideUrls) { - PluginURL serverSideURL = new PluginURL(pluginURL.getCatalogId(), new URL(customUrlStorageDir, new File(pluginURL.getURL().getFile()).getName())); - System.out.println("generated server side url : " + customUrlStorageDir); - this.communicationChannelClient.transferUrl(pluginURL.getURL(), serverSideURL.getURL()); - serverSideUrls.add(serverSideURL); - } - return serverSideUrls; - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public void addCatalog(Catalog catalog) throws CatalogServiceException { - try { - this.communicationChannelClient.addCatalog(catalog); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public void replaceCatalog(Catalog catalog) - throws CatalogServiceException { - try { - this.communicationChannelClient.replaceCatalog(catalog); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public void addCatalog(String catalogId, Index index) - throws CatalogServiceException { - try { - this.communicationChannelClient.addCatalog(catalogId, index); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public void addCatalog(String catalogId, Index index, List<Dictionary> dictionaries) throws CatalogServiceException { - try { - this.communicationChannelClient.addCatalog(catalogId, index, dictionaries); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public void addCatalog(String catalogId, Index index, List<Dictionary> dictionaries, boolean restrictQueryPermission, - boolean restrictIngestPermission) throws CatalogServiceException { - try { - this.communicationChannelClient.addCatalog(catalogId, index, dictionaries, restrictQueryPermission, restrictIngestPermission); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public void addDictionary(String catalogId, Dictionary dictionary) - throws CatalogServiceException { - try { - this.communicationChannelClient.addDictionary(catalogId, dictionary); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public void replaceDictionaries(String catalogId, List<Dictionary> dictionaries) throws CatalogServiceException { - try { - this.communicationChannelClient.replaceDictionaries(catalogId, dictionaries); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public void modifyIngestPermission(String catalogId, - boolean restrictIngestPermission) throws CatalogServiceException { - try { - this.communicationChannelClient.modifyIngestPermission(catalogId, restrictIngestPermission); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public void modifyQueryPermission(String catalogId, - boolean restrictQueryPermission) throws CatalogServiceException { - try { - this.communicationChannelClient.modifyQueryPermission(catalogId, restrictQueryPermission); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public void replaceIndex(String catalogId, Index index) - throws CatalogServiceException { - try { - this.communicationChannelClient.replaceIndex(catalogId, index); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public void removeCatalog(String catalogId) throws CatalogServiceException { - try { - this.communicationChannelClient.removeCatalog(catalogId); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public URL getPluginStorageDir() throws CatalogServiceException { - try { - return this.communicationChannelClient.getPluginStorageDir(); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public List<PluginURL> getPluginUrls() throws CatalogServiceException { - try { - return this.communicationChannelClient.getPluginUrls(); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public void addPluginUrls(List<PluginURL> urls) throws CatalogServiceException { - try { - this.communicationChannelClient.addPluginUrls(this.transferToServerSide(urls)); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public void delete(Metadata metadata) throws CatalogServiceException { - try { - this.communicationChannelClient.delete(metadata); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public List<TransactionalMetadata> getAllPages(QueryPager queryPager) - throws CatalogServiceException { - try { - List<TransactionalMetadata> metadata = new Vector<TransactionalMetadata>(); - if (queryPager.getTotalPages() > 0) { - queryPager.setPageInfo(new PageInfo(this.autoPagerSize, PageInfo.FIRST_PAGE)); - while (!queryPager.isLastPage()) { - metadata.addAll(this.communicationChannelClient.getNextPage(queryPager)); - queryPager.incrementPageNumber(); - } - metadata.addAll(this.communicationChannelClient.getNextPage(queryPager)); - } - return metadata; - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public Properties getCalalogProperties() throws CatalogServiceException { - try { - return this.communicationChannelClient.getCalalogProperties(); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public Properties getCalalogProperties(String catalogUrn) - throws CatalogServiceException { - try { - return this.communicationChannelClient.getCalalogProperties(catalogUrn); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public TransactionId<?> getCatalogServiceTransactionId( - TransactionId<?> catalogTransactionId, String catalogUrn) - throws CatalogServiceException { - try { - return this.communicationChannelClient.getCatalogServiceTransactionId(catalogTransactionId, catalogUrn); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public TransactionId<?> getCatalogServiceTransactionId( - CatalogReceipt catalogReceipt, boolean generateNew) throws CatalogServiceException { - try { - return this.communicationChannelClient.getCatalogServiceTransactionId(catalogReceipt, generateNew); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public List<TransactionId<?>> getCatalogServiceTransactionIds( - List<TransactionId<?>> catalogTransactionIds, String catalogUrn) - throws CatalogServiceException { - try { - return this.communicationChannelClient.getCatalogServiceTransactionIds(catalogTransactionIds, catalogUrn); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public Set<String> getCurrentCatalogIds() throws CatalogServiceException { - try { - return this.communicationChannelClient.getCurrentCatalogIds(); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public List<TransactionalMetadata> getMetadataFromTransactionIdStrings( - List<String> catalogServiceTransactionIdStrings) - throws CatalogServiceException { - try { - return this.communicationChannelClient.getMetadataFromTransactionIdStrings(catalogServiceTransactionIdStrings); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public List<TransactionalMetadata> getMetadataFromTransactionIds( - List<TransactionId<?>> catalogServiceTransactionIds) - throws CatalogServiceException { - try { - return this.communicationChannelClient.getMetadataFromTransactionIds(catalogServiceTransactionIds); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public List<TransactionalMetadata> getNextPage(QueryPager queryPager) - throws CatalogServiceException { - try { - return this.communicationChannelClient.getNextPage(queryPager); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public List<String> getProperty(String key) throws CatalogServiceException { - try { - return this.communicationChannelClient.getProperty(key); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public List<TransactionId<?>> getTransactionIdsForAllPages( - QueryPager queryPager) throws CatalogServiceException { - try { - return this.communicationChannelClient.getTransactionIdsForAllPages(queryPager); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public TransactionReceipt ingest(Metadata metadata) - throws CatalogServiceException { - try { - return this.communicationChannelClient.ingest(metadata); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public boolean isRestrictIngestPermissions() throws CatalogServiceException { - try { - return this.communicationChannelClient.isRestrictIngestPermissions(); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public boolean isRestrictQueryPermissions() throws CatalogServiceException { - try { - return this.communicationChannelClient.isRestrictQueryPermissions(); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public Page getNextPage(Page page) throws CatalogServiceException { - try { - return this.communicationChannelClient.getNextPage(page); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public Page getPage(PageInfo pageInfo, QueryExpression queryExpression) throws CatalogServiceException { - try { - return this.communicationChannelClient.getPage(pageInfo, queryExpression); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public Page getPage(PageInfo pageInfo, QueryExpression queryExpression, Set<String> catalogIds) throws CatalogServiceException { - try { - return this.communicationChannelClient.getPage(pageInfo, queryExpression, catalogIds); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public List<TransactionalMetadata> getMetadata(Page page) throws CatalogServiceException { - try { - return this.communicationChannelClient.getMetadata(page); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public QueryPager query(QueryExpression queryExpression) - throws CatalogServiceException { - try { - return this.communicationChannelClient.query(queryExpression); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - - public QueryPager query(QueryExpression queryExpression, Set<String> catalogIds) throws CatalogServiceException { - try { - return this.communicationChannelClient.query(queryExpression, catalogIds); - } catch (Exception e) { - throw new CatalogServiceException(e.getMessage(), e); - } - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/catalog/src/main/java/org/apache/oodt/cas/catalog/system/impl/CatalogServiceClientFactory.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/oodt/cas/catalog/system/impl/CatalogServiceClientFactory.java b/catalog/src/main/java/org/apache/oodt/cas/catalog/system/impl/CatalogServiceClientFactory.java deleted file mode 100644 index 78b5d33..0000000 --- a/catalog/src/main/java/org/apache/oodt/cas/catalog/system/impl/CatalogServiceClientFactory.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.oodt.cas.catalog.system.impl; - -//OODT imports -import org.apache.oodt.cas.catalog.server.channel.CommunicationChannelClientFactory; -import org.apache.oodt.cas.catalog.system.CatalogServiceFactory; - -//Spring imports -import org.springframework.beans.factory.annotation.Required; - -//OODT imports - -/** - * @author bfoster - * @version $Revision$ - * - * <p> - * A Factory for CatalogServiceClient - * <p> - */ -public class CatalogServiceClientFactory implements CatalogServiceFactory { - - public static final int INT = 500; - protected CommunicationChannelClientFactory communicationChannelClientFactory; - protected int autoPagerSize; - - public CatalogServiceClientFactory() { - this.autoPagerSize = INT; - } - - public CatalogServiceClient createCatalogService() { - return new CatalogServiceClient(this.communicationChannelClientFactory.createCommunicationChannelClient(), this.autoPagerSize); - } - - @Required - public void setCommunicationChannelClientFactory(CommunicationChannelClientFactory communicationChannelClientFactory) { - this.communicationChannelClientFactory = communicationChannelClientFactory; - } - - @Required - public void setAutoPagerSize(int autoPagerSize) { - if (autoPagerSize > 0) { - this.autoPagerSize = autoPagerSize; - } - } - - public String getServerUrl() { - return this.communicationChannelClientFactory.getServerUrl(); - } - -}
