Skip to content
Snippets Groups Projects
Commit f1559d80 authored by felmer's avatar felmer
Browse files

LMS-1206 First improvement.

SVN: 13071
parent d4c370af
No related branches found
No related tags found
No related merge requests found
...@@ -42,6 +42,6 @@ public class InfoBoxCallbackListener<T> extends CallbackListenerAdapter<T> ...@@ -42,6 +42,6 @@ public class InfoBoxCallbackListener<T> extends CallbackListenerAdapter<T>
final AbstractAsyncCallback<T> callback, final String failureMessage, final AbstractAsyncCallback<T> callback, final String failureMessage,
final Throwable throwable) final Throwable throwable)
{ {
infoBox.displayError(failureMessage); infoBox.displayError(failureMessage.replace("\n", "<br>"));
} }
} }
...@@ -23,6 +23,7 @@ import java.util.List; ...@@ -23,6 +23,7 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessException;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.dao.DataRetrievalFailureException; import org.springframework.dao.DataRetrievalFailureException;
import ch.systemsx.cisd.common.collections.IKeyExtractor; import ch.systemsx.cisd.common.collections.IKeyExtractor;
...@@ -55,6 +56,7 @@ import ch.systemsx.cisd.openbis.generic.shared.util.HibernateUtils; ...@@ -55,6 +56,7 @@ import ch.systemsx.cisd.openbis.generic.shared.util.HibernateUtils;
*/ */
public class VocabularyBO extends AbstractBusinessObject implements IVocabularyBO public class VocabularyBO extends AbstractBusinessObject implements IVocabularyBO
{ {
private static final int MAX_NUMBER_OF_INVAID_TERMS_IN_ERROR_MESSAGE = 10;
private VocabularyPE vocabularyPE; private VocabularyPE vocabularyPE;
public VocabularyBO(final IDAOFactory daoFactory, final Session session) public VocabularyBO(final IDAOFactory daoFactory, final Session session)
...@@ -209,9 +211,32 @@ public class VocabularyBO extends AbstractBusinessObject implements IVocabularyB ...@@ -209,9 +211,32 @@ public class VocabularyBO extends AbstractBusinessObject implements IVocabularyB
assert vocabularyPE != null : "Unspecified vocabulary"; assert vocabularyPE != null : "Unspecified vocabulary";
try try
{ {
StringBuilder builder = new StringBuilder();
int numberOfInvalidTerms = 0;
for (VocabularyTermPE term : vocabularyPE.getTerms()) for (VocabularyTermPE term : vocabularyPE.getTerms())
{ {
getVocabularyTermDAO().validate(term); try
{
getVocabularyTermDAO().validate(term);
} catch (DataIntegrityViolationException ex)
{
numberOfInvalidTerms++;
if (numberOfInvalidTerms <= MAX_NUMBER_OF_INVAID_TERMS_IN_ERROR_MESSAGE)
{
builder.append('\n').append(ex.getMessage());
}
}
}
if (builder.length() > 0)
{
builder.insert(0, "Invalid terms:");
int additionalTerms = numberOfInvalidTerms - MAX_NUMBER_OF_INVAID_TERMS_IN_ERROR_MESSAGE;
if (additionalTerms > 0)
{
builder.append("\n").append("and ").append(additionalTerms);
builder.append(" more invalid terms.");
}
throw new UserFailureException("Invalid terms:" + builder);
} }
getVocabularyDAO().createOrUpdateVocabulary(vocabularyPE); getVocabularyDAO().createOrUpdateVocabulary(vocabularyPE);
} catch (final DataAccessException e) } catch (final DataAccessException e)
......
...@@ -19,7 +19,7 @@ package ch.systemsx.cisd.openbis.generic.shared.dto; ...@@ -19,7 +19,7 @@ package ch.systemsx.cisd.openbis.generic.shared.dto;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
...@@ -79,7 +79,7 @@ public class VocabularyPE extends HibernateAbstractRegistrationHolder implements ...@@ -79,7 +79,7 @@ public class VocabularyPE extends HibernateAbstractRegistrationHolder implements
private String description; private String description;
private Set<VocabularyTermPE> terms = new HashSet<VocabularyTermPE>(); private Set<VocabularyTermPE> terms = new LinkedHashSet<VocabularyTermPE>();
private boolean managedInternally; private boolean managedInternally;
......
...@@ -206,7 +206,7 @@ public final class VocabularyBOTest extends AbstractBOTest ...@@ -206,7 +206,7 @@ public final class VocabularyBOTest extends AbstractBOTest
one(daoFactory).getHomeDatabaseInstance(); one(daoFactory).getHomeDatabaseInstance();
will(returnValue(ManagerTestTool.EXAMPLE_DATABASE_INSTANCE)); will(returnValue(ManagerTestTool.EXAMPLE_DATABASE_INSTANCE));
one(vocabularyTermDAO).validate(with(aNonNull(VocabularyTermPE.class))); exactly(3).of(vocabularyTermDAO).validate(with(aNonNull(VocabularyTermPE.class)));
will(throwException(new DataIntegrityViolationException(null))); will(throwException(new DataIntegrityViolationException(null)));
} }
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment