Skip to content

Commit

Permalink
addressing code quality issues
Browse files Browse the repository at this point in the history
  • Loading branch information
GordeaS authored and GordeaS committed Mar 18, 2024
1 parent 8ee97d1 commit 4586e78
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 59 deletions.
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<!--
<configuration>
<source>${version.java}</source>
<target>${version.java}</target>
</configuration>
-->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
4 changes: 0 additions & 4 deletions set-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<!--
<version>${version.maven-surefire-plugin}}</version>
-->

</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,11 @@ public PersistentUserSet getByIdentifier(String identifier) {
public long getDistinct(String field, boolean fieldIsArray, String collectionType)
throws UserSetServiceException {
long count = 0;
// Cursor is needed in aggregate command
// AggregationOptions aggregationOptions =
// AggregationOptions.builder().outputMode(AggregationOptions. OutputMode.CURSOR).build();
AggregationOptions aggregationOptions =
AggregationOptions.builder().allowDiskUse(true).build();
AggregationOptions.builder().allowDiskUse(Boolean.TRUE).build();
Cursor cursor = getDao().getCollection().aggregate(
getDistinctCountPipeline(field, fieldIsArray, collectionType), aggregationOptions);
if (cursor != null && cursor.hasNext()) {
if (cursor.hasNext()) {
// ideally there should be only one value present.
count = Long.parseLong(cursor.next().get(UserSetMongoConstants.MONGO_FIELD_COUNT).toString());

Expand All @@ -141,18 +138,16 @@ public long getDistinct(String field, boolean fieldIsArray, String collectionTyp

@Override
public long countItemsInEntitySets() {
// Cursor is needed in aggregate command
// AggregationOptions aggregationOptions =
// AggregationOptions.builder().outputMode(AggregationOptions.OutputMode.CURSOR).build();
AggregationOptions aggregationOptions =
AggregationOptions.builder().allowDiskUse(true).build();
AggregationOptions.builder().allowDiskUse(Boolean.TRUE).build();
long totalItems = 0;
Map<String, DBObject> groupFieldsAdditional = new ConcurrentHashMap<>();
groupFieldsAdditional.put(UserSetMongoConstants.MONGO_FIELD_COUNT,
new BasicDBObject(UserSetMongoConstants.MONGO_SUM, UserSetMongoConstants.MONGO_TOTAL));
Cursor cursor = getDao().getCollection().aggregate(
getAggregatePipeline(UserSetTypes.ENTITYBESTITEMSSET.getJsonValue(), groupFieldsAdditional), aggregationOptions);
if (cursor != null && cursor.hasNext()) {
getAggregatePipeline(UserSetTypes.ENTITYBESTITEMSSET.getJsonValue(), groupFieldsAdditional),
aggregationOptions);
if (cursor.hasNext()) {
totalItems =
Long.parseLong(cursor.next().get(UserSetMongoConstants.MONGO_FIELD_COUNT).toString());
}
Expand Down Expand Up @@ -274,21 +269,19 @@ public long count(UserSetQuery query) {
public Map<String, Long> getFacets(UserSetFacetQuery facetQuery) {
Map<String, Long> valueCountMap = new LinkedHashMap<>();
// Cursor is needed in aggregate command
AggregationOptions aggregationOptions =
AggregationOptions.builder().allowDiskUse(null).build();
AggregationOptions aggregationOptions = AggregationOptions.builder().allowDiskUse(null).build();
Cursor cursor =
getDao().getCollection().aggregate(getFacetPipeline(facetQuery), aggregationOptions);
if (cursor != null) {
while (cursor.hasNext()) {
DBObject object = cursor.next();
@SuppressWarnings("unchecked")
List<DBObject> facet = (List<DBObject>) object.get(facetQuery.getOutputField());
for (DBObject o : facet) {
valueCountMap.put(String.valueOf(o.get(UserSetMongoConstants.MONGO_ID)),
Long.parseLong(o.get(UserSetMongoConstants.MONGO_FIELD_COUNT).toString()));
}
while (cursor.hasNext()) {
DBObject object = cursor.next();
@SuppressWarnings("unchecked")
List<DBObject> facet = (List<DBObject>) object.get(facetQuery.getOutputField());
for (DBObject o : facet) {
valueCountMap.put(String.valueOf(o.get(UserSetMongoConstants.MONGO_ID)),
Long.parseLong(o.get(UserSetMongoConstants.MONGO_FIELD_COUNT).toString()));
}
}

return valueCountMap;
}

Expand Down Expand Up @@ -341,7 +334,7 @@ private DBObject getOutputFieldAndStages(UserSetFacetQuery facetQuery) {
public long countTotalLikes() {
// Cursor is needed in aggregate command
AggregationOptions aggregationOptions =
AggregationOptions.builder().allowDiskUse(true).build();
AggregationOptions.builder().allowDiskUse(Boolean.TRUE).build();

long totalLikes = 0;
Map<String, DBObject> groupFieldsAdditional = new ConcurrentHashMap<>();
Expand All @@ -350,13 +343,12 @@ public long countTotalLikes() {
Cursor cursor = getDao().getCollection().aggregate(
getAggregatePipeline(UserSetTypes.BOOKMARKSFOLDER.getJsonValue(), groupFieldsAdditional),
aggregationOptions);
if (cursor != null) {
while (cursor.hasNext()) {
DBObject object = cursor.next();
totalLikes +=
Long.parseLong(String.valueOf(object.get(UserSetMongoConstants.MONGO_TOTAL_LIKES)));
}
while (cursor.hasNext()) {
DBObject object = cursor.next();
totalLikes +=
Long.parseLong(String.valueOf(object.get(UserSetMongoConstants.MONGO_TOTAL_LIKES)));
}

return totalLikes;
}

Expand Down Expand Up @@ -423,10 +415,10 @@ private void setPaginationOptions(Query<PersistentUserSet> mongoQuery, UserSetQu
private Query<PersistentUserSet> buildMongoQuery(UserSetQuery query) {

Query<PersistentUserSet> searchQuery = buildUserConditionsQuery(query);

setPaginationOptions(searchQuery, query);
setOrder(searchQuery, query);

if (query.isAdmin()) {
// admin can see all
return searchQuery;
Expand All @@ -445,7 +437,7 @@ private Query<PersistentUserSet> buildMongoQuery(UserSetQuery query) {
// private only, user can see only his private sets
searchQuery.filter(FIELD_CREATOR, query.getUser());
}

return searchQuery;
}

Expand Down Expand Up @@ -502,13 +494,13 @@ private void setOrder(Query<PersistentUserSet> mongoQuery, UserSetQuery query) {
mongoQuery.order(Sort.descending(WebUserSetModelFields.MODIFIED));
return;
}

for (String sortField : query.getSortCriteria()) {
// check the score sort first (it can only be in desc order)
if (sortField.contains(WebUserSetFields.TEXT_SCORE_SORT)) {
mongoQuery.order(Meta.textScore());
mongoQuery.order(Sort.ascending(UserSetMongoConstants.MONGO_ID));

} else {
if (!sortField.contains(" ")) {
mongoQuery.order(Sort.ascending(sortField));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package eu.europeana.set.web.config;

/**
* Abstract class to keep an inventory of bean names
*/
public abstract class BeanNames {
public static final String BEAN_SET_MONGO_STORE = "set_db_morphia_datastore_set";
public static final String BEAN_SET_PERSITENCE_SERVICE = "set_db_setService";
public static final String BEAN_I18N_SERVICE = "i18nService";

private BeanNames() {}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
ignoreResourceNotFound = true)
public class MongoConfig {

@Value("${mongodb.set.connectionUrl:}")
@Value("${mongodb.set.connectionUrl:''}")
private String mongoConnectionUrl;

@Value("${mongodb.set.truststore:}")
@Value("${mongodb.set.truststore:''}")
private String mongoTrustStore;

@Value("${mongodb.set.truststorepass:}")
@Value("${mongodb.set.truststorepass:''}")
private String mongoTrustStorePass;

private static final String[] MODEL_PACKAGES = new String[]{"eu.europeana.set.definitions", "eu.europeana.api.commons.nosql.entity"};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,27 @@
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;

/**
* Class for configuration of SpringDoc
*/
@Configuration
@OpenAPIDefinition
public class SpringDocConfig {

private final BuildProperties buildProperties;

// private final BuildProperties buildInfo;

/**
* Initialize SpringDoc with API build information
* @param buildInfo object for retrieving build information
* @param buildProperties object for retrieving build information
*/
public SpringDocConfig(BuildProperties buildProperties) {
this.buildProperties = buildProperties;
}

/**
* create OpenAPI bean with required information
* @return the opeApi bean
*/
@Bean
public OpenAPI userServiceOpenAPI() {
return new OpenAPI().info(new Info().title(buildProperties.getName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@

import org.springframework.context.annotation.Configuration;

/**
* CLass to autoconfigure application by instantiating required beans
*/
@Configuration()
public class UserSetAutoConfig{

// @Bean("messageSource")
// public MessageSource getMessageSource() {
// ReloadableResourceBundleMessageSource messageSource =
// new ReloadableResourceBundleMessageSource();
// messageSource.setBasename("classpath:messages");
// messageSource.setDefaultEncoding("utf-8");
// messageSource.setDefaultLocale(Locale.ENGLISH);
// return messageSource;
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
import eu.europeana.set.web.config.BeanNames;
import eu.europeana.set.web.service.RequestPathMethodService;

/**
* Controller for handling application exceptions
*/
@ControllerAdvice
public class GlobalExceptionHandler extends EuropeanaGlobalExceptionHandler {

I18nService i18nService;

@Override
protected I18nService getI18nService() {
return i18nService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public UserSetErrorController(ErrorAttributes errorAttributes) {
}


/**
* handle /error requests
* @param request the request object
* @return ,app with default error attributes
*/
@GetMapping(value = "/error", produces = {HttpHeaders.CONTENT_TYPE_JSON_UTF8, HttpHeaders.CONTENT_TYPE_JSONLD})
@ResponseBody
public Map<String, Object> error(final HttpServletRequest request) {
Expand Down

0 comments on commit 4586e78

Please sign in to comment.