Commit e10936d8 by Anton Sudak

Fix possible issues in review block

* Do not handle NonUniqueResultException . It's not ok, it should fail loudly! * Mark targetId as unique and non-nullable column
parent 01e55c52
......@@ -29,8 +29,6 @@ import com.google.schemaorg.JsonLdSyntaxException;
import com.google.schemaorg.core.AggregateRating;
import com.google.schemaorg.core.CoreFactory;
import com.google.schemaorg.core.Thing;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import play.data.Form;
import play.data.validation.Constraints;
import play.mvc.Controller;
......@@ -42,12 +40,9 @@ import java.util.*;
@Entity
@Table(name = "cms_review", indexes = {
@Index(name = "targetId_index", columnList = "targetId")
})
@Table(name = "cms_review")
@DiscriminatorValue("ReviewBlock")
public class ReviewBlock extends ContentBlock implements WithSchemaorgStructuredData {
private final static Logger logger = LoggerFactory.getLogger(ReviewBlock.class);
public static final Integer FIVE_STAR = 5;
public static final Integer FOUR_STAR = 4;
......@@ -62,6 +57,7 @@ public class ReviewBlock extends ContentBlock implements WithSchemaorgStructured
}
@Constraints.Required
@Column(unique = true, nullable = false)
protected String targetId;
protected ReviewStatus status = ReviewStatus.CLOSED;
......@@ -333,12 +329,10 @@ public class ReviewBlock extends ContentBlock implements WithSchemaorgStructured
public T byTargetId(String id) {
try {
return query().andEquals("targetId", id).getSingleResult();
} catch (NonUniqueResultException | NoResultException e) {
logger.warn("Error retrieving ReviewBlock by targetId", e);
} catch (NoResultException e) {
return null;
}
}
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment