Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
merging
  • Loading branch information
ogz00 committed Apr 15, 2015
2 parents a74c2c0 + 6cda2f2 commit 5fc4188
Show file tree
Hide file tree
Showing 14 changed files with 533 additions and 47 deletions.
Expand Up @@ -39,11 +39,9 @@
import com.evolveum.midpoint.web.component.util.LoadableModel;
import com.evolveum.midpoint.web.component.util.SimplePanel;
import com.evolveum.midpoint.web.page.admin.users.component.AssignableOrgPopupContent;
import com.evolveum.midpoint.web.page.admin.users.component.AssignablePopupContent;
import com.evolveum.midpoint.web.page.admin.users.component.AssignableRolePopupContent;
import com.evolveum.midpoint.web.page.admin.users.dto.UserDtoStatus;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxCheckBox;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
Expand All @@ -56,7 +54,6 @@
import org.apache.wicket.model.Model;

import javax.xml.namespace.QName;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
Expand Down
Expand Up @@ -115,8 +115,6 @@ public OrgTreeTablePanel(String id, IModel<String> rootOid) {

@Override
protected void initLayout() {


WebMarkupContainer treeHeader = new WebMarkupContainer(ID_TREE_HEADER);
treeHeader.setOutputMarkupId(true);
add(treeHeader);
Expand Down
Expand Up @@ -43,6 +43,10 @@ <h3><wicket:message key="pageTask.basic"/></h3>
<td><wicket:message key="pageTask.intent"/></td>
<td><input class="form-control input-sm" type="text" wicket:id="intent"/></td>
</tr>
<tr>
<td><wicket:message key="pageTask.objectClass"/></td>
<td><input class="form-control input-sm" type="text" wicket:id="objectClass"/></td>
</tr>
<tr>
<td><wicket:message key="pageTask.runUntilNodeDown"/></td>
<td><input class="input-sm" type="checkbox" wicket:id="runUntilNodeDown"/></td>
Expand Down
Expand Up @@ -16,6 +16,8 @@

package com.evolveum.midpoint.web.page.admin.server;

import com.evolveum.midpoint.common.refinery.RefinedResourceSchema;
import com.evolveum.midpoint.prism.Definition;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.prism.PrismPropertyDefinition;
Expand All @@ -24,6 +26,7 @@
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.schema.SchemaRegistry;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.processor.ResourceSchema;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.security.api.AuthorizationConstants;
import com.evolveum.midpoint.security.api.MidPointPrincipal;
Expand All @@ -45,13 +48,16 @@
import com.evolveum.midpoint.web.security.SecurityUtils;
import com.evolveum.midpoint.web.util.InfoTooltipBehavior;
import com.evolveum.midpoint.web.util.WebMiscUtil;
import com.evolveum.midpoint.web.util.WebModelUtils;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.apache.commons.lang.StringUtils;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.ajax.markup.html.form.AjaxCheckBox;
import org.apache.wicket.datetime.markup.html.form.DateTextField;
import org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteSettings;
import org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField;
import org.apache.wicket.extensions.yui.calendar.DateTimeField;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
Expand All @@ -60,10 +66,10 @@
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.util.string.Strings;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.xml.namespace.QName;
import java.util.*;

/**
* @author lazyman
Expand All @@ -83,6 +89,7 @@ public class PageTaskAdd extends PageAdminTasks {
private static final String ID_DRY_RUN = "dryRun";
private static final String ID_KIND = "kind";
private static final String ID_INTENT = "intent";
private static final String ID_OBJECT_CLASS = "objectClass";
private static final String ID_FORM_MAIN = "mainForm";
private static final String ID_NAME = "name";
private static final String ID_CATEGORY = "category";
Expand All @@ -109,6 +116,7 @@ public class PageTaskAdd extends PageAdminTasks {
private static final Trace LOGGER = TraceManager.getTrace(PageTaskAdd.class);
private static final String DOT_CLASS = PageTaskAdd.class.getName() + ".";
private static final String OPERATION_LOAD_RESOURCES = DOT_CLASS + "createResourceList";
private static final String OPERATION_LOAD_RESOURCE = DOT_CLASS + "loadResource";
private static final String OPERATION_SAVE_TASK = DOT_CLASS + "saveTask";
private IModel<TaskAddDto> model;

Expand All @@ -131,7 +139,7 @@ private void initLayout() {
Form mainForm = new Form(ID_FORM_MAIN);
add(mainForm);

final DropDownChoice resource = new DropDownChoice(ID_RESOURCE,
final DropDownChoice resource = new DropDownChoice<>(ID_RESOURCE,
new PropertyModel<TaskAddResourcesDto>(model, TaskAddDto.F_RESOURCE),
new AbstractReadOnlyModel<List<TaskAddResourcesDto>>() {

Expand Down Expand Up @@ -162,10 +170,41 @@ public boolean isEnabled() {
return sync || recon || importAccounts;
}
});
resource.add(new AjaxFormComponentUpdatingBehavior("onchange") {

@Override
protected void onUpdate(AjaxRequestTarget target) {
OperationResult result = new OperationResult(OPERATION_LOAD_RESOURCE);
List<QName> objectClassList = new ArrayList<>();

TaskAddResourcesDto resourcesDto = model.getObject().getResource();

if(resourcesDto != null){
PrismObject<ResourceType> resource = WebModelUtils.loadObject(ResourceType.class, resourcesDto.getOid(), result, PageTaskAdd.this);

try {
ResourceSchema schema = RefinedResourceSchema.getResourceSchema(resource, getPrismContext());
schema.getObjectClassDefinitions();

for(Definition def: schema.getDefinitions()){
objectClassList.add(def.getTypeName());
}

model.getObject().setObjectClassList(objectClassList);
} catch (Exception e){
LoggingUtils.logException(LOGGER, "Couldn't load object class list from resource.", e);
error("Couldn't load object class list from resource.");
}

}

target.add(get(ID_FORM_MAIN + ":" + ID_OBJECT_CLASS));
}
});
resource.setOutputMarkupId(true);
mainForm.add(resource);

final DropDownChoice kind = new DropDownChoice(ID_KIND,
final DropDownChoice kind = new DropDownChoice<>(ID_KIND,
new PropertyModel<ShadowKindType>(model, TaskAddDto.F_KIND),
new AbstractReadOnlyModel<List<ShadowKindType>>() {

Expand All @@ -191,7 +230,10 @@ public String getIdValue(ShadowKindType object, int index) {
@Override
public boolean isEnabled() {
TaskAddDto dto = model.getObject();
return TaskCategory.RECONCILIATION.equals(dto.getCategory());
boolean sync = TaskCategory.LIVE_SYNCHRONIZATION.equals(dto.getCategory());
boolean recon = TaskCategory.RECONCILIATION.equals(dto.getCategory());
boolean importAccounts = TaskCategory.IMPORTING_ACCOUNTS.equals(dto.getCategory());
return sync || recon || importAccounts;
}
});
mainForm.add(kind);
Expand All @@ -204,11 +246,37 @@ public boolean isEnabled() {
@Override
public boolean isEnabled() {
TaskAddDto dto = model.getObject();
return TaskCategory.RECONCILIATION.equals(dto.getCategory());
boolean sync = TaskCategory.LIVE_SYNCHRONIZATION.equals(dto.getCategory());
boolean recon = TaskCategory.RECONCILIATION.equals(dto.getCategory());
boolean importAccounts = TaskCategory.IMPORTING_ACCOUNTS.equals(dto.getCategory());
return sync || recon || importAccounts;
}
});

AutoCompleteSettings autoCompleteSettings = new AutoCompleteSettings();
autoCompleteSettings.setShowListOnEmptyInput(true);
final AutoCompleteTextField<String> objectClass = new AutoCompleteTextField<String>(ID_OBJECT_CLASS,
new PropertyModel<String>(model, TaskAddDto.F_OBJECT_CLASS), autoCompleteSettings) {

@Override
protected Iterator<String> getChoices(String input) {
return prepareObjectClassChoiceList(input);
}
};
objectClass.add(new VisibleEnableBehaviour(){

@Override
public boolean isEnabled() {
TaskAddDto dto = model.getObject();
boolean sync = TaskCategory.LIVE_SYNCHRONIZATION.equals(dto.getCategory());
boolean recon = TaskCategory.RECONCILIATION.equals(dto.getCategory());
boolean importAccounts = TaskCategory.IMPORTING_ACCOUNTS.equals(dto.getCategory());
return sync || recon || importAccounts;
}
});
mainForm.add(objectClass);

DropDownChoice type = new DropDownChoice(ID_CATEGORY, new PropertyModel<String>(model, TaskAddDto.F_CATEGORY),
DropDownChoice type = new DropDownChoice<>(ID_CATEGORY, new PropertyModel<String>(model, TaskAddDto.F_CATEGORY),
new AbstractReadOnlyModel<List<String>>() {

@Override
Expand All @@ -234,6 +302,7 @@ protected void onUpdate(AjaxRequestTarget target) {
target.add(resource);
target.add(intent);
target.add(kind);
target.add(objectClass);
}
});
type.setRequired(true);
Expand All @@ -252,6 +321,30 @@ protected void onUpdate(AjaxRequestTarget target) {
initButtons(mainForm);
}

private Iterator<String> prepareObjectClassChoiceList(String input){
List<String> choices = new ArrayList<>();

if(model.getObject().getResource() == null){
return choices.iterator();
}

if(Strings.isEmpty(input)){
for(QName q: model.getObject().getObjectClassList()){
choices.add(q.getLocalPart());
Collections.sort(choices);
}
} else {
for(QName q: model.getObject().getObjectClassList()){
if(q.getLocalPart().startsWith(input)){
choices.add(q.getLocalPart());
}
Collections.sort(choices);
}
}

return choices.iterator();
}

private void initScheduling(final Form mainForm) {
final WebMarkupContainer container = new WebMarkupContainer(ID_CONTAINER);
container.setOutputMarkupId(true);
Expand Down Expand Up @@ -369,7 +462,7 @@ private void initAdvanced(Form mainForm) {
CheckBox createSuspended = new CheckBox(ID_CREATE_SUSPENDED, createSuspendedCheck);
mainForm.add(createSuspended);

DropDownChoice threadStop = new DropDownChoice(ID_THREAD_STOP, new Model<ThreadStopActionType>() {
DropDownChoice threadStop = new DropDownChoice<>(ID_THREAD_STOP, new Model<ThreadStopActionType>() {

@Override
public ThreadStopActionType getObject() {
Expand All @@ -394,7 +487,7 @@ public void setObject(ThreadStopActionType object) {

mainForm.add(new TsaValidator(runUntilNodeDown, threadStop));

DropDownChoice misfire = new DropDownChoice(ID_MISFIRE_ACTION, new PropertyModel<MisfireActionType>(
DropDownChoice misfire = new DropDownChoice<>(ID_MISFIRE_ACTION, new PropertyModel<MisfireActionType>(
model, TaskAddDto.F_MISFIRE_ACTION), WebMiscUtil.createReadonlyModelFromEnum(MisfireActionType.class),
new EnumChoiceRenderer<MisfireActionType>(PageTaskAdd.this));
mainForm.add(misfire);
Expand Down Expand Up @@ -605,6 +698,24 @@ private TaskType createTask(TaskAddDto dto) throws SchemaException {
intent.setRealValue(dto.getIntent());
}

if(dto.getObjectClass() != null && StringUtils.isNotEmpty(dto.getObjectClass())){
PrismObject<TaskType> prismTask = task.asPrismObject();
ItemPath path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.OBJECTCLASS_PROPERTY_NAME);
PrismProperty objectClassProperty = prismTask.findOrCreateProperty(path);

QName objectClass = null;
for(QName q: model.getObject().getObjectClassList()){
if(q.getLocalPart().equals(dto.getObjectClass())){
objectClass = q;
}
}

SchemaRegistry registry = getPrismContext().getSchemaRegistry();
PrismPropertyDefinition def = registry.findPropertyDefinitionByElementName(SchemaConstants.OBJECTCLASS_PROPERTY_NAME);
objectClassProperty.setDefinition(def);
objectClassProperty.setRealValue(objectClass);
}

return task;
}

Expand Down
Expand Up @@ -21,6 +21,7 @@ pageTask.browse=Browse
pageTask.name=Task name
pageTask.kind=Kind
pageTask.intent=Intent
pageTask.objectClass=Object class
pageTask.scheduleTitle=Scheduling
pageTask.recurring=Recurring task
pageTask.bound=Tightly bound (use if recurring task runs often)
Expand Down Expand Up @@ -57,5 +58,4 @@ pageTask.boundHelp=Tightly bound tasks are used to run short actions, which are
is not supported for these tasks; you have to specify the time interval.
pageTask.cronHelp=Cron-like specification is in the form: SECONDS MINUTES HOURS DAY-OF-MONTH MONTH DAY-OF-WEEK YEAR \
(optional), e.g. '0 0 12 ? * WED' which means 'every Wednesday at 12:00:00 pm'.
pageTask.cronHelpLink=For more information, please see

Expand Up @@ -67,6 +67,10 @@ <h2><wicket:message key="pageTaskEdit.basic"/></h2>
<td><wicket:message key="pageTaskEdit.intent"/></td>
<td><input class="form-control input-sm" type="text" wicket:id="intent"/></td>
</tr>
<tr>
<td><wicket:message key="pageTaskEdit.objectClass"/></td>
<td><input class="form-control input-sm" type="text" wicket:id="objectClass"/></td>
</tr>
<tr>
<td><wicket:message key="pageTaskEdit.workerThreads"/></td>
<td><input class="form-control input-sm" type="text" wicket:id="workerThreads"/></td>
Expand Down

0 comments on commit 5fc4188

Please sign in to comment.