/*
 * The Gemma project
 * 
 * Copyright (c) 2007 University of British Columbia
 * 
 * Licensed 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 ubic.gemma.web.taglib.displaytag.expression.experiment;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.displaytag.decorator.TableDecorator;

import ubic.gemma.loader.expression.geo.model.GeoRecord;
import ubic.gemma.model.expression.experiment.ExpressionExperiment;

/**
 * @author pavlidis
 * @version $Id$
 */
public class GeoRecordWrapper extends TableDecorator {

    /**
     * Link for loading or viewing, depending on whether the data are already in the database.
     * 
     * @return
     */
    public String getInGemma() {
        GeoRecord record = ( GeoRecord ) getCurrentRowObject();

        if ( record.getCorrespondingExperiments().size() == 0 ) {
            String accession = record.getGeoAccession();
            return "<input type=\"button\" value=\"Load\" " + "\" onClick=\"load('" + accession + "')\" >";
        } else {
            StringBuilder buf = new StringBuilder();
            for ( ExpressionExperiment ee : record.getCorrespondingExperiments() ) {
                buf.append( "<a href=\"/Gemma/expressionExperiment/showExpressionExperiment.html?" );
                buf.append( "id=" + ee.getId() + "\">" + ee.getShortName() );
                buf.append( "</a> " );
            }
            return buf.toString();
        }
    }

    public String getDetails() {
        GeoRecord record = ( GeoRecord ) getCurrentRowObject();
        String accession = record.getGeoAccession();
        return "<a href=\"#\" onClick=\"showDetails(\'" + accession + "\')\">Details</a>";
    }

    /**
     * @return
     */
    public String getGeoAccessionLink() {
        GeoRecord record = ( GeoRecord ) getCurrentRowObject();
        return "<a href='http://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=" + record.getGeoAccession() + "'>"
                + record.getGeoAccession() + "</a>";
    }

    public String getReleaseDateNoTime() {
        GeoRecord record = ( GeoRecord ) getCurrentRowObject();
        Date d = record.getReleaseDate();
        SimpleDateFormat df = new SimpleDateFormat( "dd/MM/yy" ); // F out.
        try {
            return df.format( d );
        } catch ( Exception e ) {
            return "[date unparseable]";
        }
    }

    /**
     * @return
     */
    public String getTaxa() {
        GeoRecord record = ( GeoRecord ) getCurrentRowObject();
        StringBuilder buf = new StringBuilder();
        for ( String org : record.getOrganisms() ) {
            buf.append( org + " " );
        }
        return buf.toString();
    }

}
@@ -1518,20 +1518,9 @@
    %7D
- else %7B%0A    
+%0A
     
@@ -1568,28 +1568,24 @@
 ();%0A        
- 
-   
 for ( Expres
@@ -1637,36 +1637,32 @@
 periments() ) %7B%0A
-    
             buf.
@@ -1739,28 +1739,24 @@
 t.html?%22 );%0A
-    
             
@@ -1821,36 +1821,32 @@
  );%0A            
-    
 buf.append( %22%3C/a
@@ -1864,25 +1864,18 @@
     
-    %7D%0A   
+%7D%0A
         
  ret
@@ -1866,25 +1866,24 @@
   %7D%0A        
- 
 return buf.t
@@ -1893,26 +1893,16 @@
 ring();%0A
-        %7D%0A
     %7D%0A%0A 
@@ -2299,24 +2299,40 @@
   return %22%3Ca
+ target='_blank'
  href='http:
@@ -2408,15 +2408,8 @@
 on()
- + %22'%3E%22
 %0A   
@@ -2422,16 +2422,23 @@
        +
+ %22'%3E%22 +
  record.

make geo links open in new window