Skip to content

Commit

Permalink
Merging updates from Hugo
Browse files Browse the repository at this point in the history
  • Loading branch information
nshweta90 committed May 27, 2024
1 parent 4887506 commit 0f59eea
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import com.mongodb.lang.Nullable;

import dev.morphia.mapping.Mapper;
import dev.morphia.query.FindOptions;
import dev.morphia.query.Projection;

/**
* @author Hugo
Expand All @@ -34,14 +32,15 @@ public ProjectionNew(FindOptions options) {
* @return this
* @see <a href="https://docs.mongodb.com/manual/tutorial/project-fields-from-query-results/">Project Fields to Return from Query</a>
*/
@Override
public FindOptions include(String... fields) {
if (projection == null) { projection = new Document(); }
for ( String field : fields ) {
projection.put(field, 1);
}
return super.include(fields);
}

@Override
@Nullable
public Document map(Mapper mapper, Class<?> type) {
return projection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package eu.europeana.api.record.db.repository;

import dev.morphia.Datastore;
import dev.morphia.internal.DatastoreHolder;
import dev.morphia.query.FindOptions;
import dev.morphia.query.MorphiaCursor;
import dev.morphia.query.filters.Filter;
Expand All @@ -28,11 +27,11 @@ public class RecordRepository {
/**
* Saves the given record to the database.
*
* @param record record to save
* @param recordItem record to save
* @return saved record
*/
public ProvidedCHO save(ProvidedCHO record) {
return datastore.save(record);
public ProvidedCHO save(ProvidedCHO recordItem) {
return datastore.save(recordItem);
}


Expand Down Expand Up @@ -74,11 +73,12 @@ public ProvidedCHO findById(String recordId) {
*/
public ProvidedCHO findById(String recordId, FindOptions opts) {
List<Filter> filters = new ArrayList<>();
filters.add(Filters.eq("id", recordId));
filters.add(Filters.eq("id", recordId).isValidating(false));

return datastore
.find(ProvidedCHO.class)
.filter(filters.toArray(Filter[]::new))
.disableValidation()
.iterator(opts)
.tryNext();
}
Expand Down Expand Up @@ -112,15 +112,5 @@ public Datastore getDatastore() {
return datastore;
}

// public void save(EDMClass o)
// {
// if ( o != null ) {
// long count = datastore.find(o.getClass()).filter(Filters.eq("id", o.getID())).count();
// if ( count > 0 ) { return; }
//
// datastore.save(o);
// }
// }


}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package eu.europeana.api.record.profile;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
Expand All @@ -26,7 +25,6 @@ public class ViewProfileRegistry
static {

//Metadata profiles
newProfile("external");

Profile metaBasic = newProfile("meta.basic").expand("id").expandBase("proxies"
, "id", "type", "title", "description", "creator", "edmType"
Expand Down Expand Up @@ -165,13 +163,8 @@ public static Profile buildProfile(String... profileNames) {

public static FindOptions getProjection(String... profileNames) {
FindOptions opts = new FindOptions();
Profile profile = buildProfile(profileNames);
if ( !profile.isEmpty() ) {
newProjection(opts).include(profile.toArray(String[]::new));
}
else if ( Arrays.asList(profileNames).contains("external") ) {
opts.projection().exclude("proxies");
}
Projection proj = newProjection(opts);
proj.include(buildProfile(profileNames).toArray(new String[] {}));
return opts;
}

Expand Down Expand Up @@ -244,12 +237,4 @@ protected Profile clean() {
return this;
}
}

public static final void main(String[] args) {
Profile profile = ViewProfileRegistry.buildProfile("meta.full", "prov.full", "media.full");
profile.clean();
for ( String field : profile ) {
System.out.println(field);
}
}
}

1 comment on commit 0f59eea

@Luthien-in-edhil
Copy link
Member

Choose a reason for hiding this comment

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

Looks OK

Please sign in to comment.