Skip to content

Commit

Permalink
Refactoring/Improving source: repository & fix log() (#1601)
Browse files Browse the repository at this point in the history
Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
  • Loading branch information
avgustinmm committed Feb 3, 2024
1 parent 9631292 commit a7f7b0f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,23 @@
*/
package org.eclipse.hawkbit.repository;

import com.cronutils.utils.StringUtils;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

import lombok.extern.slf4j.Slf4j;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.parser.Parser;
import org.jsoup.safety.Cleaner;
import org.jsoup.safety.Safelist;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.cronutils.utils.StringUtils;

/**
* Safe html constraint validator for strings submitted into the repository.
*
*/
@Slf4j
public class ValidStringValidator implements ConstraintValidator<ValidString, String> {
private static final Logger LOG = LoggerFactory.getLogger(ValidStringValidator.class);

private final Cleaner cleaner = new Cleaner(Safelist.none());

Expand All @@ -40,7 +38,7 @@ private boolean isValidString(final String value) {
try {
return cleaner.isValid(stringToDocument(value));
} catch (final Exception ex) {
LOG.error(String.format("There was an exception during bean field value (%s) validation", value), ex);
log.error(String.format("There was an exception during bean field value (%s) validation", value), ex);
return false;
}
}
Expand All @@ -53,5 +51,4 @@ private static Document stringToDocument(final String value) {

return resultingDocument;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,22 @@

import java.util.Optional;

import lombok.extern.slf4j.Slf4j;
import org.eclipse.hawkbit.repository.event.remote.EventEntityManagerHolder;
import org.eclipse.hawkbit.repository.event.remote.RemoteIdEvent;
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
* A base definition class for remote events which contain a tenant aware base
* entity.
*
* @param <E>
* the type of the entity
* @param <E> the type of the entity
*/
@Slf4j
public class RemoteEntityEvent<E extends TenantAwareBaseEntity> extends RemoteIdEvent {

private static final Logger LOG = LoggerFactory.getLogger(RemoteEntityEvent.class);

private static final long serialVersionUID = 1L;

private transient E entity;
Expand Down Expand Up @@ -69,9 +66,8 @@ private E reloadEntityFromRepository() {
return EventEntityManagerHolder.getInstance().getEventEntityManager().findEntity(getTenant(), getEntityId(),
clazz);
} catch (final ClassNotFoundException e) {
LOG.error("Cannot reload entity because class is not found", e);
log.error("Cannot reload entity because class is not found", e);
}
return null;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public static List<String> getAllAuthorities() {
final String role = (String) field.get(null);
allPermissions.add(role);
} catch (final IllegalAccessException e) {
log().error(e.getMessage(), e);
log.error(e.getMessage(), e);
}
}
}
Expand Down

0 comments on commit a7f7b0f

Please sign in to comment.