source: geisa/service/implementation/com/ether/TapasServiceImpl.java @ 390

Last change on this file since 390 was 390, checked in by npipsl, 12 years ago

Création du projet GEISA

File size: 4.3 KB
Line 
1package com.ether;
2
3import com.ether.dao.ParameterDAO;
4import com.ether.dao.PlateformDAO;
5import org.apache.commons.logging.Log;
6import org.apache.commons.logging.LogFactory;
7import org.jdom.*;
8import org.jdom.output.Format;
9import org.jdom.output.XMLOutputter;
10import org.jetbrains.annotations.NotNull;
11import org.jetbrains.annotations.Nullable;
12import org.springframework.beans.factory.annotation.Required;
13import org.springframework.transaction.annotation.Transactional;
14
15import java.io.FileOutputStream;
16import java.util.List;
17import java.util.prefs.Preferences;
18
19/**
20 * @author rboipsl
21 * @date 2 mars 2012
22 */
23public class TapasServiceImpl
24        implements TapasService
25{
26
27    public void createXMLRequest()
28
29    {
30        String idF = "Ether_TAPAS_0000001";
31        String idRF = "1";
32        String validFF = "ASCII";
33        String validRF = "YES";
34
35        String xvalidFF = "ASCII,FITS,NETCDF";
36        String xvalidRF = "YES,NO";
37        String fichier = "request1.xml";
38
39        final Element racine = new Element( "tapas" );
40        final Element request = new Element( "request" );
41        final Element preferences = new Element( "preferences" );
42        final Element format = new Element( "format" );
43        final Element rayleighExtinction = new Element( "rayleigh_extinction" );
44
45        //On crée un nouveau Document JDOM basé sur la racine que l'on vient de créer
46        final Document document = new Document( racine );
47
48        final Attribute id = new Attribute( "Id", idF );
49        racine.setAttribute( id );
50
51        final Attribute idR = new Attribute( "Id", idRF );
52        request.setAttribute( idR );
53
54        racine.addContent( request );
55        request.addContent( preferences );
56
57        final Attribute validF = new Attribute( "valid", xvalidFF );
58        format.setAttribute( validF );
59        format.setText( validFF );
60
61        final Attribute validR = new Attribute( "valid", xvalidRF );
62        rayleighExtinction.setAttribute( validR );
63        rayleighExtinction.setText( validRF );
64
65        createXMLFile( fichier, document );
66    }
67
68
69    public void createXMLFile( final String fichier, final Document document )
70    {
71        try
72        {
73            //On utilise ici un affichage classique avec getPrettyFormat()
74            final XMLOutputter sortie = new XMLOutputter( Format.getPrettyFormat() );
75            //Remarquez qu'il suffit simplement de créer une instance de FileOutputStream
76            //avec en argument le nom du fichier pour effectuer la sérialisation.
77            sortie.output( document, new FileOutputStream( fichier ) );
78        }
79        catch( java.io.IOException ignored )
80        {
81        }
82    }
83
84
85    @Nullable
86    @Transactional(readOnly = true)
87    public List<Plateform> getAllPlateforms()
88            throws ServiceException
89    {
90        try
91        {
92            return _plateformDAO.getAllPlateforms();
93        }
94        catch( PersistenceException e )
95        {
96            throw new ServiceException( ServiceException.ServiceCode.PLATEFORM_NOT_FOUND, e );
97        }
98    }
99
100    @Nullable
101    @Transactional(readOnly = true)
102    public Plateform getPlateformById( @Nullable final Integer plateformId )
103            throws ServiceException
104    {
105        if( null == plateformId )
106            return null;
107        try
108        {
109            return _plateformDAO.getPlateformById( plateformId );
110        }
111        catch( PersistenceException e )
112        {
113            throw new ServiceException( ServiceException.ServiceCode.PLATEFORM_NOT_FOUND, e );
114        }
115    }
116
117    @Nullable
118    @Transactional(readOnly = true)
119    public List<Parameter> getAllParametersByPlateformId( @NotNull final Integer plateformId )
120            throws ServiceException
121    {
122        try
123        {
124            return _parameterDAO.getAllParametersByPlateformId( plateformId );
125        }
126        catch( PersistenceException e )
127        {
128            throw new ServiceException( ServiceException.ServiceCode.PARAMETER_NOT_FOUND, e );
129        }
130    }
131
132    @Required
133    public void setPlateformDAO( final PlateformDAO plateformDAO )
134    {
135        _plateformDAO = plateformDAO;
136    }
137
138    @Required
139    public void setParameterDAO( final ParameterDAO parameterDAO )
140    {
141        _parameterDAO = parameterDAO;
142    }
143
144    private static final Log LOGGER = LogFactory.getLog( TapasServiceImpl.class );
145
146
147    private PlateformDAO _plateformDAO;
148    private ParameterDAO _parameterDAO;
149
150}
Note: See TracBrowser for help on using the repository browser.