use of eu.europeana.metis.schema.jibx.Lat in project metis-framework by europeana.
the class PlaceFieldInputTest method testPlace.
@Test
void testPlace() {
PlaceImpl placeImpl = new PlaceImpl();
placeImpl.setAbout("test about");
RecordDao mongoServerMock = mock(RecordDao.class);
Datastore datastoreMock = mock(Datastore.class);
@SuppressWarnings("unchecked") Query<PlaceImpl> queryMock = mock(Query.class);
when(mongoServerMock.getDatastore()).thenReturn(datastoreMock);
when(datastoreMock.find(PlaceImpl.class)).thenReturn(queryMock);
when(datastoreMock.save(placeImpl)).thenReturn(placeImpl);
when(queryMock.filter(Filters.eq("about", placeImpl.getAbout()))).thenReturn(queryMock);
PlaceType place = new PlaceType();
place.setAbout("test about");
List<AltLabel> altLabelList = new ArrayList<>();
AltLabel altLabel = new AltLabel();
Lang lang = new Lang();
lang.setLang("en");
altLabel.setLang(lang);
altLabel.setString("test alt label");
assertNotNull(altLabel);
altLabelList.add(altLabel);
place.setAltLabelList(altLabelList);
List<Note> noteList = new ArrayList<>();
Note note = new Note();
note.setString("test note");
assertNotNull(note);
noteList.add(note);
place.setNoteList(noteList);
List<PrefLabel> prefLabelList = new ArrayList<>();
PrefLabel prefLabel = new PrefLabel();
prefLabel.setLang(lang);
prefLabel.setString("test pred label");
assertNotNull(prefLabel);
prefLabelList.add(prefLabel);
place.setPrefLabelList(prefLabelList);
List<IsPartOf> isPartOfList = new ArrayList<>();
IsPartOf isPartOf = new IsPartOf();
isPartOf.setString("test resource");
isPartOfList.add(isPartOf);
place.setIsPartOfList(isPartOfList);
Lat posLat = new Lat();
posLat.setLat(Float.valueOf("1.0"));
place.setLat(posLat);
_Long posLong = new _Long();
posLong.setLong(Float.valueOf("1.0"));
place.setLong(posLong);
// create mongo place
PlaceImpl placeMongo = new PlaceFieldInput().apply(place);
mongoServerMock.getDatastore().save(placeMongo);
assertEquals(place.getAbout(), placeMongo.getAbout());
assertEquals(place.getNoteList().get(0).getString(), placeMongo.getNote().values().iterator().next().get(0));
assertTrue(placeMongo.getAltLabel().containsKey(place.getAltLabelList().get(0).getLang().getLang()));
assertEquals(place.getAltLabelList().get(0).getString(), placeMongo.getAltLabel().values().iterator().next().get(0));
assertEquals(place.getPrefLabelList().get(0).getString(), placeMongo.getPrefLabel().values().iterator().next().get(0));
assertEquals(place.getIsPartOfList().get(0).getString(), placeMongo.getIsPartOf().values().iterator().next().get(0));
assertEquals(Float.toString(place.getLat().getLat()), Float.toString(placeMongo.getLatitude()));
assertEquals(Float.toString(place.getLong().getLong()), Float.toString(placeMongo.getLongitude()));
}
use of eu.europeana.metis.schema.jibx.Lat in project metis-framework by europeana.
the class EntityMergeEngine method convertPlace.
private static PlaceType convertPlace(Place place) {
PlaceType placeType = new PlaceType();
// about
ItemExtractorUtils.setAbout(place, placeType);
// alt
if (place.getAlt() != null) {
Alt alt = new Alt();
alt.setAlt(Float.valueOf(place.getAlt()));
placeType.setAlt(alt);
}
// altlabels
placeType.setAltLabelList(ItemExtractorUtils.extractLabels(place.getAltLabelList(), AltLabel::new));
// hasPartList
placeType.setHasPartList(ItemExtractorUtils.extractLabelResources(place.getHasPartsList(), HasPart::new));
// isPartOf
if (place.getIsPartOf() != null) {
placeType.setIsPartOfList(ItemExtractorUtils.extractLabelResources(place.getIsPartOf(), IsPartOf::new));
}
// lat
if (place.getLat() != null) {
Lat lat = new Lat();
lat.setLat(Float.valueOf(place.getLat()));
placeType.setLat(lat);
}
// _long
if (place.getLon() != null) {
_Long longitude = new _Long();
longitude.setLong(Float.valueOf(place.getLon()));
placeType.setLong(longitude);
}
// noteList
placeType.setNoteList(ItemExtractorUtils.extractLabels(place.getNotes(), Note::new));
// prefLabelList
placeType.setPrefLabelList(ItemExtractorUtils.extractLabels(place.getPrefLabelList(), PrefLabel::new));
// sameAsList
placeType.setSameAList(ItemExtractorUtils.extractResources(place.getSameAs(), SameAs::new));
// Done
return placeType;
}
use of eu.europeana.metis.schema.jibx.Lat in project metis-framework by europeana.
the class ContextualClassesBreakdownClassifierTest method testEntityQualifiesForPlace.
@Test
void testEntityQualifiesForPlace() {
// Create objects
final ContextualClassesClassifier classifier = spy(new ContextualClassesClassifier());
final PlaceType place = new PlaceType();
final List<PrefLabel> prefLabelList = new ArrayList<>();
// Test empty time span
assertFalse(classifier.entityQualifies(place));
// Set values
place.setPrefLabelList(prefLabelList);
place.setLat(new Lat());
place.getLat().setLat(0.0F);
place.setLong(new _Long());
place.getLong().setLong(0.0F);
// Test all present
doReturn(true).when(classifier).hasLiteralProperty(prefLabelList);
assertTrue(classifier.entityQualifies(place));
// Test without pref label list
doReturn(false).when(classifier).hasLiteralProperty(prefLabelList);
assertFalse(classifier.entityQualifies(place));
doReturn(true).when(classifier).hasLiteralProperty(prefLabelList);
assertTrue(classifier.entityQualifies(place));
// Test without lat
place.getLat().setLat(null);
assertFalse(classifier.entityQualifies(place));
place.setLat(null);
assertFalse(classifier.entityQualifies(place));
place.setLat(new Lat());
place.getLat().setLat(0.0F);
assertTrue(classifier.entityQualifies(place));
// Test without lon
place.getLong().setLong(null);
assertFalse(classifier.entityQualifies(place));
place.setLong(null);
assertFalse(classifier.entityQualifies(place));
}
Aggregations