Commit 0f9e7235 authored by Maxym Borodenko's avatar Maxym Borodenko
Browse files

Don't create a new globalArticle if already exists

parent 38e1e303
......@@ -28,6 +28,7 @@ import org.genesys2.server.exception.InvalidApiUsageException;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.service.AmphibianService.AmphibianException;
import org.genesys2.server.service.AmphibianService.AmphibianNotAvailableException;
import org.genesys2.server.service.CRMException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.ConcurrencyFailureException;
......@@ -144,7 +145,21 @@ public class ApiExceptionHandler {
LOG.warn("Invalid argument {} for {} provided {} {}", e.getName(), e.getParameter(), request.getMethod(), request.getRequestURL());
return new ApiError<>(e);
}
/**
* Handle CRM exceptions.
*
* @param e the e
* @param request the request
* @return the api error
*/
@ResponseStatus(code = HttpStatus.BAD_REQUEST)
@ExceptionHandler({ CRMException.class })
@ResponseBody
public ApiError<Exception> handleCRMExceptions(final Exception e, final HttpServletRequest request) {
LOG.warn("CRM: {} for {} {}", e.getMessage(), request.getMethod(), request.getRequestURL());
return new ApiError<>(e);
}
/**
* Handle invalid api usage.
......
......@@ -546,6 +546,10 @@ public class ContentServiceImpl implements ContentService {
throw new CRMException("Global articles must first be created in primary language=" + getDefaultLocale().getLanguage());
}
if (primaryArticle != null && primaryArticle.getLang().equals(locale.getLanguage())) {
throw new CRMException(String.format("Global article with slug='%s' and language='%s' already exists.", slug, locale.getLanguage()));
}
Article article = new Article();
if (primaryArticle == null) {
article.setTemplate(isTemplate);
......
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