SSRF Demonstration Builder
Building a compliant, standardized SSRF document is as easy as translating
the raw data and setting the properties. The SSRF document may then be
validated and exported.
/*
* Copyright 2014 Key Bridge Global LLC.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.openssrf.utility;
import ca.gc.ic.broadcast.entity.CanadaStationAm;
import ca.gc.ic.broadcast.entity.CanadaStationFm;
import ca.gc.ic.broadcast.entity.CanadaStationSdar;
import ca.gc.ic.broadcast.entity.CanadaStationTv;
import java.util.List;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import javax.xml.bind.annotation.*;
import org.openssrf.translate.canada.SSRFTranslatorBDBS;
import us.gov.dod.standard.ssrf.SSRF;
import us.gov.dod.standard.ssrf.SSRFProperties;
import us.gov.dod.standard.ssrf.SSRFUtility;
/**
* Example SSRF message builder implementation to read an Industry Canada BDBS
* record into a SSRF Assignment, assign SSRF properties, and prepare the
* document for export.
*/
public class OpenSSRF_BDBS {
/**
* The Key Bridge Industry Canada BDBD API web service base URI.
*/
private static final String SERVICE = "https://api.keybridgeglobal.com/data/rest/bdbs/find/";
/**
* The main executable method.
* <p>
* @param args command line arguments.
* @throws Exception upon error
*/
public static void main(String[] args) throws Exception {
/**
* Retrieve a Canada broadcast television record.
*/
CanadaStations response = OpenSSRF_BDBS.get("ckco-tv-3");
/**
* Translate into SSRf.
*/
SSRF ssrf = SSRFTranslatorBDBS.translate(response.getCanadaStationList());
/**
* Set the default SSRF Properties. This sets the global metadata
* classification (CLS) level to "U" (Unclassified).
*/
ssrf.setProperties(SSRFProperties.getDefault());
/**
* Set the default organisation (sic) for all SSRF serial number instances.
* This may be up to four characters.
*/
ssrf.setProperty("TSerial.organisation", "ic");
/**
* Set the default country code for all SSRF serial number instances. This
* must be an enumerated value selected from ListCCY.
*/
ssrf.setProperty("TSerial.country", "CAN");
/**
* Prepare the SSRF message for WRITE.
*/
try {
ssrf.prepare();
} catch (Exception ex) {
/**
* If preparation failed then evaluate the SSRF document and print a list
* of validation errors.
*/
System.out.println("DEBUG SSRF PREPARATION FAULT");
for (String error : SSRFUtility.evaluate(ssrf)) {
System.err.println("SSRF ERROR: " + error);
}
return;
}
/**
* DONE.
* <p>
* At this point the SSRF document is assembled and valid and may be
* exported by whatever technique your application calls for.
* <p>
* Use JAXB to marshal the SSRF object into XML.
*/
System.out.println("+-----------------------------------------------------+");
System.out.println("| SSRF Document |");
System.out.println("+-----------------------------------------------------+");
System.out.println(SSRFUtility.marshal(ssrf));
}
/**
* Get one or more station records associated with a Canadian call sign.
* <p>
* You may provide a call sign fragment to find multiple stations. For
* example, "ckco-tv-3" will return a single station, whereas "ckco-tv" will
* return two stations ("ckco-tv-2" and "ckco-tv-3") and "ckco" will return
* three stations ("ckco-dt", "ckco-tv-2" and "ckco-tv-3").
* <p>
* Developer note: The number of records in the response body is declared in
* the "Records" response header.
* <p>
* @param callsign a call sign or call sign fragment beginning with the letter
* "C". Minimum length is three (3) characters.
* @return all stations matching the given call sign
*/
public static CanadaStations get(String callsign) {
WebTarget webTarget = ClientBuilder.newClient().target(SERVICE).path(callsign);
System.out.println("Keybridge Web Client Processing BDBS at " + webTarget.getUri());
return webTarget.request().get(CanadaStations.class);
}
/**
* Internal wrapper class to marshal the API response.
* <p>
* The Key Bridge Industry Canada BDBS API web service returns a LIST of
* Canadian AM, FM, SDAR and TV Stations.
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "canadaStations")
public static final class CanadaStations {
@XmlAnyElement
@XmlElementRefs({
@XmlElementRef(type = CanadaStationTv.class),
@XmlElementRef(type = CanadaStationFm.class),
@XmlElementRef(type = CanadaStationAm.class),
@XmlElementRef(type = CanadaStationSdar.class)
})
private List<Object> canadaStationList;
public List<Object> getCanadaStationList() {
return canadaStationList;
}
@Override
public String toString() {
return "Response{" + "canadaStation=" + canadaStationList + '}';
}
}
}