Search in sources :

Example 1 with JobMapping

use of com.palantir.stash.stashbot.persistence.JobMapping in project stashbot by palantir.

the class JobTemplateManager method getJenkinsJobsForRepository.

public ImmutableList<JobTemplate> getJenkinsJobsForRepository(RepositoryConfiguration rc) throws SQLException {
    // Ensure each default plan exists (in case it hasn't been created yet)
    createDefaultMappingsIfNeeded(rc);
    JobMapping[] mappings = ao.find(JobMapping.class, Query.select().where("REPOSITORY_CONFIGURATION_ID = ? AND VISIBLE = ?", rc.getID(), true));
    List<JobTemplate> templates = new ArrayList<JobTemplate>();
    for (JobMapping jm : mappings) {
        templates.add(jm.getJobTemplate());
    }
    return ImmutableList.copyOf(templates);
}
Also used : ArrayList(java.util.ArrayList) JobTemplate(com.palantir.stash.stashbot.persistence.JobTemplate) JobMapping(com.palantir.stash.stashbot.persistence.JobMapping)

Example 2 with JobMapping

use of com.palantir.stash.stashbot.persistence.JobMapping in project stashbot by palantir.

the class JobTemplateManager method setJenkinsJobMapping.

public void setJenkinsJobMapping(RepositoryConfiguration rc, JobTemplate jjt, Boolean isVisible, Boolean isEnabled) throws SQLException {
    JobMapping[] mappings = ao.find(JobMapping.class, Query.select().where("REPOSITORY_CONFIGURATION_ID = ? and JOB_TEMPLATE_ID = ?", rc.getID(), jjt.getID()));
    if (mappings.length == 0) {
        // just use the defaults
        JobMapping jjm = ao.create(JobMapping.class, new DBParam("REPOSITORY_CONFIGURATION_ID", rc.getID()), new DBParam("JOB_TEMPLATE_ID", jjt.getID()));
        if (isVisible != null) {
            jjm.setVisible(isVisible);
        }
        if (isEnabled != null) {
            jjm.setEnabled(isEnabled);
        }
        jjm.save();
    }
}
Also used : DBParam(net.java.ao.DBParam) JobMapping(com.palantir.stash.stashbot.persistence.JobMapping)

Example 3 with JobMapping

use of com.palantir.stash.stashbot.persistence.JobMapping in project stashbot by palantir.

the class MockJobTemplateFactory method getJobTemplate.

public JobTemplate getJobTemplate(Repository repo, RepositoryConfiguration rc, JobType jt) throws Exception {
    JobTemplate template = Mockito.mock(JobTemplate.class);
    Mockito.when(template.getJobType()).thenReturn(jt);
    Mockito.when(template.getName()).thenReturn(jt.toString());
    Mockito.when(template.getBuildNameFor(repo)).thenReturn("somename_" + jt.toString());
    Mockito.when(template.getTemplateFile()).thenReturn("src/test/resources/test-template.vm");
    JobMapping jm = Mockito.mock(JobMapping.class);
    Mockito.when(jm.getRepositoryConfiguration()).thenReturn(rc);
    Mockito.when(jm.getJobTemplate()).thenReturn(template);
    Mockito.when(jm.isVisible()).thenReturn(true);
    Mockito.when(jm.isEnabled()).thenReturn(true);
    Mockito.when(jtm.getJenkinsJobsForRepository(rc)).thenReturn(ImmutableList.copyOf(templates));
    Mockito.when(jtm.fromString(rc, jt.toString())).thenReturn(template);
    templates.add(template);
    mappings.add(jm);
    return template;
}
Also used : JobTemplate(com.palantir.stash.stashbot.persistence.JobTemplate) JobMapping(com.palantir.stash.stashbot.persistence.JobMapping)

Aggregations

JobMapping (com.palantir.stash.stashbot.persistence.JobMapping)3 JobTemplate (com.palantir.stash.stashbot.persistence.JobTemplate)2 ArrayList (java.util.ArrayList)1 DBParam (net.java.ao.DBParam)1