Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.26.x] Adds Gmd QueryResponseTransformer #6781

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
import ddf.catalog.data.BinaryContent;
import ddf.catalog.data.Metacard;
import ddf.catalog.data.impl.BinaryContentImpl;
import ddf.catalog.operation.SourceResponse;
import ddf.catalog.transform.CatalogTransformerException;
import ddf.catalog.transform.MetacardTransformer;
import ddf.catalog.transform.QueryResponseTransformer;
import java.io.ByteArrayInputStream;
import java.io.Serializable;
import java.io.StringWriter;
Expand All @@ -36,20 +38,33 @@
import org.codice.ddf.spatial.ogc.csw.catalog.common.GmdConstants;
import org.codice.ddf.spatial.ogc.csw.catalog.converter.CswRecordConverter;

public class AbstractGmdTransformer implements MetacardTransformer {
public class AbstractGmdTransformer implements MetacardTransformer, QueryResponseTransformer {

public static final String GML_PREFIX = "gml:";

public static final String GCO_PREFIX = GmdConstants.GCO_PREFIX + ":";

private Supplier<Converter> converterSupplier;

protected static final String TRANSFORM_EXCEPTION_MSG =
"Unable to transform from GMD Metadata to Metacard";

/** @param converterSupplier must be non-null */
public AbstractGmdTransformer(Supplier<Converter> converterSupplier) {
notNull(converterSupplier, "converterSupplier must be non-null");
this.converterSupplier = converterSupplier;
}

@Override
public BinaryContent transform(SourceResponse sourceResponse, Map<String, Serializable> map)
throws CatalogTransformerException {
if (sourceResponse.getResults() != null && sourceResponse.getResults().size() == 1) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the GMD Schema itself doesn't appear to support multiple metadata records in a single doc, but a possible improvement here would be to create a zip of all the results in the GMD XML format.

return transform(sourceResponse.getResults().get(0).getMetacard(), map);
} else {
throw new CatalogTransformerException(TRANSFORM_EXCEPTION_MSG);
}
}

@Override
public BinaryContent transform(Metacard metacard, Map<String, Serializable> arguments)
throws CatalogTransformerException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ public class GmdTransformer extends AbstractGmdTransformer implements InputTrans

private static final Logger LOGGER = LoggerFactory.getLogger(GmdTransformer.class);

private static final String TRANSFORM_EXCEPTION_MSG =
"Unable to transform from GMD Metadata to Metacard";

private static final Pattern WHITE_SPACE_PATTER = Pattern.compile("(\\s)+");

private static final Pattern NEW_LINE_PATTERN = Pattern.compile("(\\n)+");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,5 +211,20 @@
<argument ref="writerProvider"/>
</bean>

<service ref="gmdInputTransformerTranformer"
interface="ddf.catalog.transform.QueryResponseTransformer">
<service-properties>
<entry key="id" value="gmd:MD_Metadata"/>
<entry key="mime-type" >
<list>
<value>text/xml</value>
<value>application/xml</value>
</list>
</entry>
<entry key="schema" value="http://www.isotc211.org/2005/gmd"/>
<entry key="displayName" value="GMD Metadata"/>

</service-properties>
</service>

</blueprint>