Package org.platformlayer

Examples of org.platformlayer.RepositoryException


      String jobId = jobKey.getItemIdString();

      int projectId = db.mapToValue(project);
      int updateCount = db.queries.updateExecution(logCookie, endedAt, state, projectId, jobId, executionId);
      if (updateCount != 1) {
        throw new RepositoryException("Unexpected number of rows updated");
      }

      updateCount = db.queries.updateJob(endedAt, state, executionId, projectId, jobId);
      if (updateCount != 1) {
        throw new RepositoryException("Unexpected number of rows updated");
      }
    } catch (SQLException e) {
      throw new RepositoryException("Error updating job execution", e);
    } finally {
      db.close();
    }
  }
View Full Code Here


      execution.executionId = executionId;
      execution.jobId = jobId;

      int updateCount = db.queries.insert(execution);
      if (updateCount != 1) {
        throw new RepositoryException("Unexpected number of rows inserted");
      }

      return execution.executionId;
    } catch (SQLException e) {
      throw new RepositoryException("Error inserting job execution", e);
    } finally {
      db.close();
    }
  }
View Full Code Here

      entity.actionXml = toXml(jobData.action);
      entity.target = jobData.targetId.getUrl();

      int updateCount = db.queries.insert(entity);
      if (updateCount != 1) {
        throw new RepositoryException("Unexpected number of rows inserted");
      }

      return jobId;
    } catch (SQLException e) {
      throw new RepositoryException("Error inserting job execution", e);
    } finally {
      db.close();
    }
  }
View Full Code Here

        return null;
      }
      return fromDb(entity);

    } catch (SQLException e) {
      throw new RepositoryException("Error running query", e);
    } catch (OpsException e) {
      throw new RepositoryException("Error deserializing from database", e);
    } finally {
      db.close();
    }
  }
View Full Code Here

        db.insertItem(entity);
      } else {
        db.updateItem(entity);
      }
    } catch (SQLException e) {
      throw new RepositoryException("Error running query", e);
    } catch (OpsException e) {
      throw new RepositoryException("Error serializing to database", e);
    } finally {
      db.close();
    }
  }
View Full Code Here

      for (SchedulerRecordEntity entity : db.listItems()) {
        ret.add(fromDb(entity));
      }
      return ret;
    } catch (SQLException e) {
      throw new RepositoryException("Error running query", e);
    } catch (OpsException e) {
      throw new RepositoryException("Error deserializing from database", e);
    } finally {
      db.close();
    }
  }
View Full Code Here

      throws RepositoryException {
    DbHelper db = new DbHelper();
    try {
      UserEntity user = db.findUserByKey(username);
      if (user == null) {
        throw new RepositoryException("User not found");
      }

      ProjectEntity project = db.findProjectByKey(projectKey);
      if (project == null) {
        throw new RepositoryException("Project not found");
      }

      byte[] projectSecretData = FathomdbCrypto.serialize(projectSecret);

      PublicKey userPublicKey = user.getPublicKey();

      byte[] newSecretData;
      try {
        SecretStore store = new SecretStore(project.secretData);
        Writer writer = store.buildWriter();
        writer.writeAsymetricUserKey(projectSecretData, user.id, userPublicKey);
        writer.close();
        store.appendContents(writer);

        newSecretData = store.getEncoded();
      } catch (IOException e) {
        throw new RepositoryException("Error writing secrets", e);
      }

      db.updateProjectSecret(project.id, newSecretData);

      UserProjectEntity userProjectEntity = new UserProjectEntity();
      userProjectEntity.userId = user.id;
      userProjectEntity.projectId = project.id;
      userProjectEntity.addRoles(roles);

      db.insertUserProject(userProjectEntity);
    } catch (SQLException e) {
      throw new RepositoryException("Error reading groups", e);
    } finally {
      db.close();
    }
  }
View Full Code Here

      throws RepositoryException {
    DbHelper db = new DbHelper();
    try {
      ProjectEntity grantToProject = db.findProjectByKey(grantToProjectKey);
      if (grantToProject == null) {
        throw new RepositoryException("Project not found");
      }

      ProjectEntity onProject = db.findProjectByKey(onProjectKey);
      if (onProject == null) {
        throw new RepositoryException("Project not found");
      }

      byte[] projectSecretData = onProjectSecret.getEncoded();

      PublicKey grantToProjectPublicKey = grantToProject.getPublicKey();

      byte[] newSecretData;
      try {
        SecretStore store = new SecretStore(onProject.secretData);
        Writer writer = store.buildWriter();
        writer.writeAsymetricProjectKey(projectSecretData, grantToProject.id, grantToProjectPublicKey);
        writer.close();
        store.appendContents(writer);

        newSecretData = store.getEncoded();
      } catch (IOException e) {
        throw new RepositoryException("Error writing secrets", e);
      }

      db.updateProjectSecret(onProject.id, newSecretData);

      // db.insertUserProject(user.id, project.id);
    } catch (SQLException e) {
      throw new RepositoryException("Error reading groups", e);
    } finally {
      db.close();
    }
  }
View Full Code Here

    try {
      List<ProjectEntity> projects = Lists.newArrayList();
      projects.addAll(db.findProjectsByUserId(userId));
      return projects;
    } catch (SQLException e) {
      throw new RepositoryException("Error reading groups", e);
    } finally {
      db.close();
    }
  }
View Full Code Here

        writer.close();

        secretData = baos.toByteArray();
      } catch (IOException e) {
        throw new RepositoryException("Error encrypting secrets", e);
      }

      byte[] hashedPassword = null;
      if (password != null) {
        hashedPassword = PasswordHash.doPasswordHash(password);
      }

      // This keypair is for grants etc. The client doesn't (currently) get access to the private key
      KeyPair userRsaKeyPair = RsaUtils.generateRsaKeyPair(RsaUtils.SMALL_KEYSIZE);
      byte[] privateKeyData = RsaUtils.serialize(userRsaKeyPair.getPrivate());
      privateKeyData = FathomdbCrypto.encrypt(userSecretKey, privateKeyData);
      byte[] publicKeyData = RsaUtils.serialize(userRsaKeyPair.getPublic());

      db.insertUser(userName, hashedPassword, secretData, publicKeyData, privateKeyData);

      UserEntity user = findUser(userName);

      if (password != null) {
        user.unlockWithPassword(password);
      }

      if (publicKeyHash != null) {
        UserCertEntity userCert = new UserCertEntity();

        // TODO: Retry on collision
        Random random = new Random();
        userCert.id = random.nextInt();

        userCert.userId = user.id;
        userCert.publicKeyHash = publicKeyHash;
        db.insertUserCert(userCert);
      }

      return user;
    } catch (SQLException e) {
      throw new RepositoryException("Error creating user", e);
    } finally {
      db.close();
    }
  }
View Full Code Here

TOP

Related Classes of org.platformlayer.RepositoryException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.