BscsDeliveryResolver.java

package esa.bscs.pds4.packager.resolver;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

import org.springframework.beans.factory.annotation.Autowired;

public class BscsDeliveryResolver implements DeliveryResolver {
        
    @Autowired(required=true)
    private TimeResolver timeResolver;
    
    @Override
    public String getBaseName(String bundleId) {
        
        if(bundleId == null) {
            throw new IllegalArgumentException();
        }
        
        final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss");
        
        final String source = this.getSource(bundleId);
        final String target = "bc";
        final String type = "P";
        final String action = "I";
        final String priorityFlag = "0";
        final String geometryFlag = "1";
        final String descriptor = bundleId;
        final String deliveryDate = formatter.format(LocalDateTime.ofInstant(timeResolver.currentInstant(), ZoneId.of("UTC")));
        
        return source + target + "-" + "pds4" + "-" + type + action + "-" + priorityFlag + geometryFlag + "-" + descriptor + "-" + deliveryDate;
    }
    
    @SuppressWarnings("java:S109")
    private String getSource(String bundleId) {
        
        // If bundle equals 'bc' instrument is aux
        
        if("bc".equals(bundleId)) {
            return "aux";
        }
        
        // If not get the instrument id from the last chunk of the bundleId adjusting if necessary
        
        final String instrument = bundleId.substring(bundleId.lastIndexOf('_')+1);
                
        if("mcam".equals(instrument)) {
            return "cam";
        
        } else if("more".equals(instrument)) {
            return "mre";
        
        } else if("serena".equals(instrument)) {
            return "srn";
        
        } else {
            return instrument.substring(0, 3);
        }
    }
}