package de.ivu.elect.business.internet.entity;

import java.util.UUID;

import org.apache.commons.lang3.StringUtils;

import de.ivu.elect.business.mandant.entity.EntityMitMandant;

public abstract class AbstractInternetWidget implements InternetWidgetBase, EntityMitMandant {

  private static final long serialVersionUID = 1L;

  public String buildInternetId() {
    String result;

    if (StringUtils.isNotBlank(getIdentifier())) {
      result = getIdentifier();
    } else if (getId() != null) {
      // legacy
      result = getId().toString();
    } else {
      // nicht entpackte internet seite
      setIdentifier(createId());
      result = getIdentifier();
    }

    return "id_" + result;
  }

  @Override
  public EntityMitMandant getParent() {
    return getInternetSeite();
  }

  public static String createId() {
    return UUID.randomUUID().toString().replace('-', '_');
  }

}
