use of javax.xml.ws.Holder in project zm-mailbox by Zimbra.
the class ExchangeEWSFreeBusyProvider method findFolderByPartialProp.
List<BaseFolderType> findFolderByPartialProp(FolderIdType id, UnindexedFieldURIType prop, String val) {
FindFolderType findFolderRequest = new FindFolderType();
findFolderRequest.setTraversal(FolderQueryTraversalType.SHALLOW);
final NonEmptyArrayOfBaseFolderIdsType ffEmptyArrayOfBaseFolderIdsType = new NonEmptyArrayOfBaseFolderIdsType();
ffEmptyArrayOfBaseFolderIdsType.getFolderIdOrDistinguishedFolderId().add(id);
FolderResponseShapeType stResp = new FolderResponseShapeType();
stResp.setBaseShape(DefaultShapeNamesType.ID_ONLY);
findFolderRequest.setParentFolderIds(ffEmptyArrayOfBaseFolderIdsType);
findFolderRequest.setFolderShape(stResp);
RestrictionType rtRestriction = new RestrictionType();
ContainsExpressionType contains = new ContainsExpressionType();
PathToUnindexedFieldType pix = new PathToUnindexedFieldType();
pix.setFieldURI(prop);
contains.setPath(new JAXBElement<PathToUnindexedFieldType>(new QName("http://schemas.microsoft.com/exchange/services/2006/types", "FieldURI"), PathToUnindexedFieldType.class, pix));
FieldURIOrConstantType ct = new FieldURIOrConstantType();
ConstantValueType cv = new ConstantValueType();
cv.setValue(val);
ct.setConstant(cv);
contains.setConstant(cv);
contains.setContainmentMode(ContainmentModeType.SUBSTRING);
rtRestriction.setSearchExpression(new JAXBElement<SearchExpressionType>(new QName("http://schemas.microsoft.com/exchange/services/2006/types", "Contains"), SearchExpressionType.class, contains));
findFolderRequest.setRestriction(rtRestriction);
Holder<FindFolderResponseType> findFolderResponse = new Holder<FindFolderResponseType>();
RequestServerVersion serverVersion = new RequestServerVersion();
serverVersion.setVersion(ExchangeVersionType.EXCHANGE_2010_SP_1);
Holder<ServerVersionInfo> gfversionInfo = new Holder<ServerVersionInfo>();
MailboxCultureType mct = new MailboxCultureType();
mct.setValue("EN");
TimeZoneDefinitionType tzdt = new TimeZoneDefinitionType();
tzdt.setId("Greenwich Standard Time");
TimeZoneContextType tzct = new TimeZoneContextType();
tzct.setTimeZoneDefinition(tzdt);
service.findFolder(findFolderRequest, mct, serverVersion, tzct, findFolderResponse, gfversionInfo);
FindFolderResponseMessageType ffRespMessage = (FindFolderResponseMessageType) findFolderResponse.value.getResponseMessages().getCreateItemResponseMessageOrDeleteItemResponseMessageOrGetItemResponseMessage().get(0).getValue();
if (ResponseClassType.SUCCESS == ffRespMessage.getResponseClass()) {
return ffRespMessage.getRootFolder().getFolders().getFolderOrCalendarFolderOrContactsFolder();
}
ZimbraLog.fb.warn("findFolderByPartialProp " + ffRespMessage.getResponseCode());
return null;
}
use of javax.xml.ws.Holder in project zm-mailbox by Zimbra.
the class ExchangeEWSFreeBusyProvider method getFreeBusyForHost.
public List<FreeBusy> getFreeBusyForHost(String host, ArrayList<Request> req) throws IOException {
int fb_interval = LC.exchange_free_busy_interval_min.intValueWithinRange(5, 1444);
List<FreeBusyResponseType> results = null;
ArrayList<FreeBusy> ret = new ArrayList<FreeBusy>();
Request r = req.get(0);
long start = Request.offsetInterval(req.get(0).start, fb_interval);
ServerInfo serverInfo = (ServerInfo) r.data;
if (serverInfo == null) {
ZimbraLog.fb.warn("no exchange server info for user " + r.email);
return ret;
}
if (!serverInfo.enabled)
return ret;
ArrayOfMailboxData attendees = new ArrayOfMailboxData();
for (Request request : req) {
EmailAddress email = new EmailAddress();
email.setAddress(request.email);
MailboxData mailbox = new MailboxData();
mailbox.setEmail(email);
mailbox.setAttendeeType(MeetingAttendeeType.REQUIRED);
attendees.getMailboxData().add(mailbox);
}
try {
Duration duration = new Duration();
DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
GregorianCalendar gregorianCalStart = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
gregorianCalStart.setTimeInMillis(start);
duration.setStartTime(datatypeFactory.newXMLGregorianCalendar(gregorianCalStart));
GregorianCalendar gregorianCalEnd = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
gregorianCalEnd.setTimeInMillis(req.get(0).end);
duration.setEndTime(datatypeFactory.newXMLGregorianCalendar(gregorianCalEnd));
FreeBusyViewOptionsType availabilityOpts = new FreeBusyViewOptionsType();
availabilityOpts.setMergedFreeBusyIntervalInMinutes(fb_interval);
availabilityOpts.getRequestedView().add("MergedOnly");
availabilityOpts.setTimeWindow(duration);
GetUserAvailabilityRequestType availabilityRequest = new GetUserAvailabilityRequestType();
// TODO: check if we need to set request timezone
SerializableTimeZone timezone = new SerializableTimeZone();
timezone.setBias(0);
SerializableTimeZoneTime standardTime = new SerializableTimeZoneTime();
standardTime.setTime("00:00:00");
standardTime.setDayOrder((short) 1);
standardTime.setDayOfWeek(DayOfWeekType.SUNDAY);
timezone.setStandardTime(standardTime);
timezone.setDaylightTime(standardTime);
availabilityRequest.setTimeZone(timezone);
availabilityRequest.setFreeBusyViewOptions(availabilityOpts);
availabilityRequest.setMailboxDataArray(attendees);
RequestServerVersion serverVersion = new RequestServerVersion();
serverVersion.setVersion(ExchangeVersionType.EXCHANGE_2010_SP_1);
Holder<GetUserAvailabilityResponseType> availabilityResponse = new Holder<GetUserAvailabilityResponseType>();
Holder<ServerVersionInfo> gfversionInfo = new Holder<ServerVersionInfo>();
service.getUserAvailability(availabilityRequest, availabilityResponse, gfversionInfo);
results = availabilityResponse.value.getFreeBusyResponseArray().getFreeBusyResponse();
} catch (DatatypeConfigurationException dce) {
ZimbraLog.fb.warn("getFreeBusyForHost DatatypeConfiguration failure", dce);
return getEmptyList(req);
} catch (Exception e) {
ZimbraLog.fb.warn("getFreeBusyForHost failure", e);
return getEmptyList(req);
}
for (Request re : req) {
String fb = "";
int i = 0;
for (FreeBusyResponseType attendeeAvailability : results) {
if (re.email == attendees.getMailboxData().get(i).getEmail().getAddress()) {
if (ResponseClassType.SUCCESS != attendeeAvailability.getResponseMessage().getResponseClass()) {
ZimbraLog.fb.warn(attendeeAvailability.getResponseMessage().getMessageText());
ZimbraLog.fb.warn("Error in response. continuing to next one");
i++;
continue;
}
ZimbraLog.fb.debug("Availability for " + attendees.getMailboxData().get(i).getEmail().getAddress() + " [" + attendeeAvailability.getFreeBusyView().getMergedFreeBusy() + "]");
fb = attendeeAvailability.getFreeBusyView().getMergedFreeBusy();
if (fb == null) {
ZimbraLog.fb.warn("Merged view Free Busy info not avaiable");
//Avoid NPE.
fb = "";
}
break;
}
i++;
}
ret.add(new ExchangeFreeBusyProvider.ExchangeUserFreeBusy(fb, re.email, fb_interval, req.get(0).start, req.get(0).end));
}
return ret;
}
use of javax.xml.ws.Holder in project zm-mailbox by Zimbra.
the class ExchangeEWSFreeBusyProvider method bindFolder.
BaseFolderType bindFolder(DistinguishedFolderIdNameType distinguishedFolderId, DefaultShapeNamesType shapeType) {
final DistinguishedFolderIdType distinguishedFolderIdType = new DistinguishedFolderIdType();
distinguishedFolderIdType.setId(distinguishedFolderId);
final NonEmptyArrayOfBaseFolderIdsType nonEmptyArrayOfBaseFolderIdsType = new NonEmptyArrayOfBaseFolderIdsType();
nonEmptyArrayOfBaseFolderIdsType.getFolderIdOrDistinguishedFolderId().add(distinguishedFolderIdType);
GetFolderType getFolderRequest = new GetFolderType();
getFolderRequest.setFolderIds(nonEmptyArrayOfBaseFolderIdsType);
FolderResponseShapeType stResp = new FolderResponseShapeType();
stResp.setBaseShape(shapeType);
getFolderRequest.setFolderShape(stResp);
RequestServerVersion serverVersion = new RequestServerVersion();
serverVersion.setVersion(ExchangeVersionType.EXCHANGE_2010_SP_1);
Holder<ServerVersionInfo> gfversionInfo = new Holder<ServerVersionInfo>();
Holder<GetFolderResponseType> gfresponseHolder = new Holder<GetFolderResponseType>();
MailboxCultureType mct = new MailboxCultureType();
mct.setValue("EN");
TimeZoneDefinitionType tzdt = new TimeZoneDefinitionType();
tzdt.setId("Greenwich Standard Time");
TimeZoneContextType tzct = new TimeZoneContextType();
tzct.setTimeZoneDefinition(tzdt);
service.getFolder(getFolderRequest, mct, serverVersion, tzct, gfresponseHolder, gfversionInfo);
FolderInfoResponseMessageType firmtResp = (FolderInfoResponseMessageType) gfresponseHolder.value.getResponseMessages().getCreateItemResponseMessageOrDeleteItemResponseMessageOrGetItemResponseMessage().get(0).getValue();
if (firmtResp.getFolders().getFolderOrCalendarFolderOrContactsFolder().size() > 0) {
return firmtResp.getFolders().getFolderOrCalendarFolderOrContactsFolder().get(0);
} else {
ZimbraLog.fb.error("Could not find the folder in Exchange : " + distinguishedFolderId.toString());
}
return null;
}
use of javax.xml.ws.Holder in project midpoint by Evolveum.
the class TestSanityLegacy method test030DisableUser.
/**
* Try to disable user. As the user has an account, the account should be disabled as well.
*/
@Test
public void test030DisableUser() throws Exception {
final String TEST_NAME = "test030DisableUser";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
ObjectDeltaType objectChange = unmarshallValueFromFile(REQUEST_USER_MODIFY_ACTIVATION_DISABLE_FILENAME, ObjectDeltaType.class);
Entry entry = openDJController.searchByUid("jack");
assertOpenDJAccountJack(entry, "jack");
String pwpAccountDisabled = OpenDJController.getAttributeValue(entry, "ds-pwp-account-disabled");
display("ds-pwp-account-disabled before change", pwpAccountDisabled);
assertTrue("LDAP account is not enabled (precondition)", openDJController.isAccountEnabled(entry));
assertNoRepoCache();
// WHEN ObjectTypes.USER.getTypeQName(),
OperationResultType result = modifyObjectViaModelWS(objectChange);
// THEN
assertNoRepoCache();
displayJaxb("modifyObject result:", result, SchemaConstants.C_RESULT);
TestUtil.assertSuccess("modifyObject has failed", result);
// Check if user object was modified in the repo
OperationResult repoResult = new OperationResult("getObject");
PrismObject<UserType> repoUser = repositoryService.getObject(UserType.class, USER_JACK_OID, null, repoResult);
display("repository user", repoUser);
UserType repoUserType = repoUser.asObjectable();
// Check if nothing else was modified
assertEqualsPolyString("wrong repo fullName", "Cpt. Jack Sparrow", repoUserType.getFullName());
assertEqualsPolyString("wrong repo locality", "somewhere", repoUserType.getLocality());
// Check if appropriate accountRef is still there
List<ObjectReferenceType> accountRefs = repoUserType.getLinkRef();
assertEquals(1, accountRefs.size());
for (ObjectReferenceType accountRef : accountRefs) {
assertTrue("No OID in " + accountRef + " in " + repoUserType, accountRef.getOid().equals(accountShadowOidOpendj));
}
// Check if shadow is still in the repo and that it is untouched
repoResult = new OperationResult("getObject");
PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, accountShadowOidOpendj, null, repoResult);
display("repo shadow", repoShadow);
ShadowType repoShadowType = repoShadow.asObjectable();
repoResult.computeStatus();
TestUtil.assertSuccess("getObject(repo) has failed", repoResult);
AssertJUnit.assertNotNull(repoShadowType);
AssertJUnit.assertEquals(RESOURCE_OPENDJ_OID, repoShadowType.getResourceRef().getOid());
// check attributes in the shadow: should be only identifiers (ICF UID)
String uid = checkRepoShadow(repoShadow);
// Use getObject to test fetch of complete shadow
Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
Holder<ObjectType> objectHolder = new Holder<ObjectType>();
SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
assertNoRepoCache();
// WHEN
modelWeb.getObject(ObjectTypes.SHADOW.getTypeQName(), accountShadowOidOpendj, options, objectHolder, resultHolder);
// THEN
assertNoRepoCache();
displayJaxb("getObject result", resultHolder.value, SchemaConstants.C_RESULT);
TestUtil.assertSuccess("getObject has failed", resultHolder.value);
ShadowType modelShadow = (ShadowType) objectHolder.value;
display("Shadow (model)", modelShadow);
AssertJUnit.assertNotNull(modelShadow);
AssertJUnit.assertEquals(RESOURCE_OPENDJ_OID, modelShadow.getResourceRef().getOid());
assertAttributeNotNull(modelShadow, SchemaConstants.ICFS_UID);
assertAttribute(resourceTypeOpenDjrepo, modelShadow, "uid", "jack");
assertAttribute(resourceTypeOpenDjrepo, modelShadow, "givenName", "Jack");
assertAttribute(resourceTypeOpenDjrepo, modelShadow, "sn", "Sparrow");
assertAttribute(resourceTypeOpenDjrepo, modelShadow, "cn", "Cpt. Jack Sparrow");
assertAttribute(resourceTypeOpenDjrepo, modelShadow, "displayName", "Cpt. Jack Sparrow");
assertAttribute(resourceTypeOpenDjrepo, modelShadow, "l", "somewhere");
assertNotNull("The account activation is null in the shadow", modelShadow.getActivation());
assertNotNull("The account activation status was not present in shadow", modelShadow.getActivation().getAdministrativeStatus());
assertEquals("The account was not disabled in the shadow", ActivationStatusType.DISABLED, modelShadow.getActivation().getAdministrativeStatus());
// Check if LDAP account was updated
entry = openDJController.searchAndAssertByEntryUuid(uid);
assertOpenDJAccountJack(entry, "jack");
pwpAccountDisabled = OpenDJController.getAttributeValue(entry, "ds-pwp-account-disabled");
display("ds-pwp-account-disabled after change", pwpAccountDisabled);
assertFalse("LDAP account was not disabled", openDJController.isAccountEnabled(entry));
}
use of javax.xml.ws.Holder in project midpoint by Evolveum.
the class TestSanityLegacy method test400ImportFromResource.
@Test
public void test400ImportFromResource() throws Exception {
final String TEST_NAME = "test400ImportFromResource";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
checkAllShadows();
assertNoRepoCache();
OperationResult result = new OperationResult(TestSanityLegacy.class.getName() + "." + TEST_NAME);
// Make sure Mr. Gibbs has "l" attribute set to the same value as an outbound expression is setting
ChangeRecordEntry entry = openDJController.executeLdifChange(LDIF_GIBBS_MODIFY_FILE);
display("Entry from LDIF", entry);
// Let's add an entry with multiple uids.
Entry addEntry = openDJController.addEntryFromLdifFile(LDIF_HERMAN_FILENAME);
display("Entry from LDIF", addEntry);
// WHEN
TaskType taskType = modelWeb.importFromResource(RESOURCE_OPENDJ_OID, IMPORT_OBJECTCLASS);
// THEN
assertNoRepoCache();
displayJaxb("importFromResource result", taskType.getResult(), SchemaConstants.C_RESULT);
AssertJUnit.assertEquals("importFromResource has failed", OperationResultStatusType.IN_PROGRESS, taskType.getResult().getStatus());
// Convert the returned TaskType to a more usable Task
Task task = taskManager.createTaskInstance(taskType.asPrismObject(), result);
AssertJUnit.assertNotNull(task);
assertNotNull(task.getOid());
AssertJUnit.assertTrue(task.isAsynchronous());
AssertJUnit.assertEquals(TaskExecutionStatus.RUNNABLE, task.getExecutionStatus());
// AssertJUnit.assertEquals(TaskExclusivityStatus.CLAIMED, task.getExclusivityStatus());
display("Import task after launch", task);
PrismObject<TaskType> tObject = repositoryService.getObject(TaskType.class, task.getOid(), null, result);
TaskType taskAfter = tObject.asObjectable();
display("Import task in repo after launch", taskAfter);
result.computeStatus();
TestUtil.assertSuccess("getObject has failed", result);
final String taskOid = task.getOid();
waitFor("Waiting for import to complete", new Checker() {
@Override
public boolean check() throws CommonException {
Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
Holder<ObjectType> objectHolder = new Holder<ObjectType>();
OperationResult opResult = new OperationResult("import check");
assertNoRepoCache();
SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
try {
modelWeb.getObject(ObjectTypes.TASK.getTypeQName(), taskOid, options, objectHolder, resultHolder);
} catch (FaultMessage faultMessage) {
throw new SystemException(faultMessage);
}
assertNoRepoCache();
// display("getObject result (wait loop)",resultHolder.value);
TestUtil.assertSuccess("getObject has failed", resultHolder.value);
Task task = taskManager.createTaskInstance((PrismObject<TaskType>) objectHolder.value.asPrismObject(), opResult);
System.out.println(new Date() + ": Import task status: " + task.getExecutionStatus() + ", progress: " + task.getProgress());
if (task.getExecutionStatus() == TaskExecutionStatus.CLOSED) {
// Task closed, wait finished
return true;
}
// IntegrationTestTools.display("Task result while waiting: ", task.getResult());
return false;
}
@Override
public void timeout() {
// No reaction, the test will fail right after return from this
}
}, 180000);
// wait a second until the task will be definitely saved
Thread.sleep(1000);
//### Check task state after the task is finished ###
Holder<ObjectType> objectHolder = new Holder<ObjectType>();
Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
assertNoRepoCache();
modelWeb.getObject(ObjectTypes.TASK.getTypeQName(), task.getOid(), options, objectHolder, resultHolder);
assertNoRepoCache();
TestUtil.assertSuccess("getObject has failed", resultHolder.value);
task = taskManager.createTaskInstance((PrismObject<TaskType>) objectHolder.value.asPrismObject(), result);
display("Import task after finish (fetched from model)", task);
AssertJUnit.assertEquals(TaskExecutionStatus.CLOSED, task.getExecutionStatus());
assertNotNull("Null lastRunStartTimestamp in " + task, task.getLastRunStartTimestamp());
assertNotNull("Null lastRunFinishTimestamp in " + task, task.getLastRunFinishTimestamp());
long importDuration = task.getLastRunFinishTimestamp() - task.getLastRunStartTimestamp();
double usersPerSec = (task.getProgress() * 1000) / importDuration;
display("Imported " + task.getProgress() + " users in " + importDuration + " milliseconds (" + usersPerSec + " users/sec)");
OperationResult taskResult = task.getResult();
AssertJUnit.assertNotNull("Task has no result", taskResult);
TestUtil.assertSuccess("Import task result is not success", taskResult);
AssertJUnit.assertTrue("Task failed", taskResult.isSuccess());
AssertJUnit.assertTrue("No progress", task.getProgress() > 0);
//### Check if the import created users and shadows ###
// Listing of shadows is not supported by the provisioning. So we need
// to look directly into repository
List<PrismObject<ShadowType>> sobjects = repositoryService.searchObjects(ShadowType.class, null, null, result);
result.computeStatus();
TestUtil.assertSuccess("listObjects has failed", result);
AssertJUnit.assertFalse("No shadows created", sobjects.isEmpty());
for (PrismObject<ShadowType> aObject : sobjects) {
ShadowType shadow = aObject.asObjectable();
display("Shadow object after import (repo)", shadow);
// This would be really strange ;-)
assertNotEmpty("No OID in shadow", shadow.getOid());
assertNotEmpty("No name in shadow", shadow.getName());
AssertJUnit.assertNotNull("No objectclass in shadow", shadow.getObjectClass());
AssertJUnit.assertNotNull("Null attributes in shadow", shadow.getAttributes());
assertAttributeNotNull("No UID in shadow", shadow, SchemaConstants.ICFS_UID);
}
Holder<ObjectListType> listHolder = new Holder<ObjectListType>();
assertNoRepoCache();
modelWeb.searchObjects(ObjectTypes.USER.getTypeQName(), null, null, listHolder, resultHolder);
assertNoRepoCache();
ObjectListType uobjects = listHolder.value;
TestUtil.assertSuccess("listObjects has failed", resultHolder.value);
AssertJUnit.assertFalse("No users created", uobjects.getObject().isEmpty());
// TODO: use another account, not guybrush
display("Users after import " + uobjects.getObject().size());
for (ObjectType oo : uobjects.getObject()) {
UserType user = (UserType) oo;
if (SystemObjectsType.USER_ADMINISTRATOR.value().equals(user.getOid())) {
//skip administrator check
continue;
}
display("User after import (repo)", user);
// This would be
assertNotEmpty("No OID in user", user.getOid());
// really
// strange ;-)
assertNotEmpty("No name in user", user.getName());
assertNotNull("No fullName in user", user.getFullName());
assertNotEmpty("No fullName in user", user.getFullName().getOrig());
assertNotEmpty("No familyName in user", user.getFamilyName().getOrig());
if (user.getName().getOrig().equals(USER_GUYBRUSH_USERNAME)) {
// skip the rest of checks for guybrush, he does not have LDAP account now
continue;
}
assertTrue("User " + user.getName() + " is disabled (" + user.getActivation().getAdministrativeStatus() + ")", user.getActivation() == null || user.getActivation().getAdministrativeStatus() == ActivationStatusType.ENABLED);
List<ObjectReferenceType> accountRefs = user.getLinkRef();
AssertJUnit.assertEquals("Wrong accountRef for user " + user.getName(), 1, accountRefs.size());
ObjectReferenceType accountRef = accountRefs.get(0);
boolean found = false;
for (PrismObject<ShadowType> aObject : sobjects) {
ShadowType acc = aObject.asObjectable();
if (accountRef.getOid().equals(acc.getOid())) {
found = true;
break;
}
}
if (!found) {
AssertJUnit.fail("accountRef does not point to existing account " + accountRef.getOid());
}
PrismObject<ShadowType> aObject = modelService.getObject(ShadowType.class, accountRef.getOid(), null, task, result);
ShadowType account = aObject.asObjectable();
display("Account after import ", account);
String attributeValueL = ShadowUtil.getMultiStringAttributeValueAsSingle(account, new QName(ResourceTypeUtil.getResourceNamespace(resourceTypeOpenDjrepo), "l"));
// assertEquals("Unexcpected value of l", "middle of nowhere", attributeValueL);
assertEquals("Unexcpected value of l", getUserLocality(user), attributeValueL);
}
// This also includes "idm" user imported from LDAP. Later we need to ignore that one.
assertEquals("Wrong number of users after import", 10, uobjects.getObject().size());
checkAllShadows();
}
Aggregations