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;
}
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;
}
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();
}
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);
}
}
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();
}
Aggregations