This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ZNTA-1073) : create custom exceptions + handlers (#1169)
* fix(ZNTA-1073):Fix NullPointerEx on iteration view Throw EntityNotFoundException instead of NullPointerException when attempt to access non-existing project through writing invalid project slug on the iteration page * fix(ZNTA-1073):create custom exceptions + handlers Create ProjectNotFoundEx and VersionNotFoundEx and throw them when trying to write invalid project or iteration slug on project view or iteration view pages. Handle these exceptions and return warn page with the proper warning message. * fix(ZNTA-1073):change the structure of the ex.s Instead of passing parameters on the warning page for the error messages, creating constructors with slug arguments and passing project slug and version slug parameters when throwing the exceptions. Also, rename warn page to missing_entity. * fix(ZNTA-1073) : Add header comment * fix(ZNTA-1073) : remove unnecessary comment * fix(ZNTA-1073): change the exception message
- Loading branch information
1 parent
90af336
commit 62148e1
Showing
10 changed files
with
223 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
zanata-war/src/main/java/org/zanata/exception/ProjectNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2016, Red Hat, Inc. and individual contributors as indicated by the | ||
* @author tags. See the copyright.txt file in the distribution for a full | ||
* listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it under the | ||
* terms of the GNU Lesser General Public License as published by the Free | ||
* Software Foundation; either version 2.1 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this software; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF | ||
* site: http://www.fsf.org. | ||
*/ | ||
package org.zanata.exception; | ||
|
||
public class ProjectNotFoundException extends RuntimeException { | ||
private static final long serialVersionUID = 1L; | ||
private final String projectSlug; | ||
|
||
public ProjectNotFoundException(String projectSlug) { | ||
this.projectSlug = projectSlug; | ||
} | ||
|
||
public String getProjectSlug() { | ||
return projectSlug; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
zanata-war/src/main/java/org/zanata/exception/VersionNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 2016, Red Hat, Inc. and individual contributors as indicated by the | ||
* @author tags. See the copyright.txt file in the distribution for a full | ||
* listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it under the | ||
* terms of the GNU Lesser General Public License as published by the Free | ||
* Software Foundation; either version 2.1 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this software; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF | ||
* site: http://www.fsf.org. | ||
*/ | ||
package org.zanata.exception; | ||
|
||
public class VersionNotFoundException extends RuntimeException { | ||
private static final long serialVersionUID = 1L; | ||
private final String projectSlug; | ||
private final String versionSlug; | ||
|
||
public VersionNotFoundException(String projectSlug, String versionSlug) { | ||
this.projectSlug = projectSlug; | ||
this.versionSlug = versionSlug; | ||
} | ||
|
||
public String getProjectSlug() { | ||
return projectSlug; | ||
} | ||
|
||
public String getVersionSlug() { | ||
return versionSlug; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
zanata-war/src/main/java/org/zanata/exception/handler/ProjectNotFoundExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2016, Red Hat, Inc. and individual contributors as indicated by the | ||
* @author tags. See the copyright.txt file in the distribution for a full | ||
* listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it under the | ||
* terms of the GNU Lesser General Public License as published by the Free | ||
* Software Foundation; either version 2.1 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this software; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF | ||
* site: http://www.fsf.org. | ||
*/ | ||
|
||
package org.zanata.exception.handler; | ||
|
||
import org.apache.deltaspike.core.api.exception.control.ExceptionHandler; | ||
import org.apache.deltaspike.core.api.exception.control.Handles; | ||
import org.apache.deltaspike.core.api.exception.control.event.ExceptionEvent; | ||
import org.zanata.exception.ProjectNotFoundException; | ||
|
||
import javax.faces.application.FacesMessage; | ||
|
||
|
||
@ExceptionHandler | ||
public class ProjectNotFoundExceptionHandler extends AbstractExceptionHandler { | ||
public void handleException(@Handles ExceptionEvent<ProjectNotFoundException> event) { | ||
handle(event, LogLevel.Warn, urlUtil.missingEntityPage(), FacesMessage.SEVERITY_WARN, | ||
"jsf.ProjectNotFound", event.getException().getProjectSlug()); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
zanata-war/src/main/java/org/zanata/exception/handler/VersionNotFoundExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2016, Red Hat, Inc. and individual contributors as indicated by the | ||
* @author tags. See the copyright.txt file in the distribution for a full | ||
* listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it under the | ||
* terms of the GNU Lesser General Public License as published by the Free | ||
* Software Foundation; either version 2.1 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this software; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF | ||
* site: http://www.fsf.org. | ||
*/ | ||
|
||
package org.zanata.exception.handler; | ||
|
||
import org.apache.deltaspike.core.api.exception.control.ExceptionHandler; | ||
import org.apache.deltaspike.core.api.exception.control.Handles; | ||
import org.apache.deltaspike.core.api.exception.control.event.ExceptionEvent; | ||
import org.zanata.exception.VersionNotFoundException; | ||
|
||
import javax.faces.application.FacesMessage; | ||
|
||
|
||
@ExceptionHandler | ||
public class VersionNotFoundExceptionHandler extends AbstractExceptionHandler { | ||
public void handleException(@Handles ExceptionEvent<VersionNotFoundException> event) { | ||
VersionNotFoundException exception = event.getException(); | ||
handle(event, LogLevel.Warn, urlUtil.missingEntityPage(), FacesMessage.SEVERITY_WARN, | ||
"jsf.VersionNotFound", exception.getProjectSlug(), exception.getVersionSlug()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
<ui:composition xmlns="http://www.w3.org/1999/xhtml" | ||
xmlns:ui="http://java.sun.com/jsf/facelets" | ||
xmlns:h="http://java.sun.com/jsf/html" | ||
template="../WEB-INF/template/template.xhtml"> | ||
|
||
<ui:define name="page_title">#{msgs['jsf.Error']}</ui:define> | ||
<ui:param name="showGlobalMessages" value="false"/> | ||
<ui:define name="center_content"> | ||
<ui:remove> | ||
<!-- TODO [CDI] use h:messages instead of jsfMessages.globalMessagesList? --> | ||
</ui:remove> | ||
<ui:fragment | ||
rendered="#{empty jsfMessages.globalMessagesList}"> | ||
<h2>#{msgs['jsf.NoErrors']}</h2> | ||
</ui:fragment> | ||
|
||
<ui:fragment | ||
rendered="#{not empty jsfMessages.globalMessagesList}"> | ||
<ul class="list--no-bullets"> | ||
<li> | ||
<div class="alert--danger"> | ||
<h2 class="alert__heading">#{msgs['jsf.ErrorTitle']}</h2> | ||
|
||
<div class="alert__content"> | ||
<ul class="list--no-bullets"> | ||
<ui:repeat | ||
value="#{jsfMessages.globalMessagesList}" | ||
var="message"> | ||
<h:outputText | ||
value="#{message.detail}"> | ||
</h:outputText> | ||
|
||
</ui:repeat> | ||
</ul> | ||
</div> | ||
</div> | ||
</li> | ||
</ul> | ||
</ui:fragment> | ||
</ui:define> | ||
</ui:composition> |