private int doDelete( MetadataStoreTransaction ta, DeleteOperation delete ) throws MetadataStoreException { int i = ta.performDelete( delete ); LOG.info( "Delete done!" ); return i; }
private int doUpdate( MetadataStoreTransaction ta, UpdateOperation update ) throws MetadataStoreException, MetadataInspectorException { int i = ta.performUpdate( update ); LOG.info( "Update done!" ); return i; }
private List<String> doInsert( MetadataStoreTransaction ta, InsertOperation insert ) throws MetadataStoreException, OWSException, MetadataInspectorException { // TODO the first element determines the metadataStore // String uri = insert.getElements().get( 0 ).getNamespace().getNamespaceURI(); // String localName = insert.getElements().get( 0 ).getLocalName(); // String prefix = insert.getElements().get( 0 ).getNamespace().getPrefix(); List<String> ids = ta.performInsert( insert ); LOG.debug( "inserted metadata: " + ids ); LOG.info( "Insert done!" ); return ids; }
MetadataStoreTransaction trans; try { trans = acquireTransaction(); } catch ( MetadataStoreException e ) { String msg = "Could not aquireTranacation to update the profile: " + e.getMessage(); null ); Filter constraint = new OperatorFilter( new PropertyIsEqualTo( propertyName, lit, true, null ) ); trans.performDelete( new DeleteOperation( null, null, constraint ) ); List<String> performInsert = trans.performInsert( new InsertOperation( Collections.singletonList( profile ), null, null ) ); trans.commit(); if ( !performInsert.isEmpty() ) { LOG.info( "Inserted profile with id " + performInsert.get( 0 ) ); LOG.debug( msg ); try { trans.rollback(); } catch ( MetadataStoreException e1 ) { LOG.error( "Rollback failed: ", e1 ); String msg = "Could not update the profile: " + e.getMessage(); LOG.debug( msg ); try { trans.rollback(); } catch ( MetadataStoreException e1 ) { LOG.error( "Rollback failed: ", e1 );
@Override boolean insertRecord( OMElement record ) throws Exception { MetadataStoreTransaction trans = metadataStore.acquireTransaction(); try { List<String> performInsert = trans.performInsert( new InsertOperation( Collections.singletonList( MetadataRecordFactory.create( record ) ), null, null ) ); trans.commit(); if ( performInsert.isEmpty() ) return false; return true; } catch ( Exception e ) { trans.rollback(); throw e; } }
MetadataStoreTransaction ta = store.acquireTransaction(); currentHandle = transact.getHandle(); switch ( transact.getType() ) { case INSERT: List<String> ids = doInsert( ta, (InsertOperation) transact ); insertHandles.add( transact.getHandle() ); insertIds.add( ids ); insertCount += ids.size(); ta.commit(); } catch ( Throwable e ) { ta.rollback(); if ( currentHandle != null ) { String msg = "Transaction operation '" + currentHandle + "' failed: " + e.getMessage(); writer.writeAttribute( "handleRef", handle ); MetadataResultSet<?> rs = store.getRecordById( ids, null ); try { while ( rs.next() ) { DCRecord dc = rs.getRecord().toDublinCore(); dc.serialize( writer, ReturnableElement.brief ); rs.close();
/** * Requests all records matching the query. * * @param query * never <code>null</code> * @return all records matching the query, may be empty but never <code>null</code> * @throws FilterEvaluationException */ public MetadataResultSet<ISORecord> getRecords( MetadataQuery query ) throws FilterEvaluationException { if ( query == null ) { throw new IllegalArgumentException( "MetadataQuery must not be null!" ); } List<ISORecord> result = applyFilter( query.getFilter(), query.getStartPosition(), query.getMaxRecords() ); return new ListMetadataResultSet( result ); }
QName[] queryTypeNames = cswQuery.getQueryTypeNames(); QName[] returnTypeNames = cswQuery.getReturnTypeNames(); query = new MetadataQuery( queryTypeNames, returnTypeNames, constraints, sortProps, startPosition, maxRecords ); } else { countRows = store.getRecordCount( query ); returnedRecords = 0; nextRecord = 1; if ( !isResultTypeHits ) { rs = store.getRecords( query ); returnedRecords = computeReturned( countRows, getRec.getMaxRecords(), getRec.getStartPosition() ); nextRecord = computeNext( countRows, getRec.getMaxRecords(), getRec.getStartPosition() ); while ( rs.next() ) { if ( counter < returnedRecords ) { writeRecord( writer, rs.getRecord(), outputSchema, elementSetName, returnElements ); rs = store.getRecords( query ); List<MetadataRecord> records = new ArrayList<MetadataRecord>( maxMatches ); int maxRecords = getRec.getMaxRecords(); if ( rs.next() ) { records.add( rs.getRecord() ); int remaining = rs.getRemaining(); int nextRecord = 0; if ( remaining > 0 ) {
protected AbstractWhereBuilder getWhereBuilder( MetadataQuery query, Connection conn ) throws FilterEvaluationException, UnmappableException { return dialect.getWhereBuilder( new ISOPropertyNameMapper( dialect, queryables ), (OperatorFilter) query.getFilter(), query.getSorting(), false ); }
/** * Before any transaction operation is possible there should be an evaluation of the record. The response of the * full ISO record has to be valid. With this method this is guaranteed. * * @param elem * that has to be evaluated before there is any transaction operation possible. * @return a list of error-strings, or empty list if there is no validation needed. * @throws MetadataStoreException */ private List<SchemaValidationEvent> validate( OMElement elem ) throws MetadataInspectorException { InputStream is = null; try { StreamBufferStore os = new StreamBufferStore(); elem.serialize( os ); is = os.getInputStream(); } catch ( Throwable e ) { LOG.debug( "error: " + e.getMessage(), e ); throw new MetadataInspectorException( e.getMessage() ); } if ( new QName( "http://www.isotc211.org/2005/gmd", "MD_Metadata" ).equals( elem.getQName() ) ) { return SchemaValidator.validate( is, SCHEMA_URL_GMD, SCHEMA_URL_SRV ); } // DublinCore return SchemaValidator.validate( is, SCHEMA_URL ); }
private AdhocQuery getStoredQuery( String id, MetadataStore<RegistryObject> queryStore ) throws MetadataStoreException { MetadataResultSet<RegistryObject> recordById; recordById = queryStore.getRecordById( Collections.singletonList( id ), new QName[] { new QName( RIM_NS, "AdhocQuery", "rim" ) } ); recordById.next(); Object storedQuery = recordById.getRecord(); if ( storedQuery == null || !( storedQuery instanceof AdhocQuery ) ) { String msg = "Could not find an stored AdhocQuery with id " + id; LOG.debug( msg ); throw new IllegalArgumentException( msg ); } return (AdhocQuery) storedQuery; }
@Override public int getRecordCount( MetadataQuery query ) throws MetadataStoreException { try { List<ISORecord> records = storedIsoRecords.getRecords( query.getFilter() ); return records.size(); } catch ( FilterEvaluationException e ) { throw new MetadataStoreException( e ); } }
@Override public T inspect( T record, Connection conn, SQLDialect dialect ) throws MetadataInspectorException { List<SchemaValidationEvent> errors = validate( record.getAsOMElement() ); if ( errors.isEmpty() ) { return record; } else { StringBuilder sb = new StringBuilder(); for ( SchemaValidationEvent error : errors ) { sb.append( error ); sb.append( "\n" ); } String msg = Messages.getMessage( "ERROR_VALIDATE" + sb ); LOG.debug( msg ); throw new MetadataInspectorException( msg ); } } }
if ( config != null && !config.isRejectEmpty() ) { if ( rsList.size() == 0 && id == null && uuid == null ) { LOG.debug( Messages.getMessage( "INFO_FI_GENERATE_NEW" ) ); String msg = Messages.getMessage( "ERROR_REJECT_FI" ); LOG.debug( msg ); throw new MetadataInspectorException( msg );
public static ServiceProfile createProfile( MetadataStore<?> store ) { LOG.info( "Create profile for store with type " + store.getType() ); if ( "iso".equals( store.getType() ) ) { return new CommonCSWProfile(); } if ( "ebrimeo".equals( store.getType() ) ) { return new EbrimProfile(); } throw new IllegalArgumentException( "Unknown store type '" + store.getType() + "'" ); }
@Override public T getRecord() throws MetadataStoreException { try { BufferedInputStream bais = new BufferedInputStream( rs.getBinaryStream( 1 ) ); XMLStreamReader xmlReader = XMLInputFactory.newInstance().createXMLStreamReader( bais ); return getRecord( xmlReader ); } catch ( Exception e ) { throw new MetadataStoreException( "Error re-creating MetadataRecord from result set: " + e.getMessage() ); } }
protected MetadataResultSet<?> getRecordById( GetRecordById getRecBI, MetadataStore<?> store, List<String> requestedIdList ) throws OWSException { if ( store != null ) { try { return store.getRecordById( requestedIdList, getRecBI.getTypeNames() ); } catch ( MetadataStoreException e ) { throw new OWSException( e.getMessage(), OWSException.NO_APPLICABLE_CODE ); } } return null; }
@Override public ISORecord inspect( ISORecord record, Connection conn, SQLDialect dialect ) throws MetadataInspectorException { // 2.2.5 Unique resource identifier for dataset and dataset series String type = record.getType(); if ( ( type == null || "dataset".equals( type ) || "series".equals( type ) ) && record.getParsedElement().getQueryableProperties().getResourceIdentifier() == null ) { throw new MetadataInspectorException( Messages.get( "INSPIRE_COMPLIANCE_MISSING_RI", record.getIdentifier() ) ); } return record; } }
/** * If there is a data metadata record available for the service metadata record. * */ private boolean getCoupledDataMetadatasets( Connection conn, String resourceIdentifier, SQLDialect dialect ) throws MetadataInspectorException { String resourceIdCol = ISOPropertyNameMapper.CommonColumnNames.resourceid.name(); String mainTable = ISOPropertyNameMapper.DatabaseTables.idxtb_main.name(); ResultSet rs = null; PreparedStatement stm = null; LOG.warn( "Check table / column names." ); String s = "SELECT " + resourceIdCol + " FROM " + mainTable + " WHERE " + resourceIdCol + " = ?"; try { stm = conn.prepareStatement( s ); stm.setString( 1, resourceIdentifier ); rs = stm.executeQuery(); return rs.next(); } catch ( SQLException e ) { String msg = Messages.getMessage( "ERROR_SQL", s, e.getMessage() ); LOG.debug( msg ); throw new MetadataInspectorException( msg ); } finally { close( rs ); close( stm ); } }
String msg = Messages.getMessage( "ERROR_MANDATORY_ELEMENT_MISSING", "contact" ); LOG.debug( msg ); throw new MetadataInspectorException( msg );