public List<MetadataFormat> formatFor(FilterResolver resolver, ItemIdentifier item) { List<MetadataFormat> result = new ArrayList<MetadataFormat>(); for (MetadataFormat format : this.metadataFormats) if (!format.hasCondition() || format.getCondition().getFilter(resolver).isItemShown(item)) result.add(format); return result; } }
public Context withMetadataFormat(String prefix, Transformer transformer, Condition condition) { withMetadataFormat( new MetadataFormat() .withNamespace(prefix) .withPrefix(prefix) .withSchemaLocation(prefix) .withTransformer(transformer) .withCondition(condition) ); return this; }
public MetadataFormat formatForPrefix(String metadataPrefix) { for (MetadataFormat format : this.metadataFormats) if (format.getPrefix().equals(metadataPrefix)) return format; return null; }
public static MetadataFormat metadataFormat (String prefix) { return new MetadataFormat().withPrefix(prefix); }
private Context addDataverseJsonMetadataFormat(Context context) { MetadataFormat metadataFormat = MetadataFormat.metadataFormat(DATAVERSE_EXTENDED_METADATA_FORMAT); metadataFormat.withNamespace(DATAVERSE_EXTENDED_METADATA_INFO); metadataFormat.withSchemaLocation(DATAVERSE_EXTENDED_METADATA_SCHEMA); context.withMetadataFormat(metadataFormat); return context; }
throw new IdDoesNotExistException("This context does not include this item"); if (format.hasCondition() && !format.getCondition().getFilter(getRepository().getFilterResolver()).isItemShown(item)) throw new CannotDisseminateRecordException("Format not applicable to this item"); metadata = new Metadata(toPipeline(item) .apply(getContext().getTransformer()) .apply(format.getTransformer()) .process()); } else { metadata = new Metadata(toPipeline(item) .apply(format.getTransformer()) .process());
@Override public ListMetadataFormats handle(OAICompiledRequest params) throws OAIException, HandlerException { ListMetadataFormats result = new ListMetadataFormats(); if (params.hasIdentifier()) { Item item = itemRepositoryHelper.getItem(params.getIdentifier()); List<MetadataFormat> metadataFormats = getContext().formatFor(getRepository().getFilterResolver(), item); if (metadataFormats.isEmpty()) throw new NoMetadataFormatsException(); for (MetadataFormat metadataFormat : metadataFormats) { com.lyncode.xoai.model.oaipmh.MetadataFormat format = new com.lyncode.xoai.model.oaipmh.MetadataFormat() .withMetadataPrefix(metadataFormat.getPrefix()) .withMetadataNamespace(metadataFormat.getNamespace()) .withSchema(metadataFormat.getSchemaLocation()); result.withMetadataFormat(format); } } else { for (MetadataFormat metadataFormat : getContext().getMetadataFormats()) { com.lyncode.xoai.model.oaipmh.MetadataFormat format = new com.lyncode.xoai.model.oaipmh.MetadataFormat() .withMetadataPrefix(metadataFormat.getPrefix()) .withMetadataNamespace(metadataFormat.getNamespace()) .withSchema(metadataFormat.getSchemaLocation()); result.withMetadataFormat(format); } } return result; }
metadata = new Metadata(toPipeline(item) .apply(getContext().getTransformer()) .apply(format.getTransformer()) .process()); } else { metadata = new Metadata(toPipeline(item) .apply(format.getTransformer()) .process());
private void addSupportedMetadataFormats(Context context) { for (String[] provider : ExportService.getInstance(settingsService).getExportersLabels()) { String formatName = provider[1]; Exporter exporter; try { exporter = ExportService.getInstance(settingsService).getExporter(formatName); } catch (ExportException ex) { exporter = null; } if (exporter != null && exporter.isXMLFormat() && exporter.isHarvestable()) { MetadataFormat metadataFormat; try { metadataFormat = MetadataFormat.metadataFormat(formatName); metadataFormat.withNamespace(exporter.getXMLNameSpace()); metadataFormat.withSchemaLocation(exporter.getXMLSchemaLocation()); } catch (ExportException ex) { metadataFormat = null; } if (metadataFormat != null) { context.withMetadataFormat(metadataFormat); } } } //return context; }
public Context withMetadataFormat(String prefix, Transformer transformer) { withMetadataFormat(new MetadataFormat().withNamespace(prefix).withPrefix(prefix).withSchemaLocation(prefix).withTransformer(transformer)); return this; }
private List<ScopedFilter> getScopedFilters(Context context, String metadataPrefix) throws CannotDisseminateFormatException { List<ScopedFilter> filters = new ArrayList<ScopedFilter>(); if (context.hasCondition()) filters.add(new ScopedFilter(context.getCondition(), Scope.Context)); MetadataFormat metadataFormat = context.formatForPrefix(metadataPrefix); if (metadataFormat.hasCondition()) filters.add(new ScopedFilter(metadataFormat.getCondition(), Scope.MetadataFormat)); return filters; }
public Context withMetadataFormat(MetadataFormat metadataFormat) { int remove = -1; for (int i = 0;i<metadataFormats.size();i++) if (metadataFormats.get(i).getPrefix().equals(metadataFormat.getPrefix())) remove = i; if (remove >= 0) this.metadataFormats.remove(remove); this.metadataFormats.add(metadataFormat); return this; }
private boolean canDisseminate(ItemIdentifier itemIdentifier, MetadataFormat format) { return !format.hasCondition() || format.getCondition().getFilter(getRepository().getFilterResolver()).isItemShown(itemIdentifier); } }
private Header createHeader(OAICompiledRequest parameters, ItemIdentifier itemIdentifier) throws BadArgumentException, OAIException, NoMetadataFormatsException { MetadataFormat format = getContext().formatForPrefix(parameters .getMetadataPrefix()); if (!itemIdentifier.isDeleted() && !canDisseminate(itemIdentifier, format)) throw new InternalOAIException("The item repository is currently providing items which cannot be disseminated with format "+format.getPrefix()); Header header = new Header(); header.withDatestamp(itemIdentifier.getDatestamp()); header.withIdentifier(itemIdentifier.getIdentifier()); if (itemIdentifier.isDeleted()) header.withStatus(Header.Status.DELETED); for (Set set : getContext().getSets()) if (set.getCondition().getFilter(getRepository().getFilterResolver()).isItemShown(itemIdentifier)) header.withSetSpec(set.getSpec()); for (Set set : itemIdentifier.getSets()) header.withSetSpec(set.getSpec()); return header; }
@Override public GetRecord handle(OAICompiledRequest parameters) throws OAIException, HandlerException { MetadataFormat format = getContext().formatForPrefix(parameters.getMetadataPrefix()); Item item = getRepository().getItemRepository().getItem(parameters.getIdentifier()); if (getContext().hasCondition() && !getContext().getCondition().getFilter(getRepository().getFilterResolver()).isItemShown(item)) throw new IdDoesNotExistException("This context does not include this item"); if (format.hasCondition() && !format.getCondition().getFilter(getRepository().getFilterResolver()).isItemShown(item)) throw new CannotDisseminateRecordException("Format not applicable to this item"); Xrecord record = this.createRecord(parameters, item); GetRecord result = new XgetRecord(record); return result; }