Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-ws-commons</artifactId>
<version>1.29.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright (c) 2025, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.gridsuite.directory.server;

import com.powsybl.ws.commons.error.BusinessErrorCode;

/**
* @author Mohamed Ben-rejeb {@literal <mohamed.ben-rejeb at rte-france.com>}
*
* Business error codes emitted by the directory service.
*/
public enum DirectoryBusinessErrorCode implements BusinessErrorCode {
DIRECTORY_PERMISSION_DENIED("directory.permissionDenied"),
DIRECTORY_ELEMENT_NAME_BLANK("directory.elementNameBlank"),
DIRECTORY_ROOT_ALREADY_EXISTS("directory.rootAlreadyExists"),
DIRECTORY_NOT_DIRECTORY("directory.notDirectory"),
DIRECTORY_ELEMENT_NAME_CONFLICT("directory.elementNameConflict"),
DIRECTORY_MOVE_IN_DESCENDANT_NOT_ALLOWED("directory.moveInDescendantNotAllowed"),
DIRECTORY_MOVE_SELECTION_EMPTY("directory.moveSelectionEmpty"),
DIRECTORY_ELEMENT_NOT_FOUND("directory.elementNotFound"),
DIRECTORY_DIRECTORY_NOT_FOUND_IN_PATH("directory.directoryNotFoundInPath"),
DIRECTORY_NOTIFICATION_UNKNOWN("directory.notificationUnknown"),
DIRECTORY_CANNOT_DELETE_ELEMENT("directory.cannotDeleteElement"),
DIRECTORY_REMOTE_ERROR("directory.remoteError");

private final String code;

DirectoryBusinessErrorCode(String code) {
this.code = code;
}

public String value() {
return code;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,63 @@
*/
package org.gridsuite.directory.server;

import com.powsybl.ws.commons.error.AbstractPowsyblWsException;
import com.powsybl.ws.commons.error.BusinessErrorCode;
import com.powsybl.ws.commons.error.PowsyblWsProblemDetail;
import lombok.NonNull;

import java.util.Objects;
import java.util.Optional;
import java.util.UUID;

/**
* @author Abdelsalem Hedhili <abdelsalem.hedhili at rte-france.com>
* @author Mohamed Ben-rejeb {@literal <mohamed.ben-rejeb at rte-france.com>}
*/
public class DirectoryException extends RuntimeException {
public class DirectoryException extends AbstractPowsyblWsException {

private final Type type;
private final DirectoryBusinessErrorCode errorCode;
private final PowsyblWsProblemDetail remoteError;

public DirectoryException(Type type) {
super(Objects.requireNonNull(type.name()));
this.type = type;
public DirectoryException(DirectoryBusinessErrorCode errorCode, String message) {
this(errorCode, message, null);
}

public DirectoryException(Type type, String message) {
super(message);
this.type = type;
public DirectoryException(DirectoryBusinessErrorCode errorCode, String message, PowsyblWsProblemDetail remoteError) {
super(Objects.requireNonNull(message, "message must not be null"));
this.errorCode = Objects.requireNonNull(errorCode, "errorCode must not be null");
this.remoteError = remoteError;
}

public static DirectoryException createNotificationUnknown(@NonNull String action) {
return new DirectoryException(Type.UNKNOWN_NOTIFICATION, String.format("The notification type '%s' is unknown", action));
return new DirectoryException(DirectoryBusinessErrorCode.DIRECTORY_NOTIFICATION_UNKNOWN,
String.format("The notification type '%s' is unknown", action));
}

public static DirectoryException createElementNotFound(@NonNull String type, @NonNull UUID uuid) {
return new DirectoryException(Type.NOT_FOUND, String.format("%s '%s' not found !", type, uuid));
return new DirectoryException(DirectoryBusinessErrorCode.DIRECTORY_ELEMENT_NOT_FOUND,
String.format("%s '%s' not found !", type, uuid));
}

public static DirectoryException createElementNameAlreadyExists(@NonNull String name) {
return new DirectoryException(Type.NAME_ALREADY_EXISTS, String.format("Element with the same name '%s' already exists in the directory !", name));
return new DirectoryException(DirectoryBusinessErrorCode.DIRECTORY_ELEMENT_NAME_CONFLICT,
String.format("Element with the same name '%s' already exists in the directory !", name));
}

Type getType() {
return type;
public static DirectoryException of(DirectoryBusinessErrorCode errorCode, String message, Object... args) {
return new DirectoryException(errorCode, args.length == 0 ? message : String.format(message, args));
}

public enum Type {
NOT_ALLOWED,
NOT_FOUND,
NOT_DIRECTORY,
IS_DIRECTORY,
UNKNOWN_NOTIFICATION,
NAME_ALREADY_EXISTS,
MOVE_IN_DESCENDANT_NOT_ALLOWED,
public Optional<DirectoryBusinessErrorCode> getErrorCode() {
return Optional.of(errorCode);
}

@Override
public Optional<BusinessErrorCode> getBusinessErrorCode() {
return Optional.ofNullable(errorCode);
}

public Optional<PowsyblWsProblemDetail> getRemoteError() {
return Optional.ofNullable(remoteError);
}
}
Loading