Search in sources :

Example 1 with ExecTO

use of org.apache.syncope.common.lib.to.ExecTO in project syncope by apache.

the class ReconciliationWidget method parseReconciliationReportExec.

private Pair<List<ProgressBean>, ReconciliationReport> parseReconciliationReportExec() throws IOException {
    List<ProgressBean> beans = Collections.emptyList();
    ReconciliationReport report = null;
    Optional<ExecTO> exec = Optional.empty();
    if (SyncopeConsoleSession.get().owns(StandardEntitlement.REPORT_LIST)) {
        exec = restClient.listRecentExecutions(ROWS).stream().filter(e -> reconciliationReportKey.equals(e.getRefKey())).findAny();
    }
    if (!exec.isPresent()) {
        LOG.error("Could not find the last execution of reconciliation report");
    } else {
        Object entity = restClient.exportExecutionResult(exec.get().getKey(), ReportExecExportFormat.XML).getEntity();
        if (entity instanceof InputStream) {
            try {
                report = ReconciliationReportParser.parse(exec.get().getEnd(), (InputStream) entity);
                beans = new ArrayList<>();
                ProgressBean progressBean = new ProgressBean();
                progressBean.setText(getString("users"));
                progressBean.setTotal(report.getUsers().getTotal());
                progressBean.setFraction(report.getUsers().getTotal() - report.getUsers().getAnys().size());
                progressBean.setCssClass("progress-bar-yellow");
                beans.add(progressBean);
                progressBean = new ProgressBean();
                progressBean.setText(getString("groups"));
                progressBean.setTotal(report.getGroups().getTotal());
                progressBean.setFraction(report.getGroups().getTotal() - report.getGroups().getAnys().size());
                progressBean.setCssClass("progress-bar-red");
                beans.add(progressBean);
                int i = 0;
                for (Anys anys : report.getAnyObjects()) {
                    progressBean = new ProgressBean();
                    progressBean.setText(anys.getAnyType());
                    progressBean.setTotal(anys.getTotal());
                    progressBean.setFraction(anys.getTotal() - anys.getAnys().size());
                    progressBean.setCssClass("progress-bar-" + (i % 2 == 0 ? "green" : "aqua"));
                    beans.add(progressBean);
                    i++;
                }
            } catch (Exception e) {
                LOG.error("Could not parse the last execution available of reconciliation report", e);
            }
        }
    }
    return Pair.of(beans, report == null ? new ReconciliationReport(new Date()) : report);
}
Also used : ReconciliationReport(org.apache.syncope.client.console.widgets.reconciliation.ReconciliationReport) ExecTO(org.apache.syncope.common.lib.to.ExecTO) InputStream(java.io.InputStream) Anys(org.apache.syncope.client.console.widgets.reconciliation.Anys) IOException(java.io.IOException) Date(java.util.Date)

Example 2 with ExecTO

use of org.apache.syncope.common.lib.to.ExecTO in project syncope by apache.

the class PropagationTaskITCase method issueSYNCOPE741.

@Test
public void issueSYNCOPE741() {
    for (int i = 0; i < 3; i++) {
        taskService.execute(new ExecuteQuery.Builder().key("1e697572-b896-484c-ae7f-0c8f63fcbc6c").build());
        taskService.execute(new ExecuteQuery.Builder().key("316285cc-ae52-4ea2-a33b-7355e189ac3f").build());
    }
    try {
        Thread.sleep(3000);
    } catch (InterruptedException e) {
    // ignore
    }
    // check list
    PagedResult<TaskTO> tasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).page(1).size(2).details(false).build());
    for (TaskTO item : tasks.getResult()) {
        assertTrue(item.getExecutions().isEmpty());
    }
    tasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).page(1).size(2).details(true).build());
    for (TaskTO item : tasks.getResult()) {
        assertFalse(item.getExecutions().isEmpty());
    }
    // check read
    PropagationTaskTO task = taskService.read(TaskType.PROPAGATION, "1e697572-b896-484c-ae7f-0c8f63fcbc6c", false);
    assertNotNull(task);
    assertEquals("1e697572-b896-484c-ae7f-0c8f63fcbc6c", task.getKey());
    assertTrue(task.getExecutions().isEmpty());
    task = taskService.read(TaskType.PROPAGATION, "1e697572-b896-484c-ae7f-0c8f63fcbc6c", true);
    assertNotNull(task);
    assertEquals("1e697572-b896-484c-ae7f-0c8f63fcbc6c", task.getKey());
    assertFalse(task.getExecutions().isEmpty());
    // check list executions
    PagedResult<ExecTO> execs = taskService.listExecutions(new ExecQuery.Builder().key("1e697572-b896-484c-ae7f-0c8f63fcbc6c").page(1).size(2).build());
    assertTrue(execs.getTotalCount() >= execs.getResult().size());
}
Also used : TaskTO(org.apache.syncope.common.lib.to.TaskTO) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) ExecTO(org.apache.syncope.common.lib.to.ExecTO) ExecQuery(org.apache.syncope.common.rest.api.beans.ExecQuery) ExecuteQuery(org.apache.syncope.common.rest.api.beans.ExecuteQuery) TaskQuery(org.apache.syncope.common.rest.api.beans.TaskQuery) Test(org.junit.jupiter.api.Test)

