@Override public String toString() { return super.toString() + "; owner=" + owner.getAc(); } }
@Override public int replaceInstitution(Institution sourceInstitution, Institution destinationInstitution) { verifyOwnable(); if (sourceInstitution.getAc() == null) { throw new IllegalArgumentException("Source institution needs to be present in the database. Supplied institution does not have an AC: " + destinationInstitution); } if (destinationInstitution.getAc() == null) { throw new IllegalArgumentException("Destination institution needs to be present in the database. Supplied institution does not have an AC: " + destinationInstitution); } return getEntityManager().createQuery("update " + getEntityClass().getName() + " ao " + "set ao.owner = :destInstitution " + "where ao.owner.ac = :sourceInstitutionAc " + "and ao.owner.ac <> :destInstitutionAc") .setParameter("sourceInstitutionAc", sourceInstitution.getAc()) .setParameter("destInstitution", destinationInstitution) .setParameter("destInstitutionAc", destinationInstitution.getAc()) .executeUpdate(); }
@Override public int replaceInstitution(Institution sourceInstitution, Institution destinationInstitution) { verifyOwnable(); if (sourceInstitution.getAc() == null) { throw new IllegalArgumentException("Source institution needs to be present in the database. Supplied institution does not have an AC: " + destinationInstitution); } if (destinationInstitution.getAc() == null) { throw new IllegalArgumentException("Destination institution needs to be present in the database. Supplied institution does not have an AC: " + destinationInstitution); } return getEntityManager().createQuery("update " + getEntityClass().getName() + " ao " + "set ao.owner = :destInstitution " + "where ao.owner.ac = :sourceInstitutionAc " + "and ao.owner.ac <> :destInstitutionAc") .setParameter("sourceInstitutionAc", sourceInstitution.getAc()) .setParameter("destInstitution", destinationInstitution) .setParameter("destInstitutionAc", destinationInstitution.getAc()) .executeUpdate(); }
@Override public int replaceInstitution(Institution destinationInstitution, String createUser) { verifyOwnable(); if (destinationInstitution.getAc() == null) { throw new IllegalArgumentException("Destination institution needs to be present in the database. Supplied institution does not have an AC: " + destinationInstitution); } return getEntityManager().createQuery("update " + getEntityClass().getName() + " ao " + "set ao.owner = :destInstitution " + "where ao.creator = :creator " + "and ao.owner.ac <> :destInstitutionAc") .setParameter("destInstitution", destinationInstitution) .setParameter("creator", createUser.toUpperCase()) .setParameter("destInstitutionAc", destinationInstitution.getAc()) .executeUpdate(); }
@Override public int replaceInstitution(Institution destinationInstitution, String createUser) { verifyOwnable(); if (destinationInstitution.getAc() == null) { throw new IllegalArgumentException("Destination institution needs to be present in the database. Supplied institution does not have an AC: " + destinationInstitution); } return getEntityManager().createQuery("update " + getEntityClass().getName() + " ao " + "set ao.owner = :destInstitution " + "where ao.creator = :creator " + "and ao.owner.ac <> :destInstitutionAc") .setParameter("destInstitution", destinationInstitution) .setParameter("creator", createUser.toUpperCase()) .setParameter("destInstitutionAc", destinationInstitution.getAc()) .executeUpdate(); }
@Override public String toString() { return this.getAc() + "; owner=" + this.getOwner().getAc() + "; name=" + this.shortLabel + "; fullname=" + fullName; } }
public static void setInstitution(User user, Institution institution) { user.addOrUpdatePreference(Preference.KEY_INSTITUTION_AC, institution.getAc()); user.addOrUpdatePreference(Preference.KEY_INSTITUTION_NAME, institution.getShortLabel()); }
public static void setInstitution(User user, Institution institution) { user.addOrUpdatePreference(Preference.KEY_INSTITUTION_AC, institution.getAc()); user.addOrUpdatePreference(Preference.KEY_INSTITUTION_NAME, institution.getShortLabel()); }
/** * Gets the institution from the RuntimeConfig object. In addition, tries to refresh * the instance from the database if it is detached. * * @return * @throws IntactException */ public Institution getInstitution() throws IntactException { Institution institution = config.getDefaultInstitution(); if (institution.getAc() != null && getDataContext().getDaoFactory().getInstitutionDao().isTransient(institution)) { institution = getDataContext().getDaoFactory().getInstitutionDao().getByAc(institution.getAc()); } return institution; }
/** * Gets the institution from the RuntimeConfig object. In addition, tries to refresh * the instance from the database if it is detached. * * @return * @throws IntactException */ public Institution getInstitution() throws IntactException { Institution institution = config.getDefaultInstitution(); if (institution.getAc() != null && getDataContext().getDaoFactory().getInstitutionDao().isTransient(institution)) { institution = getDataContext().getDaoFactory().getInstitutionDao().getByAc(institution.getAc()); } return institution; }
private static void persistInstitution(IntactContext context) throws IntactTransactionException { Institution institution = context.getConfig().getInstitution(); if (institution == null) { throw new NullPointerException("Institution is null. Set an institution to the RuntimeConfig first"); } // remove ac, it should not have one at this point to be persisted correctly if (institution.getAc() != null) institution.setAc(null); log.debug("Persisting institution: " + institution.getShortLabel()); DaoFactory daoFactory = getDefaultDaoFactory(context); daoFactory.beginTransaction(); daoFactory.getInstitutionDao().persist(institution); context.getDataContext().commitTransaction(); }
/** * Finds an institution based on its properties. * * @param institution the object we are searching an AC for. * @return an AC or null if it couldn't be found. */ protected String findAcForInstitution( Institution institution ) { String ac = null; // try to fetch it first using the xref. If not, use the shortlabel Xref institutionXref = XrefUtils.getPsiMiIdentityXref( institution ); if ( institutionXref != null ) { Query query = getEntityManager().createQuery( "select distinct institution.ac from Institution institution " + "left join institution.xrefs as xref " + "where xref.primaryId = :primaryId" ); query.setParameter( "primaryId", institutionXref.getPrimaryId() ); ac = getFirstAcForQuery( query, institution ); } if ( ac == null ) { Institution fetchedInstitution = getDaoFactory().getInstitutionDao().getByShortLabel( institution.getShortLabel() ); if ( fetchedInstitution != null ) { ac = fetchedInstitution.getAc(); } } return ac; }
/** * Finds an institution based on its properties. * * @param institution the object we are searching an AC for. * @return an AC or null if it couldn't be found. */ protected String findAcForInstitution( Institution institution ) { String ac = null; // try to fetch it first using the xref. If not, use the shortlabel Xref institutionXref = XrefUtils.getPsiMiIdentityXref( institution ); if ( institutionXref != null ) { Query query = getEntityManager().createQuery( "select distinct institution.ac from Institution institution " + "left join institution.xrefs as xref " + "where xref.primaryId = :primaryId" ); query.setParameter( "primaryId", institutionXref.getPrimaryId() ); ac = getFirstAcForQuery( query, institution ); } if ( ac == null ) { Institution fetchedInstitution = getDaoFactory().getInstitutionDao().getByShortLabel( institution.getShortLabel() ); if ( fetchedInstitution != null ) { ac = fetchedInstitution.getAc(); } } return ac; }
for (Institution sourceInstitution : sourceInstitutions) { if (!sourceInstitution.equals(destinationInstitution)) { intactContext.getDaoFactory().getInstitutionDao().deleteByAc(sourceInstitution.getAc());
for (Institution sourceInstitution : sourceInstitutions) { if (!sourceInstitution.equals(destinationInstitution)) { intactContext.getDaoFactory().getInstitutionDao().deleteByAc(sourceInstitution.getAc());
Institution owner = daoFactory.getInstitutionDao().getByAc( IntactContext.getCurrentInstance().getInstitution().getAc() );
Institution owner = daoFactory.getInstitutionDao().getByAc( IntactContext.getCurrentInstance().getInstitution().getAc() );