2017-07-05 18:42:04 +02:00
package org.gcube.spatial.data.sdi.engine.impl.metadata.templates ;
2018-05-18 17:50:51 +02:00
import java.util.ArrayList ;
2017-08-03 12:43:53 +02:00
2017-07-05 18:42:04 +02:00
import org.gcube.spatial.data.sdi.engine.impl.metadata.MetadataHandler ;
import org.gcube.spatial.data.sdi.engine.impl.metadata.MetadataUtils ;
import org.gcube.spatial.data.sdi.engine.impl.metadata.MetadataUtils.Position ;
import org.gcube.spatial.data.sdi.engine.impl.metadata.templates.ThreddsOnlineTemplate.ThreddsOnlineRequest ;
2018-05-18 17:50:51 +02:00
import org.gcube.spatial.data.sdi.model.ParameterType ;
2017-07-05 18:42:04 +02:00
import org.gcube.spatial.data.sdi.model.metadata.TemplateDescriptor ;
import org.gcube.spatial.data.sdi.model.metadata.TemplateInvocation ;
2017-08-03 12:43:53 +02:00
import org.gcube.spatial.data.sdi.model.metadata.TemplateInvocationBuilder ;
2017-07-05 18:42:04 +02:00
import lombok.AllArgsConstructor ;
import lombok.Getter ;
import lombok.ToString ;
2018-05-18 17:50:51 +02:00
public class ThreddsOnlineTemplate extends AbstractMetadataTemplate < ThreddsOnlineRequest > {
2017-07-05 18:42:04 +02:00
2017-08-03 12:43:53 +02:00
2018-05-18 17:50:51 +02:00
private static ArrayList < ParameterType > EXPECTED_PARAMETERS = new ArrayList < ParameterType > ( ) ;
2017-08-03 12:43:53 +02:00
private static String TEMPLATE_ID = TemplateInvocationBuilder . THREDDS_ONLINE . ID ;
2017-07-05 18:42:04 +02:00
private static String TEMPLATE_NAME = " Thredds Online Resources " ;
private static String FILENAME = " ThreddsOnlineResources.ftlx " ;
2017-08-03 12:43:53 +02:00
private static InsertionPoint INSERTION = new InsertionPoint ( Position . sibling_after , " //gmd:identificationInfo " ) ;
private static TemplateDescriptor DESCRIPTOR ;
static {
2018-05-18 17:50:51 +02:00
EXPECTED_PARAMETERS . add ( new ParameterType ( TemplateInvocationBuilder . THREDDS_ONLINE . CATALOG , " The thredds catalog name " ) ) ;
EXPECTED_PARAMETERS . add ( new ParameterType ( TemplateInvocationBuilder . THREDDS_ONLINE . FILENAME , " The dataset's file name " ) ) ;
EXPECTED_PARAMETERS . add ( new ParameterType ( TemplateInvocationBuilder . THREDDS_ONLINE . HOSTNAME , " Thredds hostname " ) ) ;
2017-08-03 12:43:53 +02:00
DESCRIPTOR = new TemplateDescriptor ( TEMPLATE_ID , TEMPLATE_NAME , " Template for online resources exposed by thredds. " , " http://sdi-d4s.d4science.org " , EXPECTED_PARAMETERS ) ;
}
2017-07-05 18:42:04 +02:00
public ThreddsOnlineTemplate ( ) {
super ( FILENAME , INSERTION , DESCRIPTOR ) ;
}
@Getter
@AllArgsConstructor
@ToString
public static class ThreddsOnlineRequest {
private String hostname ;
private String catalog ;
private String filename ;
private String gisViewerLink ;
}
@Override
public ThreddsOnlineRequest getInstantiationRequest ( MetadataHandler handler , TemplateInvocation invocation ) throws InvalidTemplateInvocationException , Exception {
2017-08-03 12:43:53 +02:00
if ( ! invocation . getToInvokeTemplateID ( ) . equals ( TEMPLATE_ID ) ) throw new InvalidTemplateInvocationException ( " Invalid template ID : " + invocation . getToInvokeTemplateID ( ) ) ;
String filename = getParameter ( TemplateInvocationBuilder . THREDDS_ONLINE . FILENAME , invocation . getTemplateParameters ( ) , true , null ) ;
String catalog = getParameter ( TemplateInvocationBuilder . THREDDS_ONLINE . CATALOG , invocation . getTemplateParameters ( ) , true , null ) ;
String hostname = getParameter ( TemplateInvocationBuilder . THREDDS_ONLINE . HOSTNAME , invocation . getTemplateParameters ( ) , true , null ) ;
2017-07-05 18:42:04 +02:00
String uuid = handler . getUUID ( ) ;
String gisLink = MetadataUtils . getGisLinkByUUID ( uuid ) ;
2017-08-03 12:43:53 +02:00
return new ThreddsOnlineRequest ( hostname , catalog , filename , gisLink ) ;
2017-07-05 18:42:04 +02:00
}
}