Example 3 with ExecTO

use of org.apache.syncope.common.lib.to.ExecTO in project syncope by apache.

the class PullTaskITCase method syncTokenWithErrors.

@Test
public void syncTokenWithErrors() {
    ResourceTO origResource = resourceService.read(RESOURCE_NAME_DBPULL);
    ConnInstanceTO origConnector = connectorService.read(origResource.getConnector(), null);
    ResourceTO resForTest = SerializationUtils.clone(origResource);
    resForTest.setKey("syncTokenWithErrors");
    resForTest.setConnector(null);
    ConnInstanceTO connForTest = SerializationUtils.clone(origConnector);
    connForTest.setKey(null);
    connForTest.setDisplayName("For syncTokenWithErrors");
    JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
    try {
        connForTest.getCapabilities().add(ConnectorCapability.SYNC);
        ConnConfProperty changeLogColumn = connForTest.getConf("changeLogColumn").get();
        assertNotNull(changeLogColumn);
        assertTrue(changeLogColumn.getValues().isEmpty());
        changeLogColumn.getValues().add("lastModification");
        Response response = connectorService.create(connForTest);
        if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) {
            throw (RuntimeException) clientFactory.getExceptionMapper().fromResponse(response);
        }
        connForTest = getObject(response.getLocation(), ConnectorService.class, ConnInstanceTO.class);
        assertNotNull(connForTest);
        resForTest.setConnector(connForTest.getKey());
        resForTest = createResource(resForTest);
        assertNotNull(resForTest);
        PullTaskTO pullTask = new PullTaskTO();
        pullTask.setActive(true);
        pullTask.setName("For syncTokenWithErrors");
        pullTask.setResource(resForTest.getKey());
        pullTask.setDestinationRealm(SyncopeConstants.ROOT_REALM);
        pullTask.setPullMode(PullMode.INCREMENTAL);
        pullTask.setPerformCreate(true);
        pullTask.setPerformUpdate(true);
        pullTask.setPerformDelete(true);
        response = taskService.create(TaskType.PULL, pullTask);
        if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) {
            throw (RuntimeException) clientFactory.getExceptionMapper().fromResponse(response);
        }
        pullTask = getObject(response.getLocation(), TaskService.class, PullTaskTO.class);
        assertNotNull(pullTask);
        jdbcTemplate.execute("DELETE FROM testpull");
        jdbcTemplate.execute("INSERT INTO testpull VALUES " + "(1040, 'syncTokenWithErrors1', 'Surname1', " + "false, 'syncTokenWithErrors1@syncope.apache.org', '2014-05-23 13:53:24.293')");
        jdbcTemplate.execute("INSERT INTO testpull VALUES " + "(1041, 'syncTokenWithErrors2', 'Surname2', " + "false, 'syncTokenWithErrors1@syncope.apache.org', '2015-05-23 13:53:24.293')");
        ExecTO exec = execProvisioningTask(taskService, TaskType.PULL, pullTask.getKey(), 50, false);
        assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(exec.getStatus()));
        resForTest = resourceService.read(resForTest.getKey());
        assertTrue(resForTest.getProvision(AnyTypeKind.USER.name()).get().getSyncToken().contains("2014-05-23"));
        jdbcTemplate.execute("UPDATE testpull " + "SET email='syncTokenWithErrors2@syncope.apache.org', lastModification='2016-05-23 13:53:24.293' " + "WHERE ID=1041");
        exec = execProvisioningTask(taskService, TaskType.PULL, pullTask.getKey(), 50, false);
        assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(exec.getStatus()));
        resForTest = resourceService.read(resForTest.getKey());
        assertTrue(resForTest.getProvision(AnyTypeKind.USER.name()).get().getSyncToken().contains("2016-05-23"));
    } finally {
        if (resForTest.getConnector() != null) {
            resourceService.delete(resForTest.getKey());
            connectorService.delete(connForTest.getKey());
        }
        jdbcTemplate.execute("DELETE FROM testpull WHERE ID=1040");
        jdbcTemplate.execute("DELETE FROM testpull WHERE ID=1041");
    }
}
Also used : Response(javax.ws.rs.core.Response) ExecTO(org.apache.syncope.common.lib.to.ExecTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) TaskService(org.apache.syncope.common.rest.api.service.TaskService) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) ConnConfProperty(org.apache.syncope.common.lib.types.ConnConfProperty) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) ConnectorService(org.apache.syncope.common.rest.api.service.ConnectorService) Test(org.junit.jupiter.api.Test)

