resource-manager/io/src/main/java/org/gcube/resourcemanagement/manager/io/codeexceptions/deserializer/ErrorEntityManager.java

56 lines
1.5 KiB
Java

package org.gcube.resourcemanagement.manager.io.codeexceptions.deserializer;
import java.util.Objects;
import org.gcube.resourcemanagement.manager.io.codeexceptions.ErrorCode;
import org.gcube.resourcemanagement.manager.io.codeexceptions.SerializableErrorEntity;
/**
* Manager for extracting information held inside a {@link SerializableErrorEntity}.
*
* @author Manuele Simi (ISTI CNR)
*
*/
public class ErrorEntityManager {
private final SerializableErrorEntity entity;
/**
*
*/
public ErrorEntityManager(SerializableErrorEntity entity) {
this.entity = entity;
}
/**
* Checks if there is an {@link Exception} in the entity.
* @return true if the entity holds an exception, false otherwise
*/
public boolean hasException() {
return Objects.nonNull(this.entity.getExceptionClass());
}
/**
* Gets the {@link Exception} inside the entity.
* @return the exception or null
*/
public <E extends Exception> E getException() {
return ExceptionDeserializer.deserialize(this.entity.getExceptionClass(),this.entity.getMessage());
}
/**
* Checks if there is an {@link ErrorCode} in the entity.
* @return true if the entity holds an errorcode, false otherwise
*/
public boolean hasErrorCode() {
return this.entity.getId() != -1;
}
/**
* Gets the {@link ErrorCode} inside the entity.
* @return the error code or null
*/
public ErrorCode getErrorCode(){
return ErrorCodeDeserializer.deserialize(this.entity.getId(), this.entity.getMessage());
}
}