Search in sources :

Example 51 with SystemException

use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.

the class RUtil method getByteArrayFromXml.

public static byte[] getByteArrayFromXml(String xml, boolean compress) {
    byte[] array;
    GZIPOutputStream gzip = null;
    try {
        if (compress) {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            gzip = new GZIPOutputStream(out);
            gzip.write(xml.getBytes("utf-8"));
            gzip.close();
            out.close();
            array = out.toByteArray();
        } else {
            array = xml.getBytes("utf-8");
        }
    } catch (Exception ex) {
        throw new SystemException("Couldn't save full xml object, reason: " + ex.getMessage(), ex);
    } finally {
        IOUtils.closeQuietly(gzip);
    }
    return array;
}
Also used : SystemException(com.evolveum.midpoint.util.exception.SystemException) GZIPOutputStream(java.util.zip.GZIPOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SystemException(com.evolveum.midpoint.util.exception.SystemException)

Example 52 with SystemException

use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.

the class RUtil method getXmlFromByteArray.

public static String getXmlFromByteArray(byte[] array, boolean compressed) {
    String xml;
    GZIPInputStream gzip = null;
    try {
        if (compressed) {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            gzip = new GZIPInputStream(new ByteArrayInputStream(array));
            IOUtils.copy(gzip, out);
            xml = new String(out.toByteArray(), "utf-8");
        } else {
            xml = new String(array, "utf-8");
        }
    } catch (Exception ex) {
        throw new SystemException("Couldn't read data from full object column, reason: " + ex.getMessage(), ex);
    } finally {
        IOUtils.closeQuietly(gzip);
    }
    return xml;
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) SystemException(com.evolveum.midpoint.util.exception.SystemException) ByteArrayInputStream(java.io.ByteArrayInputStream) RPolyString(com.evolveum.midpoint.repo.sql.data.common.embedded.RPolyString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SystemException(com.evolveum.midpoint.util.exception.SystemException)

Example 53 with SystemException

use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.

the class OrgClosureManager method initializeOracleTemporaryTable.

private void initializeOracleTemporaryTable() {
    Session session = baseHelper.getSessionFactory().openSession();
    Query qCheck = session.createSQLQuery("select table_name from user_tables where table_name = upper('" + TEMP_DELTA_TABLE_NAME_FOR_ORACLE + "')");
    if (qCheck.list().isEmpty()) {
        LOGGER.info("Creating temporary table {}", TEMP_DELTA_TABLE_NAME_FOR_ORACLE);
        session.beginTransaction();
        Query qCreate = session.createSQLQuery("CREATE GLOBAL TEMPORARY TABLE " + TEMP_DELTA_TABLE_NAME_FOR_ORACLE + "    (descendant_oid VARCHAR2(36 CHAR), " + "     ancestor_oid VARCHAR2(36 CHAR), " + "     val NUMBER (10, 0), " + "     PRIMARY KEY (descendant_oid, ancestor_oid)) " + "  ON COMMIT DELETE ROWS");
        try {
            qCreate.executeUpdate();
            session.getTransaction().commit();
        } catch (RuntimeException e) {
            String m = "Couldn't create temporary table " + TEMP_DELTA_TABLE_NAME_FOR_ORACLE + ". Please create the table manually.";
            LoggingUtils.logException(LOGGER, m, e);
            throw new SystemException(m, e);
        }
    }
    session.close();
}
Also used : Query(org.hibernate.Query) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) SystemException(com.evolveum.midpoint.util.exception.SystemException) Session(org.hibernate.Session)

Example 54 with SystemException

use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.

the class TestBrokenResources method test100GetAccountMurray.

@Test
public void test100GetAccountMurray() throws Exception {
    final String TEST_NAME = "test100GetAccountMurray";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = createTask(TEST_NAME);
    OperationResult result = task.getResult();
    try {
        // WHEN
        PrismObject<ShadowType> account = modelService.getObject(ShadowType.class, ACCOUNT_SHADOW_MURRAY_CSVFILE_OID, null, task, result);
        display("Account (unexpected)", account);
        AssertJUnit.fail("Expected SystemException but the operation was successful");
    } catch (SystemException e) {
        // This is expected
        display("Expected exception", e);
        result.computeStatus();
        display("getObject result", result);
        TestUtil.assertFailure("getObject result", result);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SystemException(com.evolveum.midpoint.util.exception.SystemException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) AbstractConfiguredModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractConfiguredModelIntegrationTest)

Example 55 with SystemException

use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.

the class TestDummy method test110SeachIterative.

@Test
public void test110SeachIterative() throws Exception {
    final String TEST_NAME = "test110SeachIterative";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(TestDummy.class.getName() + "." + TEST_NAME);
    // Make sure there is an account on resource that the provisioning has
    // never seen before, so there is no shadow
    // for it yet.
    DummyAccount newAccount = new DummyAccount("meathook");
    newAccount.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Meathook");
    newAccount.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Sea Monkey");
    newAccount.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "hook");
    newAccount.addAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOOT_NAME, 666L);
    newAccount.setEnabled(true);
    newAccount.setPassword("parrotMonster");
    dummyResource.addAccount(newAccount);
    ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(RESOURCE_DUMMY_OID, new QName(ResourceTypeUtil.getResourceNamespace(resourceType), SchemaConstants.ACCOUNT_OBJECT_CLASS_LOCAL_NAME), prismContext);
    final XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();
    final Holder<Boolean> seenMeathookHolder = new Holder<Boolean>(false);
    final List<PrismObject<ShadowType>> foundObjects = new ArrayList<PrismObject<ShadowType>>();
    ResultHandler<ShadowType> handler = new ResultHandler<ShadowType>() {

        @Override
        public boolean handle(PrismObject<ShadowType> object, OperationResult parentResult) {
            foundObjects.add(object);
            display("Found", object);
            XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
            assertTrue(object.canRepresent(ShadowType.class));
            try {
                checkAccountShadow(object, parentResult, true, startTs, endTs);
            } catch (SchemaException e) {
                throw new SystemException(e.getMessage(), e);
            }
            assertCachingMetadata(object, false, startTs, endTs);
            if (object.asObjectable().getName().getOrig().equals("meathook")) {
                meathookAccountOid = object.getOid();
                seenMeathookHolder.setValue(true);
                try {
                    Long loot = ShadowUtil.getAttributeValue(object, dummyResourceCtl.getAttributeQName(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOOT_NAME));
                    assertEquals("Wrong meathook's loot", (Long) 666L, loot);
                } catch (SchemaException e) {
                    throw new SystemException(e.getMessage(), e);
                }
            }
            return true;
        }
    };
    rememberShadowFetchOperationCount();
    // WHEN
    provisioningService.searchObjectsIterative(ShadowType.class, query, null, handler, null, result);
    // THEN
    XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
    result.computeStatus();
    display("searchObjectsIterative result", result);
    TestUtil.assertSuccess(result);
    assertShadowFetchOperationCountIncrement(1);
    assertEquals(4, foundObjects.size());
    checkConsistency(foundObjects);
    assertProtected(foundObjects, 1);
    PrismObject<ShadowType> shadowWillRepo = repositoryService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, result);
    assertRepoShadowCachedAttributeValue(shadowWillRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Flying Dutchman");
    checkRepoAccountShadowWill(shadowWillRepo, startTs, endTs);
    PrismObject<ShadowType> shadowMeathook = repositoryService.getObject(ShadowType.class, meathookAccountOid, null, result);
    display("Meathook shadow", shadowMeathook);
    assertRepoShadowCachedAttributeValue(shadowMeathook, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "hook");
    assertRepoCachingMetadata(shadowMeathook, startTs, endTs);
    // And again ...
    foundObjects.clear();
    rememberShadowFetchOperationCount();
    XMLGregorianCalendar startTs2 = clock.currentTimeXMLGregorianCalendar();
    // WHEN
    provisioningService.searchObjectsIterative(ShadowType.class, query, null, handler, null, result);
    // THEN
    XMLGregorianCalendar endTs2 = clock.currentTimeXMLGregorianCalendar();
    assertShadowFetchOperationCountIncrement(1);
    display("Found shadows", foundObjects);
    assertEquals(4, foundObjects.size());
    checkConsistency(foundObjects);
    assertProtected(foundObjects, 1);
    shadowWillRepo = repositoryService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, result);
    checkRepoAccountShadowWill(shadowWillRepo, startTs2, endTs2);
    shadowMeathook = repositoryService.getObject(ShadowType.class, meathookAccountOid, null, result);
    assertRepoShadowCachedAttributeValue(shadowMeathook, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "hook");
    assertRepoCachingMetadata(shadowMeathook, startTs2, endTs2);
    assertSteadyResource();
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) Holder(com.evolveum.midpoint.util.Holder) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) PrismObject(com.evolveum.midpoint.prism.PrismObject) SystemException(com.evolveum.midpoint.util.exception.SystemException) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) Test(org.testng.annotations.Test)

Aggregations

SystemException (com.evolveum.midpoint.util.exception.SystemException)201 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)113 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)76 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)65 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)35 PrismObject (com.evolveum.midpoint.prism.PrismObject)32 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)32 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)31 QName (javax.xml.namespace.QName)28 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)26 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)26 Task (com.evolveum.midpoint.task.api.Task)23 ArrayList (java.util.ArrayList)21 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)16 GenericFrameworkException (com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)16 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)14 Test (org.testng.annotations.Test)14 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)12 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)12 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)12