Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More detailed info in ContentNotFound exception #10089 #10098

Merged
merged 10 commits into from
Mar 23, 2023
Merged
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.enonic.xp.app;

import java.text.MessageFormat;

import com.enonic.xp.annotation.PublicApi;
import com.enonic.xp.exception.NotFoundException;

Expand All @@ -9,6 +11,6 @@ public final class ApplicationNotFoundException
{
public ApplicationNotFoundException( final ApplicationKey applicationKey )
{
super( "Application [{0}] was not found", applicationKey );
super( MessageFormat.format( "Application [{0}] was not found", applicationKey ) );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public ContentAccessException( final User user, final ContentPath contentPath, f

private ContentAccessException( final Throwable cause, final User user, final ContentPath contentPath, final Permission permission )
{
super( MessageFormat.format( "Access denied to [{0}] for [{1}] by user [{2}] {3}", contentPath, permission,
super( cause, MessageFormat.format( "Access denied to [{0}] for [{1}] by user [{2}] {3}", contentPath, permission,
user == null ? "unknown" : user.getKey(),
user != null && user.getDisplayName() != null ? "''" + user.getDisplayName() + "''" : "" ), cause );
user != null && user.getDisplayName() != null ? "''" + user.getDisplayName() + "''" : "" ) );
this.user = user;
this.contentPath = contentPath;
this.permission = permission;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public String getCode()

private static String buildMessage( final ContentPath path, final RepositoryId repositoryId, final Branch branch )
{
return Stream.of( MessageFormat.format( "Content at path [{0}]", path ),
repositoryId != null ? MessageFormat.format( "in repository [{0}]", repositoryId ) : "",
return Stream.of( MessageFormat.format( "Content at path [{0}]", path ), repositoryId != null ? MessageFormat.format(
"in repository [{0}]", repositoryId ) : "",
branch != null ? MessageFormat.format( "in branch [{0}]", branch ) : "", "already exists" ).
filter( Predicate.not( String::isEmpty ) ).
collect( Collectors.joining( " " ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,159 @@

import java.text.MessageFormat;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.enonic.xp.annotation.PublicApi;
import com.enonic.xp.branch.Branch;
import com.enonic.xp.exception.NotFoundException;
import com.enonic.xp.node.NodePath;
import com.enonic.xp.repository.RepositoryId;

@PublicApi
public final class ContentNotFoundException
extends NotFoundException
{
private ContentPath path;
private final ContentPath path;

public ContentNotFoundException( final ContentPath path, final Branch branch )
@Deprecated
public ContentNotFoundException( final ContentPath contentPath, final Branch branch )
{
super( MessageFormat.format( "Content with path [{0}] was not found in branch [{1}]", path.toString(), branch ) );
this.path = path;
this( null, contentPath, null, branch, null, null );
}

@Deprecated
public ContentNotFoundException( final ContentPaths contentPaths, final Branch branch )
{
super( MessageFormat.format( "Contents with paths [{0}] were not found in branch [{1}]",
contentPaths.stream().map( Objects::toString ).collect( Collectors.joining( ", " ) ), branch ) );
this.path = null;
}

@Deprecated
public ContentNotFoundException( final ContentId contentId, final Branch branch )
{
super( MessageFormat.format( "Content with id [{0}] was not found in branch [{1}]", contentId.toString(), branch ) );
this( contentId, null, null, branch, null, null );
}

@Deprecated
public ContentNotFoundException( final ContentId contentId, final Branch branch, final NodePath contentRoot )
{
super(
MessageFormat.format( "Content with id [{0}] was not found in branch [{1}] in content root [{2}]", contentId.toString(), branch,
contentRoot ) );
this( contentId, null, null, branch, contentRoot, null );
}

@Deprecated
public ContentNotFoundException( final ContentIds contentIds, final Branch branch )
{
super( MessageFormat.format( "Contents with ids [{0}] were not found in branch [{1}]",
contentIds.stream().map( Objects::toString ).collect( Collectors.joining( ", " ) ), branch ) );
this.path = null;
}

@Deprecated
public ContentNotFoundException( final ContentId contentId, final ContentVersionId versionId, final Branch branch )
{
super( MessageFormat.format( "Content with id [{0}] and versionId [{1}] was not found in branch [{2}]", contentId, versionId,
branch ) );
this.path = null;
}

@Deprecated
public ContentNotFoundException( final ContentPath contentPath, final ContentVersionId versionId, final Branch branch )
{
super( MessageFormat.format( "Content with path [{0}] and versionId [{1}] was not found in branch [{2}]", contentPath, versionId,
branch ) );
this.path = contentPath;
}

private ContentNotFoundException( final ContentId contentId, final ContentPath contentPath, final RepositoryId repositoryId,
final Branch branch, final NodePath contentRoot, final Throwable cause )
{
super( cause, buildMessage( contentPath, contentId, repositoryId, branch, contentRoot ) );
this.path = contentPath;
}

@Deprecated
public ContentPath getPath()
{
return path;
}

private static String buildMessage( final ContentPath path, final ContentId contentId, final RepositoryId repositoryId,
final Branch branch, final NodePath contentRoot )
{
return Stream.of( "Content", path != null ? MessageFormat.format( "with path [{0}]", path ) : "",
MessageFormat.format( "with id [{0}]", contentId ),
repositoryId != null ? MessageFormat.format( "in repository [{0}]", repositoryId ) : "",
branch != null ? MessageFormat.format( "in branch [{0}]", branch ) : "",
contentRoot != null ? MessageFormat.format( "with root [{0}]", contentRoot ) : "", "not found" )
.filter( Predicate.not( String::isEmpty ) )
.collect( Collectors.joining( " " ) );
}

public static Builder create()
{
return new Builder();
}

public static class Builder
{
private RepositoryId repositoryId;
Fixed Show fixed Hide fixed

private Branch branch;
Fixed Show fixed Hide fixed

private ContentPath contentPath;
Fixed Show fixed Hide fixed

private ContentId contentId;
Fixed Show fixed Hide fixed

private NodePath contentRoot;
Fixed Show fixed Hide fixed

private Throwable cause;
Fixed Show fixed Hide fixed

private Builder()
{
}

public Builder repositoryId( final RepositoryId repositoryId )
{
this.repositoryId = repositoryId;
return this;
}

public Builder branch( final Branch branch )
{
this.branch = branch;
return this;
}

public Builder contentPath( final ContentPath contentPath )
{
this.contentPath = contentPath;
return this;
}

public Builder contentId( final ContentId contentId )
{
this.contentId = contentId;
return this;
}

public Builder contentRoot( final NodePath contentRoot )
{
this.contentRoot = contentRoot;
return this;
}

public Builder cause( final Throwable cause )
{
this.cause = cause;
return this;
}

public ContentNotFoundException build()
{
return new ContentNotFoundException( contentId, contentPath, repositoryId, branch, contentRoot, cause );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ public BaseException( final Throwable t, final String message )
super( message, t );
}

@Deprecated
public BaseException( final String message, final Object... args )
{
this( null, message, args );
}

@Deprecated
public BaseException( final Throwable cause, final String message, final Object... args )
{
super( message == null ? "" : MessageFormat.format( message, args ), cause );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,23 @@
public final class InitializationException
extends BaseException
{
public InitializationException( final String message )
{
super( message );
}

@Deprecated
public InitializationException( final String message, final Object... args )
{
super( message, args );
}

public InitializationException( final Throwable cause, final String message )
{
super( cause, message );
}

@Deprecated
public InitializationException( final Throwable cause, final String message, final Object... args )
{
super( cause, message, args );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ public NotFoundException( final Throwable t, final String message )
super( t, message );
}

@Deprecated
public NotFoundException( final String message, final Object... args )
{
super( message, args );
}

@Deprecated
public NotFoundException( final Throwable cause, final String message, final Object... args )
{
super( cause, message, args );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.enonic.xp.annotation.PublicApi;

@PublicApi
@Deprecated
public final class SystemException
extends BaseException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void standBy( final String initializationSubject )
}
catch ( InterruptedException e )
{
throw new InitializationException( initializationSubject + " initialization check thread interrupted", e );
throw new InitializationException( e, initializationSubject + " initialization check thread interrupted" );
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.enonic.xp.resource;

import java.text.MessageFormat;

import com.enonic.xp.annotation.PublicApi;
import com.enonic.xp.exception.NotFoundException;

Expand All @@ -11,7 +13,7 @@ public final class ResourceNotFoundException

public ResourceNotFoundException( final ResourceKey resource )
{
super( "Resource [{0}] was not found", resource );
super( MessageFormat.format( "Resource [{0}] was not found", resource ) );
this.resource = resource;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.enonic.xp.security;

import java.text.MessageFormat;

import com.enonic.xp.annotation.PublicApi;
import com.enonic.xp.exception.BaseException;

Expand All @@ -11,7 +13,8 @@ public class IdProviderAlreadyExistsException

public IdProviderAlreadyExistsException( final IdProviderKey idProviderKey )
{
super( "Id Provider [{0}] could not be created. A Id Provider with that name already exists", idProviderKey );
super(
MessageFormat.format( "Id Provider [{0}] could not be created. A Id Provider with that name already exists", idProviderKey ) );
this.idProviderKey = idProviderKey;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.enonic.xp.security;

import java.text.MessageFormat;

import com.enonic.xp.annotation.PublicApi;
import com.enonic.xp.exception.BaseException;

Expand All @@ -12,7 +14,7 @@ public class IdProviderNotFoundException

public IdProviderNotFoundException( final IdProviderKey idProviderKey )
{
super( "IdProvider [{0}] not found", idProviderKey );
super( MessageFormat.format( "IdProvider [{0}] not found", idProviderKey ) );
this.idProviderKey = idProviderKey;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.enonic.xp.security;

import java.text.MessageFormat;

import com.enonic.xp.annotation.PublicApi;
import com.enonic.xp.exception.BaseException;

Expand All @@ -12,7 +14,7 @@ public class PrincipalAlreadyExistsException

public PrincipalAlreadyExistsException( final PrincipalKey principalKey )
{
super( "Principal [{0}] could not be created. A principal with that name already exists", principalKey.getId() );
super( MessageFormat.format( "Principal [{0}] could not be created. A principal with that name already exists", principalKey ) );
this.principalKey = principalKey;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.enonic.xp.security;

import java.text.MessageFormat;

import com.enonic.xp.annotation.PublicApi;
import com.enonic.xp.exception.BaseException;

Expand All @@ -12,7 +14,7 @@ public class PrincipalNotFoundException

public PrincipalNotFoundException( final PrincipalKey principalKey )
{
super( "Principal [{0}] not found", principalKey );
super( MessageFormat.format( "Principal [{0}] not found", principalKey ) );
this.principalKey = principalKey;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ public AuthenticationException( final Throwable t, final String message )
super( t, message );
}

@Deprecated
public AuthenticationException( final String message, final Object... args )
{
super( message, args );
}

@Deprecated
public AuthenticationException( final Throwable cause, final String message, final Object... args )
{
super( cause, message, args );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.enonic.xp.task;

import java.text.MessageFormat;

import com.enonic.xp.annotation.PublicApi;
import com.enonic.xp.exception.BaseException;
import com.enonic.xp.page.DescriptorKey;
Expand All @@ -12,13 +14,13 @@ public class TaskNotFoundException

public TaskNotFoundException( final DescriptorKey task )
{
super( "Task [{0}] not found", task );
super( MessageFormat.format( "Task [{0}] not found", task ) );
this.task = task;
}

public TaskNotFoundException( final DescriptorKey task, final String message )
{
super( "Task [{0}] not found. " + message, task );
super( MessageFormat.format( "Task [{0}] not found. {1}", task, message ) );
this.task = task;
}

Expand Down
Loading