Example 4 with ExecTO

use of org.apache.syncope.common.lib.to.ExecTO in project syncope by apache.

the class PullTaskITCase method dryRun.

@Test
public void dryRun() {
    ExecTO execution = execProvisioningTask(taskService, TaskType.PULL, PULL_TASK_KEY, 50, true);
    assertEquals("SUCCESS", execution.getStatus());
}
Also used : ExecTO(org.apache.syncope.common.lib.to.ExecTO) Test(org.junit.jupiter.api.Test)

Example 5 with ExecTO

use of org.apache.syncope.common.lib.to.ExecTO in project syncope by apache.

the class PullTaskITCase method issueSYNCOPE68.

@Test
public void issueSYNCOPE68() {
    // -----------------------------
    // Create a new user ... it should be updated applying pull policy
    // -----------------------------
    UserTO userTO = new UserTO();
    userTO.setRealm(SyncopeConstants.ROOT_REALM);
    userTO.setPassword("password123");
    userTO.setUsername("testuser2");
    userTO.getPlainAttrs().add(attrTO("firstname", "testuser2"));
    userTO.getPlainAttrs().add(attrTO("surname", "testuser2"));
    userTO.getPlainAttrs().add(attrTO("ctype", "a type"));
    userTO.getPlainAttrs().add(attrTO("fullname", "a type"));
    userTO.getPlainAttrs().add(attrTO("userId", "testuser2@syncope.apache.org"));
    userTO.getPlainAttrs().add(attrTO("email", "testuser2@syncope.apache.org"));
    userTO.getResources().add(RESOURCE_NAME_NOPROPAGATION2);
    userTO.getResources().add(RESOURCE_NAME_NOPROPAGATION4);
    userTO.getMemberships().add(new MembershipTO.Builder().group("bf825fe1-7320-4a54-bd64-143b5c18ab97").build());
    userTO = createUser(userTO).getEntity();
    assertNotNull(userTO);
    assertEquals("testuser2", userTO.getUsername());
    assertEquals(1, userTO.getMemberships().size());
    assertEquals(3, userTO.getResources().size());
    try {
        // -----------------------------
        // add user template
        // -----------------------------
        UserTO template = new UserTO();
        template.getMemberships().add(new MembershipTO.Builder().group("b8d38784-57e7-4595-859a-076222644b55").build());
        template.getResources().add(RESOURCE_NAME_NOPROPAGATION4);
        // -----------------------------
        // Update pull task
        PullTaskTO task = taskService.read(TaskType.PULL, "81d88f73-d474-4450-9031-605daa4e313f", true);
        assertNotNull(task);
        task.getTemplates().put(AnyTypeKind.USER.name(), template);
        taskService.update(TaskType.PULL, task);
        PullTaskTO actual = taskService.read(TaskType.PULL, task.getKey(), true);
        assertNotNull(actual);
        assertEquals(task.getKey(), actual.getKey());
        assertFalse(actual.getTemplates().get(AnyTypeKind.USER.name()).getResources().isEmpty());
        assertFalse(((UserTO) actual.getTemplates().get(AnyTypeKind.USER.name())).getMemberships().isEmpty());
        ExecTO execution = execProvisioningTask(taskService, TaskType.PULL, actual.getKey(), 50, false);
        assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
        userTO = userService.read("testuser2");
        assertNotNull(userTO);
        assertEquals("testuser2@syncope.apache.org", userTO.getPlainAttr("userId").get().getValues().get(0));
        assertEquals(2, userTO.getMemberships().size());
        assertEquals(4, userTO.getResources().size());
    } finally {
        UserTO dUserTO = deleteUser(userTO.getKey()).getEntity();
        assertNotNull(dUserTO);
    }
}
Also used : ExecTO(org.apache.syncope.common.lib.to.ExecTO) UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) Test(org.junit.jupiter.api.Test)

Aggregations

ExecTO (org.apache.syncope.common.lib.to.ExecTO)37 Test (org.junit.jupiter.api.Test)22 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)13 UserTO (org.apache.syncope.common.lib.to.UserTO)13 Response (javax.ws.rs.core.Response)11 PullTaskTO (org.apache.syncope.common.lib.to.PullTaskTO)10 Date (java.util.Date)9 TaskService (org.apache.syncope.common.rest.api.service.TaskService)8 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 Map (java.util.Map)6 GroupTO (org.apache.syncope.common.lib.to.GroupTO)6 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)6 IOException (java.io.IOException)5 TaskTO (org.apache.syncope.common.lib.to.TaskTO)5 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)5 AttrTO (org.apache.syncope.common.lib.to.AttrTO)4 ConnInstanceTO (org.apache.syncope.common.lib.to.ConnInstanceTO)4 ImplementationTO (org.apache.syncope.common.lib.to.ImplementationTO)4 ItemTO (org.apache.syncope.common.lib.to.ItemTO)4