All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.molgenis.data.EntityAlreadyExistsException Maven / Gradle / Ivy

There is a newer version: 8.4.5
Show newest version
package org.molgenis.data;

import static java.lang.String.format;
import static java.util.Objects.requireNonNull;

import javax.annotation.CheckForNull;
import javax.annotation.Nullable;

@SuppressWarnings({"squid:MaximumInheritanceDepth"})
public class EntityAlreadyExistsException extends DataAlreadyExistsException {
  private static final String ERROR_CODE = "D09";

  private final transient Entity entity;

  public EntityAlreadyExistsException(Entity entity) {
    super(ERROR_CODE);
    this.entity = requireNonNull(entity);
  }

  public EntityAlreadyExistsException(Entity entity, @Nullable @CheckForNull Throwable cause) {
    super(ERROR_CODE, cause);
    this.entity = requireNonNull(entity);
  }

  @Override
  public String getMessage() {
    return format("type:%s id:%s", entity.getEntityType().getId(), entity.getIdValue().toString());
  }

  @Override
  protected Object[] getLocalizedMessageArguments() {
    return new Object[] {entity.getIdValue().toString(), entity.getEntityType()};
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy