Search in sources :

Example 1 with Gene2CsStatus

use of ubic.gemma.persistence.model.Gene2CsStatus in project Gemma by PavlidisLab.

the class TableMaintenanceUtilImpl method updateGene2CsEntries.

@Override
@Transactional
public synchronized void updateGene2CsEntries() {
    if (TableMaintenanceUtilImpl.running.get())
        return;
    TableMaintenanceUtilImpl.log.debug("Running Gene2CS status check");
    String annotation = "";
    try {
        TableMaintenanceUtilImpl.running.set(true);
        Gene2CsStatus status = this.getLastGene2CsUpdateStatus();
        boolean needToRefresh = false;
        if (status == null) {
            needToRefresh = true;
        }
        if (!needToRefresh) {
            Collection<Auditable> newObj = auditEventService.getNewSinceDate(status.getLastUpdate());
            for (Auditable a : newObj) {
                if (a instanceof ArrayDesign) {
                    needToRefresh = true;
                    annotation = a + " is new since " + status.getLastUpdate();
                    TableMaintenanceUtilImpl.log.debug(annotation);
                    break;
                }
            }
        }
        if (!needToRefresh) {
            Collection<Auditable> updatedObj = auditEventService.getUpdatedSinceDate(status.getLastUpdate());
            for (Auditable a : updatedObj) {
                if (a instanceof ArrayDesign) {
                    for (AuditEvent ae : auditEventService.getEvents(a)) {
                        if (ae == null)
                            // legacy of ordered-list which could end up with gaps; should
                            continue;
                        // not be needed any more
                        if (ae.getEventType() != null && ae.getEventType() instanceof ArrayDesignGeneMappingEvent && ae.getDate().after(status.getLastUpdate())) {
                            needToRefresh = true;
                            annotation = a + " had probe mapping done since: " + status.getLastUpdate();
                            TableMaintenanceUtilImpl.log.debug(annotation);
                            break;
                        }
                    }
                }
                if (needToRefresh)
                    break;
            }
        }
        if (needToRefresh) {
            TableMaintenanceUtilImpl.log.debug("Update of GENE2CS initiated");
            this.generateGene2CsEntries();
            Gene2CsStatus updatedStatus = this.writeUpdateStatus(annotation, null);
            this.sendEmail(updatedStatus);
        } else {
            TableMaintenanceUtilImpl.log.debug("No update of GENE2CS needed");
        }
    } catch (Exception e) {
        try {
            TableMaintenanceUtilImpl.log.info("Error during attempt to check status or update GENE2CS", e);
            Gene2CsStatus updatedStatus = this.writeUpdateStatus(annotation, e);
            this.sendEmail(updatedStatus);
        } catch (IOException e1) {
            throw new RuntimeException(e1);
        }
    } finally {
        TableMaintenanceUtilImpl.running.set(false);
    }
}
Also used : Auditable(ubic.gemma.model.common.Auditable) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) Gene2CsStatus(ubic.gemma.persistence.model.Gene2CsStatus) AuditEvent(ubic.gemma.model.common.auditAndSecurity.AuditEvent) ArrayDesignGeneMappingEvent(ubic.gemma.model.common.auditAndSecurity.eventType.ArrayDesignGeneMappingEvent) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with Gene2CsStatus

use of ubic.gemma.persistence.model.Gene2CsStatus in project Gemma by PavlidisLab.

the class TableMaintenanceUtilImpl method writeUpdateStatus.

/**
 * @param annotation extra text that describes the status
 */
private Gene2CsStatus writeUpdateStatus(String annotation, Exception e) throws IOException {
    this.initDirectories();
    Gene2CsStatus status = new Gene2CsStatus();
    Calendar c = Calendar.getInstance();
    Date date = c.getTime();
    status.setLastUpdate(date);
    status.setError(e);
    status.setAnnotation(annotation);
    try (FileOutputStream fos = new FileOutputStream(this.getGene2CsInfopath());
        ObjectOutputStream oos = new ObjectOutputStream(fos)) {
        oos.writeObject(status);
    }
    return status;
}
Also used : Calendar(java.util.Calendar) Gene2CsStatus(ubic.gemma.persistence.model.Gene2CsStatus) Date(java.util.Date)

Aggregations

Gene2CsStatus (ubic.gemma.persistence.model.Gene2CsStatus)2 Calendar (java.util.Calendar)1 Date (java.util.Date)1 Transactional (org.springframework.transaction.annotation.Transactional)1 Auditable (ubic.gemma.model.common.Auditable)1 AuditEvent (ubic.gemma.model.common.auditAndSecurity.AuditEvent)1 ArrayDesignGeneMappingEvent (ubic.gemma.model.common.auditAndSecurity.eventType.ArrayDesignGeneMappingEvent)1 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)1