2017-07-05 18:42:04 +02:00
package org.gcube.spatial.data.sdi.engine.impl.metadata.templates ;
2017-08-03 12:43:53 +02:00
import java.util.HashMap ;
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 ;
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 ;
public class ThreddsOnlineTemplate extends AbstractTemplate < ThreddsOnlineRequest > {
2017-08-03 12:43:53 +02:00
private static HashMap < String , String > EXPECTED_PARAMETERS = new HashMap < String , String > ( ) ;
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 {
EXPECTED_PARAMETERS . put ( TemplateInvocationBuilder . THREDDS_ONLINE . CATALOG , " The thredds catalog name " ) ;
EXPECTED_PARAMETERS . put ( TemplateInvocationBuilder . THREDDS_ONLINE . FILENAME , " The dataset's file name " ) ;
EXPECTED_PARAMETERS . put ( TemplateInvocationBuilder . THREDDS_ONLINE . HOSTNAME , " Thredds hostname " ) ;
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
}
}