private void checkResult(AnnotatedObject<?, ?> annotatedObject, String ac, String type) { if (annotatedObject == null) { throw new IntactException("No " + type + " found with: " + ac); } } }
public static <T> T newInstance(Class<T> clazz) { T instance; try { instance = clazz.newInstance(); } catch (Exception e) { throw new IntactException(e); } return instance; } }
public void addPackageWithEntities( String packageName ) { if ( isInitialized() ) { throw new IntactException( "Cannot add package after the sessionFactory has been initialized" ); } packagesWithEntities.add( packageName ); }
private Collection<Experiment> getExperiments( int firstResult, int maxResults ) { output.println( "Retrieving data from DB store, from " + firstResult ); if ( searchPattern.contains( "," ) ) { throw new IntactException( "Lists with comma-separated experiments are not accepted anymore" ); } Collection<Experiment> searchResults = getDaoFactory().getExperimentDao().getByShortLabelLike( searchPattern, true, firstResult, maxResults, true ); int resultSize = searchResults.size(); output.println( "done (retrieved " + resultSize + " experiment" + ( resultSize > 1 ? "s" : "" ) + ")" ); return searchResults; }
private Collection<Experiment> getExperiments( int firstResult, int maxResults ) { output.println( "Retrieving data from DB store, from " + firstResult ); if ( searchPattern.contains( "," ) ) { throw new IntactException( "Lists with comma-separated experiments are not accepted anymore" ); } Collection<Experiment> searchResults = getDaoFactory().getExperimentDao().getByShortLabelLike( searchPattern, true, firstResult, maxResults, true ); int resultSize = searchResults.size(); output.println( "done (retrieved " + resultSize + " experiment" + ( resultSize > 1 ? "s" : "" ) + ")" ); return searchResults; }
private Collection<Experiment> getExperiments( int firstResult, int maxResults ) { log.debug( "Retrieving data from DB store, from " + firstResult ); if ( searchPattern.contains( "," ) ) { throw new IntactException( "Lists with comma-separated experiments are not accepted anymore" ); } Collection<Experiment> searchResults = getDaoFactory().getExperimentDao().getByShortLabelLike( searchPattern, true, firstResult, maxResults, true ); int resultSize = searchResults.size(); log.debug( "done (retrieved " + resultSize + " experiment" + ( resultSize > 1 ? "s" : "" ) + ")" ); return searchResults; }
private static void addPropertyWithReflection( SearchableQuery query, String propName, String propValue ) throws Exception { Method getter = PropertyUtils.getReadMethod( new PropertyDescriptor( propName, query.getClass() ) ); Class returnType = getter.getReturnType(); Object objPhrase; if ( returnType.equals( QueryPhrase.class ) ) { objPhrase = new StandardQueryPhraseConverter().objectToPhrase( propValue ); } else if ( returnType.getName().equals( "boolean" ) ) { objPhrase = Boolean.valueOf( propValue ).booleanValue(); } else { throw new IntactException( "Unexpected type " + returnType.getName() + " for property name: " + propName ); } BeanUtils.setProperty( query, propName, objPhrase ); }
private Map<Class<? extends CvObject>, Set<String>> getChildrenCvClassified( CvDagObject parentCv ) { if ( parentCv == null ) { throw new IntactException( "CvDagObject is null" ); } Map<Class<? extends CvObject>, Set<String>> cvsMap = new HashMap<Class<? extends CvObject>, Set<String>>(); List<CvDagObject> children = new ArrayList<CvDagObject>(); fillChildrenRecursively( parentCv, children ); for ( CvDagObject child : children ) { addCvObjectToMap( cvsMap, child.getClass(), child.getShortLabel() ); } return cvsMap; }
protected void checkReadOnly() { boolean readOnly = RuntimeConfig.getCurrentInstance( intactSession ).isReadOnlyApp(); if ( readOnly ) { throw new IntactException( "This application is running on mode READ-ONLY, so it cannot persist or update " + "objects in the database. Set the init-param " + IntactEnvironment.READ_ONLY_APP + " to false if you want to " + "do that." ); } }
protected void commitTransaction() { try { getDataContext().commitTransaction(); } catch (IntactTransactionException e) { throw new IntactException(e); } }
/** * Initialize the database, adding the institution and schema version, if necessary * @param context IntactContext */ public static void initializeDatabaseIfNecessary(IntactContext context) { try { persistInstitutionAndCvsIfNecessary( context ); } catch ( IntactTransactionException e ) { throw new IntactException( "Error while persisting institution.", e ); } persistSchemaVersionIfNecessary( context ); }
protected void commitTransaction() { try { getDataContext().commitTransaction(); } catch (IntactTransactionException e) { throw new IntactException(e); } }
/** * todo prove if it really works.. * * @param aSearchObject * * @throws IntactException */ private void removeIndex( final SearchObject aSearchObject ) throws IntactException { try { final IndexReader reader = IndexReader.open( index ); final Term term = new Term( SearchEngineConstants.AC, aSearchObject.getAc() ); reader.deleteDocuments( term ); reader.close(); } catch ( IOException e ) { logger.error( "problems with removing a term", e ); throw new IntactException( "Error while removing searchObject data from index", e ); } throw new RuntimeException( "implement me" ); }
/** * todo prove if it really works.. * * @param aSearchObject * * @throws IntactException */ private void removeIndex( final SearchObject aSearchObject ) throws IntactException { try { final IndexReader reader = IndexReader.open( index ); final Term term = new Term( SearchEngineConstants.AC, aSearchObject.getAc() ); reader.deleteDocuments( term ); reader.close(); } catch ( IOException e ) { logger.error( "problems with removing a term", e ); throw new IntactException( "Error while removing searchObject data from index", e ); } throw new RuntimeException( "implement me" ); }
/** * Initialize the database, adding the institution and schema version * @param context IntactContext */ public static void initializeDatabase(IntactContext context) { try { persistInstitution(context); } catch (IntactTransactionException e) { throw new IntactException("Error while persisting institution.", e); } persistSchemaVersion(context); persistBasicCvObjects(context); }
private <X extends Xref> X createPsiMiXref(Class<X> xrefClass, String psiMi, Institution institution) { if (xrefClass == null) { throw new NullPointerException("xrefClass"); } X xref; try { xref = xrefClass.newInstance(); } catch (Exception e) { throw new IntactException("Problems instantiating Xref of type: " + xrefClass.getName()); } xref.setOwner(institution); xref.setPrimaryId(psiMi); xref.setCvDatabase(createPsiMiCvDatabase(institution)); xref.setCvXrefQualifier(createIdentityCvXrefQualifier(institution)); return xref; }
public GeneratedEntry addInteractorWithUniprotId(String uniprotId) { List<ProteinImpl> interactors = intactContext.getDataContext().getDaoFactory() .getProteinDao().getByUniprotId(uniprotId); if (interactors.isEmpty()) { throw new IntactException("No interactors found with uniprot id: " + uniprotId); } for (Interactor interactor : interactors) { addInteractor(interactor); } return this; }
public static UserContext getCurrentInstance( IntactSession session ) { if ( !session.isRequestAvailable() ) { throw new IntactException( "Cannot get a UserContext if the IntactSession does not have request and session scope" ); } Object obj = session.getAttribute( SESSION_ATT_NAME ); if ( obj != null ) { return ( UserContext ) obj; } UserContext userContext = createDefaultUserContext( session ); session.setAttribute( SESSION_ATT_NAME, userContext ); return userContext; }
public UpdateTargetSpecies() { if (getDataContext().isTransactionActive()) { throw new IntactException("Transaction must NOT be active when instantiating UpdateTargetSpecies"); } beginTransaction(); CvObjectDao cvObjectDao = getDataContext().getDaoFactory().getCvObjectDao(); newt = (CvDatabase) cvObjectDao.getByPsiMiRef( CvDatabase.NEWT_MI_REF ); if (newt == null) { throw new IllegalStateException("Cv is null: "+ CvDatabase.NEWT + "("+ CvDatabase.NEWT_MI_REF + ")"); } targetSpeciesQualifier = (CvXrefQualifier) cvObjectDao.getByShortLabel( CvXrefQualifier.class, CvXrefQualifier.TARGET_SPECIES ); if (targetSpeciesQualifier == null) { throw new IllegalStateException("Cv is null: "+ CvXrefQualifier.TARGET_SPECIES); } commitTransaction(); }
/** * Import a testDataset into the database * @param testDataset the dataset to use */ public void importTestDataset(DbUnitTestDataset testDataset) { if (testDataset == null) { throw new NullPointerException("testDataset"); } try { IDataSet dbUnitDataSet = convertTestDatasetToDbUnit(testDataset); DatabaseOperation.INSERT.execute(getDatabaseConnection(), dbUnitDataSet); } catch (Exception e) { throw new IntactException("Exception importing dataset: "+testDataset.getId(), e); } // reset institution List<Institution> institutions = IntactContext.getCurrentInstance().getDataContext().getDaoFactory().getInstitutionDao().getAll(); if (!institutions.isEmpty()) { IntactContext.getCurrentInstance().getConfig().setInstitution(institutions.get(0)); } }