@Test public void testToJsonObject() { NdkPageMapper mapper = new NdkPageMapper(); ModsDefinition mods = ModsUtils.unmarshal(PageMapperTest.class.getResource("page_mods.xml"), ModsDefinition.class); Page result = mapper.toJsonObject(mods, new Context("uuid:test")); assertNotNull(result); assertEquals("1", result.getIndex()); assertEquals("[1]", result.getNumber()); assertEquals("Blank", result.getType()); assertEquals("note", result.getPhysicalDescription()); List<IdentifierItem> identifiers = result.getIdentifiers(); assertEquals(2, identifiers.size()); assertEquals("issn", identifiers.get(0).getType()); assertEquals("issn value", identifiers.get(0).getValue()); assertEquals("uuid", identifiers.get(1).getType()); assertEquals("1", identifiers.get(1).getValue()); }
@Override public Page toJsonObject(ModsDefinition mods, Context ctx) { Page page = new Page(); if (NdkPlugin.MODEL_NDK_PAGE.equals(super.getModelId())) { for (TitleInfoDefinition titleInfo : mods.getTitleInfo()) { page.setTitle(getTitleDefinitionValue(titleInfo, "title")); page.setSubtitle(getTitleDefinitionValue(titleInfo, "subtitle")); } for (NoteDefinition noteDefinition : mods.getNote()) { page.setNote(noteDefinition.getValue() == null ? "" : noteDefinition.getValue()); } for (GenreDefinition genreDefinition : mods.getGenre()) { page.setGenre(genreDefinition.getValue() == null ? "" : genreDefinition.getValue()); } for (TypeOfResourceDefinition typeOfResourceDefinition : mods.getTypeOfResource()) { page.setTypeOfResource(typeOfResourceDefinition.getValue() == null ? "" : typeOfResourceDefinition.getValue()); } for (PhysicalDescriptionDefinition physicalDescription : mods.getPhysicalDescription()) { page.setPhysicalDescription(getPhysicalDescriptionValue(physicalDescription)); } for (PartDefinition partDefinition : mods.getPart()) { page.setExtent(getExtentValue(partDefinition)); } } else { List<PartDefinition> parts = mods.getPart(); if (!parts.isEmpty()) { PartDefinition part = parts.get(0); List<Text> partTexts = part.getText(); if (!partTexts.isEmpty()) { Text partText = partTexts.get(0); page.setPhysicalDescription(partText.getValue()); } } } if (!mods.getPart().isEmpty()) { String pageIndex = null; String pageNumber = null; String pageType = null; for (PartDefinition part : mods.getPart()) { if (pageIndex == null) { pageIndex = getNumber(getDetail(part.getDetail(), NUMBER_TYPE_PAGE_INDEX)); } if (pageNumber == null) { pageNumber = getNumber(getDetail(part.getDetail(), NUMBER_TYPE_PAGE_NUMBER)); } if (pageType == null) { if (part.getType() != null) { pageType = part.getType(); } } } if (pageType == null) { pageType = PAGE_TYPE_NORMAL; } page.setType(pageType); page.setNumber(pageNumber); page.setIndex(pageIndex); } else { page.setType(PAGE_TYPE_NORMAL); } page.setIdentifiers(getIdentifierItems(mods.getIdentifier())); return page; }
NdkPageMapper extends NdkMapper { @Override public Page toJsonObject(ModsDefinition mods, Context ctx) { Page page = new Page(); if (NdkPlugin.MODEL_NDK_PAGE.equals(super.getModelId())) { for (TitleInfoDefinition titleInfo : mods.getTitleInfo()) { page.setTitle(getTitleDefinitionValue(titleInfo, "title")); page.setSubtitle(getTitleDefinitionValue(titleInfo, "subtitle")); } for (NoteDefinition noteDefinition : mods.getNote()) { page.setNote(noteDefinition.getValue() == null ? "" : noteDefinition.getValue()); } for (GenreDefinition genreDefinition : mods.getGenre()) { page.setGenre(genreDefinition.getValue() == null ? "" : genreDefinition.getValue()); } for (TypeOfResourceDefinition typeOfResourceDefinition : mods.getTypeOfResource()) { page.setTypeOfResource(typeOfResourceDefinition.getValue() == null ? "" : typeOfResourceDefinition.getValue()); } for (PhysicalDescriptionDefinition physicalDescription : mods.getPhysicalDescription()) { page.setPhysicalDescription(getPhysicalDescriptionValue(physicalDescription)); } for (PartDefinition partDefinition : mods.getPart()) { page.setExtent(getExtentValue(partDefinition)); } } else { List<PartDefinition> parts = mods.getPart(); if (!parts.isEmpty()) { PartDefinition part = parts.get(0); List<Text> partTexts = part.getText(); if (!partTexts.isEmpty()) { Text partText = partTexts.get(0); page.setPhysicalDescription(partText.getValue()); } } } if (!mods.getPart().isEmpty()) { String pageIndex = null; String pageNumber = null; String pageType = null; for (PartDefinition part : mods.getPart()) { if (pageIndex == null) { pageIndex = getNumber(getDetail(part.getDetail(), NUMBER_TYPE_PAGE_INDEX)); } if (pageNumber == null) { pageNumber = getNumber(getDetail(part.getDetail(), NUMBER_TYPE_PAGE_NUMBER)); } if (pageType == null) { if (part.getType() != null) { pageType = part.getType(); } } } if (pageType == null) { pageType = PAGE_TYPE_NORMAL; } page.setType(pageType); page.setNumber(pageNumber); page.setIndex(pageIndex); } else { page.setType(PAGE_TYPE_NORMAL); } page.setIdentifiers(getIdentifierItems(mods.getIdentifier())); return page; } }
NdkPageMapper extends NdkMapper { @Override public Page toJsonObject(ModsDefinition mods, Context ctx) { Page page = new Page(); if (NdkPlugin.MODEL_NDK_PAGE.equals(super.getModelId())) { for (TitleInfoDefinition titleInfo : mods.getTitleInfo()) { page.setTitle(getTitleDefinitionValue(titleInfo, "title")); page.setSubtitle(getTitleDefinitionValue(titleInfo, "subtitle")); } for (NoteDefinition noteDefinition : mods.getNote()) { page.setNote(noteDefinition.getValue() == null ? "" : noteDefinition.getValue()); } for (GenreDefinition genreDefinition : mods.getGenre()) { page.setGenre(genreDefinition.getValue() == null ? "" : genreDefinition.getValue()); } for (TypeOfResourceDefinition typeOfResourceDefinition : mods.getTypeOfResource()) { page.setTypeOfResource(typeOfResourceDefinition.getValue() == null ? "" : typeOfResourceDefinition.getValue()); } for (PhysicalDescriptionDefinition physicalDescription : mods.getPhysicalDescription()) { page.setPhysicalDescription(getPhysicalDescriptionValue(physicalDescription)); } for (PartDefinition partDefinition : mods.getPart()) { page.setExtent(getExtentValue(partDefinition)); } } else { List<PartDefinition> parts = mods.getPart(); if (!parts.isEmpty()) { PartDefinition part = parts.get(0); List<Text> partTexts = part.getText(); if (!partTexts.isEmpty()) { Text partText = partTexts.get(0); page.setPhysicalDescription(partText.getValue()); } } } if (!mods.getPart().isEmpty()) { String pageIndex = null; String pageNumber = null; String pageType = null; for (PartDefinition part : mods.getPart()) { if (pageIndex == null) { pageIndex = getNumber(getDetail(part.getDetail(), NUMBER_TYPE_PAGE_INDEX)); } if (pageNumber == null) { pageNumber = getNumber(getDetail(part.getDetail(), NUMBER_TYPE_PAGE_NUMBER)); } if (pageType == null) { if (part.getType() != null) { pageType = part.getType(); } } } if (pageType == null) { pageType = PAGE_TYPE_NORMAL; } page.setType(pageType); page.setNumber(pageNumber); page.setIndex(pageIndex); } else { page.setType(PAGE_TYPE_NORMAL); } page.setIdentifiers(getIdentifierItems(mods.getIdentifier())); return page; }  }
NdkPageMapper extends NdkMapper { @Override public Page toJsonObject(ModsDefinition mods, Context ctx) { Page page = new Page(); if (NdkPlugin.MODEL_NDK_PAGE.equals(super.getModelId())) { for (TitleInfoDefinition titleInfo : mods.getTitleInfo()) { page.setTitle(getTitleDefinitionValue(titleInfo, "title")); page.setSubtitle(getTitleDefinitionValue(titleInfo, "subtitle")); } for (NoteDefinition noteDefinition : mods.getNote()) { page.setNote(noteDefinition.getValue() == null ? "" : noteDefinition.getValue()); } for (GenreDefinition genreDefinition : mods.getGenre()) { page.setGenre(genreDefinition.getValue() == null ? "" : genreDefinition.getValue()); } for (TypeOfResourceDefinition typeOfResourceDefinition : mods.getTypeOfResource()) { page.setTypeOfResource(typeOfResourceDefinition.getValue() == null ? "" : typeOfResourceDefinition.getValue()); } for (PhysicalDescriptionDefinition physicalDescription : mods.getPhysicalDescription()) { page.setPhysicalDescription(getPhysicalDescriptionValue(physicalDescription)); } for (PartDefinition partDefinition : mods.getPart()) { page.setExtent(getExtentValue(partDefinition)); } } else { List<PartDefinition> parts = mods.getPart(); if (!parts.isEmpty()) { PartDefinition part = parts.get(0); List<Text> partTexts = part.getText(); if (!partTexts.isEmpty()) { Text partText = partTexts.get(0); page.setPhysicalDescription(partText.getValue()); } } } if (!mods.getPart().isEmpty()) { String pageIndex = null; String pageNumber = null; String pageType = null; for (PartDefinition part : mods.getPart()) { if (pageIndex == null) { pageIndex = getNumber(getDetail(part.getDetail(), NUMBER_TYPE_PAGE_INDEX)); } if (pageNumber == null) { pageNumber = getNumber(getDetail(part.getDetail(), NUMBER_TYPE_PAGE_NUMBER)); } if (pageType == null) { if (part.getType() != null) { pageType = part.getType(); } } } if (pageType == null) { pageType = PAGE_TYPE_NORMAL; } page.setType(pageType); page.setNumber(pageNumber); page.setIndex(pageIndex); } else { page.setType(PAGE_TYPE_NORMAL); } page.setIdentifiers(getIdentifierItems(mods.getIdentifier())); return page; }  static ResourceBundle getPageTypeLabels(Locale locale); static String getPageTypeLabel(String pageType, Locale locale); @Override void createMods(ModsDefinition mods, Context ctx); @Override Page toJsonObject(ModsDefinition mods, Context ctx); @Override ModsDefinition fromJsonObject(ObjectMapper jsMapper, String json, Context ctx); ModsDefinition createPage(String pid, String pageIndex, String pageNumber, String pageType); ModsDefinition createPage(String pageIndex, String pageNumber, String pageType, Context ctx); ModsDefinition toMods(Page page, Context ctx); ModsDefinition toMods(Page page, ModsDefinition mods); }
NdkPageMapper extends NdkMapper { @Override public Page toJsonObject(ModsDefinition mods, Context ctx) { Page page = new Page(); if (NdkPlugin.MODEL_NDK_PAGE.equals(super.getModelId())) { for (TitleInfoDefinition titleInfo : mods.getTitleInfo()) { page.setTitle(getTitleDefinitionValue(titleInfo, "title")); page.setSubtitle(getTitleDefinitionValue(titleInfo, "subtitle")); } for (NoteDefinition noteDefinition : mods.getNote()) { page.setNote(noteDefinition.getValue() == null ? "" : noteDefinition.getValue()); } for (GenreDefinition genreDefinition : mods.getGenre()) { page.setGenre(genreDefinition.getValue() == null ? "" : genreDefinition.getValue()); } for (TypeOfResourceDefinition typeOfResourceDefinition : mods.getTypeOfResource()) { page.setTypeOfResource(typeOfResourceDefinition.getValue() == null ? "" : typeOfResourceDefinition.getValue()); } for (PhysicalDescriptionDefinition physicalDescription : mods.getPhysicalDescription()) { page.setPhysicalDescription(getPhysicalDescriptionValue(physicalDescription)); } for (PartDefinition partDefinition : mods.getPart()) { page.setExtent(getExtentValue(partDefinition)); } } else { List<PartDefinition> parts = mods.getPart(); if (!parts.isEmpty()) { PartDefinition part = parts.get(0); List<Text> partTexts = part.getText(); if (!partTexts.isEmpty()) { Text partText = partTexts.get(0); page.setPhysicalDescription(partText.getValue()); } } } if (!mods.getPart().isEmpty()) { String pageIndex = null; String pageNumber = null; String pageType = null; for (PartDefinition part : mods.getPart()) { if (pageIndex == null) { pageIndex = getNumber(getDetail(part.getDetail(), NUMBER_TYPE_PAGE_INDEX)); } if (pageNumber == null) { pageNumber = getNumber(getDetail(part.getDetail(), NUMBER_TYPE_PAGE_NUMBER)); } if (pageType == null) { if (part.getType() != null) { pageType = part.getType(); } } } if (pageType == null) { pageType = PAGE_TYPE_NORMAL; } page.setType(pageType); page.setNumber(pageNumber); page.setIndex(pageIndex); } else { page.setType(PAGE_TYPE_NORMAL); } page.setIdentifiers(getIdentifierItems(mods.getIdentifier())); return page; }  static ResourceBundle getPageTypeLabels(Locale locale); static String getPageTypeLabel(String pageType, Locale locale); @Override void createMods(ModsDefinition mods, Context ctx); @Override Page toJsonObject(ModsDefinition mods, Context ctx); @Override ModsDefinition fromJsonObject(ObjectMapper jsMapper, String json, Context ctx); ModsDefinition createPage(String pid, String pageIndex, String pageNumber, String pageType); ModsDefinition createPage(String pageIndex, String pageNumber, String pageType, Context ctx); ModsDefinition toMods(Page page, Context ctx); ModsDefinition toMods(Page page, ModsDefinition mods); static final String PAGE_TYPE_NORMAL; static final String RESOURCE_TYPE_TEXT; }