@Override
  public long getEntityOwnerId() {

    Volume volume = _entityMgr.findById(Volume.class, getVolumeId());
    if (volume == null) {
      throw new InvalidParameterValueException("Unable to find volume by id=" + volumeId);
    }

    Account account = _accountService.getAccount(volume.getAccountId());
    // Can create templates for enabled projects/accounts only
    if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
      Project project = _projectService.findByProjectAccountId(volume.getAccountId());
      if (project.getState() != Project.State.Active) {
        throw new PermissionDeniedException(
            "Can't add resources to the project id="
                + project.getId()
                + " in state="
                + project.getState()
                + " as it's no longer active");
      }
    } else if (account.getState() == Account.State.disabled) {
      throw new PermissionDeniedException("The owner of template is disabled: " + account);
    }

    return volume.getAccountId();
  }
Ejemplo n.º 2
0
 @Override
 public void create() throws ResourceAllocationException {
   UserContext.current().setEventDetails("Project Name: " + getName());
   Project project =
       _projectService.createProject(getName(), getDisplayText(), getAccountName(), getDomainId());
   if (project != null) {
     this.setEntityId(project.getId());
   } else {
     throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a project");
   }
 }