Search in sources :

Example 11 with RepositoryException

use of org.platformlayer.RepositoryException in project platformlayer by platformlayer.

the class JdbcJobRepository method findJob.

@Override
@JdbcTransaction
public JobData findJob(PlatformLayerKey jobKey) throws RepositoryException {
    DbHelper db = new DbHelper();
    try {
        ProjectId projectId = jobKey.getProject();
        String jobId = jobKey.getItemIdString();
        JobEntity execution = db.queries.findJob(db.mapToValue(projectId), jobId);
        if (execution == null) {
            return null;
        }
        return mapFromEntity(execution, jobKey);
    } catch (SQLException e) {
        throw new RepositoryException("Error listing job executions", e);
    } finally {
        db.close();
    }
}
Also used : SQLException(java.sql.SQLException) ProjectId(org.platformlayer.ids.ProjectId) RepositoryException(org.platformlayer.RepositoryException) JdbcTransaction(com.fathomdb.jdbc.JdbcTransaction)

Example 12 with RepositoryException

use of org.platformlayer.RepositoryException in project platformlayer by platformlayer.

the class JdbcJobRepository method toXml.

private String toXml(Action action) throws RepositoryException {
    Object o;
    try {
        Marshaller marshaller = jaxbContext.createMarshaller();
        StringWriter writer = new StringWriter();
        marshaller.marshal(action, writer);
        return writer.toString();
    } catch (JAXBException e) {
        throw new RepositoryException("Error serializing action", e);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) JAXBException(javax.xml.bind.JAXBException) RepositoryException(org.platformlayer.RepositoryException)

Example 13 with RepositoryException

use of org.platformlayer.RepositoryException in project platformlayer by platformlayer.

the class JdbcJobRepository method insertJob.

@Override
@JdbcTransaction
public String insertJob(ProjectId projectId, JobData jobData) throws RepositoryException {
    DbHelper db = new DbHelper();
    try {
        String jobId = UUID.randomUUID().toString();
        JobEntity entity = new JobEntity();
        entity.project = db.mapToValue(projectId);
        entity.jobId = jobId;
        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();
    }
}
Also used : SQLException(java.sql.SQLException) RepositoryException(org.platformlayer.RepositoryException) JdbcTransaction(com.fathomdb.jdbc.JdbcTransaction)

Example 14 with RepositoryException

use of org.platformlayer.RepositoryException in project platformlayer by platformlayer.

the class JdbcUserRepository method listProjectsByUserId.

@Override
@JdbcTransaction
public List<ProjectEntity> listProjectsByUserId(int userId) throws RepositoryException {
    DbHelper db = new DbHelper();
    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();
    }
}
Also used : SQLException(java.sql.SQLException) RepositoryException(org.platformlayer.RepositoryException) JdbcTransaction(com.fathomdb.jdbc.JdbcTransaction)

Example 15 with RepositoryException

use of org.platformlayer.RepositoryException in project platformlayer by platformlayer.

the class JdbcUserRepository method listAllProjectNames.

@Override
@JdbcTransaction
public List<String> listAllProjectNames(String prefix) throws RepositoryException {
    String match;
    if (prefix == null) {
        match = "%";
    } else {
        match = prefix + "%";
    }
    DbHelper db = new DbHelper();
    try {
        return db.listProjects(match);
    } catch (SQLException e) {
        throw new RepositoryException("Error listing projects", e);
    } finally {
        db.close();
    }
}
Also used : SQLException(java.sql.SQLException) RepositoryException(org.platformlayer.RepositoryException) JdbcTransaction(com.fathomdb.jdbc.JdbcTransaction)

Aggregations

RepositoryException (org.platformlayer.RepositoryException)56 JdbcTransaction (com.fathomdb.jdbc.JdbcTransaction)30 SQLException (java.sql.SQLException)30 OpsException (org.platformlayer.ops.OpsException)18 ProjectId (org.platformlayer.ids.ProjectId)14 ItemBase (org.platformlayer.core.model.ItemBase)10 CryptoKey (com.fathomdb.crypto.CryptoKey)8 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)7 ManagedItemId (org.platformlayer.ids.ManagedItemId)7 OpsContext (org.platformlayer.ops.OpsContext)7 ServiceProvider (org.platformlayer.xaas.services.ServiceProvider)7 IOException (java.io.IOException)6 AesCryptoKey (com.fathomdb.crypto.AesCryptoKey)5 PublicKey (java.security.PublicKey)4 JAXBException (javax.xml.bind.JAXBException)4 Tag (org.platformlayer.core.model.Tag)4 ServiceType (org.platformlayer.ids.ServiceType)4 JobData (org.platformlayer.jobs.model.JobData)4 JoinedQueryResult (com.fathomdb.jpa.impl.JoinedQueryResult)3 X509Certificate (java.security.cert.X509Certificate)3