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
  • Loading branch information
KaterynaHonchar committed Oct 27, 2015
2 parents 929e94b + 66e25db commit 07cc610
Show file tree
Hide file tree
Showing 44 changed files with 730 additions and 126 deletions.
Expand Up @@ -34,6 +34,7 @@
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.util.Selectable;
import com.evolveum.midpoint.web.component.util.SelectableBean;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

Expand All @@ -51,6 +52,8 @@ public class ObjectDataProvider<W extends Serializable, T extends ObjectType>
private static final String OPERATION_SEARCH_OBJECTS = DOT_CLASS + "searchObjects";
private static final String OPERATION_COUNT_OBJECTS = DOT_CLASS + "countObjects";

private Set<T> selected = new HashSet<>();

private Class<T> type;
private Collection<SelectorOptions<GetOperationOptions>> options;

Expand All @@ -60,10 +63,46 @@ public ObjectDataProvider(Component component, Class<T> type) {
Validate.notNull(type);
this.type = type;
}


public List<T> getSelectedData() {
for (Serializable s : super.getAvailableData()){
if (s instanceof SelectableBean){
SelectableBean<T> selectable = (SelectableBean<T>) s;
if (selectable.isSelected()){
selected.add(selectable.getValue());
}
}
}
List<T> allSelected = new ArrayList<>();
allSelected.addAll(selected);
return allSelected;
}


@Override
public Iterator<W> internalIterator(long first, long count) {
LOGGER.trace("begin::iterator() from {} count {}.", new Object[]{first, count});

for (W available : getAvailableData()){
if (available instanceof SelectableBean){
SelectableBean<T> selectableBean = (SelectableBean<T>) available;
if (selectableBean.isSelected()){
selected.add(selectableBean.getValue());
}
}
}

for (W available : getAvailableData()){
if (available instanceof SelectableBean){
SelectableBean<T> selectableBean = (SelectableBean<T>) available;
if (!selectableBean.isSelected()){
if (selected.contains(selectableBean.getValue())){
selected.remove(selectableBean.getValue());
}
}
}
}

getAvailableData().clear();

OperationResult result = new OperationResult(OPERATION_SEARCH_OBJECTS);
Expand Down Expand Up @@ -104,7 +143,11 @@ protected void handleNotSuccessOrHandledErrorInIterator(OperationResult result){
}

public W createDataObjectWrapper(PrismObject<T> obj) {
return (W) new SelectableBean<T>(obj.asObjectable());
SelectableBean<T> selectable = new SelectableBean<T>(obj.asObjectable());
if (selected.contains(obj.asObjectable())){
selectable.setSelected(true);
}
return (W) selectable ;
}

@Override
Expand Down
Expand Up @@ -197,13 +197,13 @@ public void onClick(AjaxRequestTarget target) {
@Override
public void onClick(AjaxRequestTarget target) {
DataTable table = getTable().getDataTable();
List<SelectableBean> availableData = ((ObjectDataProvider)table.getDataProvider()).getAvailableData();
List<T> selected = new ArrayList<>();
for (SelectableBean o : availableData){
if (o.isSelected()){
selected.add((T)o.getValue());
}
}
List<T> selected = ((ObjectDataProvider)table.getDataProvider()).getSelectedData();
// List<T> selected = new ArrayList<>();
// for (SelectableBean o : availableData){
// if (o.isSelected()){
// selected.add((T)o.getValue());
// }
// }
addPerformed(target, selected);
}
};
Expand Down
Expand Up @@ -529,12 +529,20 @@ private void loadParentOrgs(ObjectWrapper<T> wrapper, Task task, OperationResult
subResult);
LOGGER.trace("Loaded parent org with result {}",
new Object[] { subResult.getLastSubresult() });
} catch (AuthorizationException e) {
// This can happen if the user has permission to read parentOrgRef but it does not have
// the permission to read target org
// It is OK to just ignore it.
subResult.muteLastSubresultError();
LOGGER.debug("User {} does not have permission to read parent org unit {} (ignoring error)", task.getOwner().getName(), parentOrgRef.getOid());
} catch (Exception ex) {
subResult.recordWarning("Cannot load parent org " + parentOrgRef.getOid(), ex);
LOGGER.warn("Cannot load parent org {}: {}", parentOrgRef.getOid(), ex.getMessage(), ex);
}

wrapper.getParentOrgs().add(parentOrg);
if (parentOrg != null) {
wrapper.getParentOrgs().add(parentOrg);
}
}
subResult.computeStatus();
}
Expand Down Expand Up @@ -638,6 +646,10 @@ private <P extends ObjectType> List<FocusProjectionDto> loadProjectionWrappers(C

PrismObject<P> projection = WebModelUtils.loadObject(type, reference.getOid(), options, this,
task, subResult);
if (projection == null) {
// No access, just skip it
continue;
}
P projectionType = projection.asObjectable();

OperationResultType fetchResult = projectionType.getFetchResult();
Expand Down
Expand Up @@ -31,6 +31,10 @@ <h3><wicket:message key="pageTask.basic"/></h3>
<td><wicket:message key="pageTask.type"/></td>
<td><select class="form-control input-sm" wicket:id="category"/></td>
</tr>
<tr>
<td><wicket:message key="pageTask.focusType"/></td>
<td><select class="form-control input-sm" wicket:id="focusType"/></td>
</tr>
<tr>
<td><wicket:message key="pageTask.objectRef"/></td>
<td><select class="form-control input-sm" wicket:id="resource"/></td>
Expand Down
Expand Up @@ -86,7 +86,8 @@ public class PageTaskAdd extends PageAdminTasks {

private static final long serialVersionUID = 2317887071933841581L;

private static final String ID_DRY_RUN = "dryRun";
private static final String ID_DRY_RUN = "dryRun";
private static final String ID_FOCUS_TYPE = "focusType";
private static final String ID_KIND = "kind";
private static final String ID_INTENT = "intent";
private static final String ID_OBJECT_CLASS = "objectClass";
Expand Down Expand Up @@ -206,6 +207,41 @@ protected void onUpdate(AjaxRequestTarget target) {
resource.setOutputMarkupId(true);
mainForm.add(resource);

final DropDownChoice focusType = new DropDownChoice<>(ID_FOCUS_TYPE,
new PropertyModel<QName>(model, TaskAddDto.F_FOCUS_TYPE),
new AbstractReadOnlyModel<List<QName>>() {

@Override
public List<QName> getObject() {
return createFocusTypeList();
}
}, new IChoiceRenderer<QName>() {

@Override
public Object getDisplayValue(QName object) {
if (FocusType.COMPLEX_TYPE.equals(object)){
return "All (including role,orgs,users)";
}
return object.getLocalPart();
}

@Override
public String getIdValue(QName object, int index) {
return Integer.toString(index);
}
});
focusType.setOutputMarkupId(true);
focusType.add(new VisibleEnableBehaviour(){

@Override
public boolean isEnabled() {
TaskAddDto dto = model.getObject();
return TaskCategory.RECOMPUTATION.equals(dto.getCategory());
}
});
mainForm.add(focusType);


final DropDownChoice kind = new DropDownChoice<>(ID_KIND,
new PropertyModel<ShadowKindType>(model, TaskAddDto.F_KIND),
new AbstractReadOnlyModel<List<ShadowKindType>>() {
Expand Down Expand Up @@ -305,6 +341,7 @@ protected void onUpdate(AjaxRequestTarget target) {
target.add(intent);
target.add(kind);
target.add(objectClass);
target.add(focusType);
}
});
type.setRequired(true);
Expand Down Expand Up @@ -554,6 +591,17 @@ private List<ShadowKindType> createShadowKindTypeList(){

return kindList;
}

private List<QName> createFocusTypeList(){
List<QName> focusTypeList = new ArrayList<>();

focusTypeList.add(UserType.COMPLEX_TYPE);
focusTypeList.add(RoleType.COMPLEX_TYPE);
focusTypeList.add(OrgType.COMPLEX_TYPE);
focusTypeList.add(FocusType.COMPLEX_TYPE);

return focusTypeList;
}

private List<TaskAddResourcesDto> createResourceList() {
OperationResult result = new OperationResult(OPERATION_LOAD_RESOURCES);
Expand Down Expand Up @@ -679,6 +727,16 @@ private TaskType createTask(TaskAddDto dto) throws SchemaException {
dryRun.setRealValue(true);
}

if (dto.getFocusType() != null){

PrismObject<TaskType> prismTask = task.asPrismObject();

ItemPath path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_OBJECT_TYPE);
PrismProperty focusType = prismTask.findOrCreateProperty(path);
focusType.setRealValue(dto.getFocusType());

}

if(dto.getKind() != null){
PrismObject<TaskType> prismTask = task.asPrismObject();
ItemPath path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_KIND);
Expand Down
Expand Up @@ -33,6 +33,7 @@
public class TaskAddDto implements Serializable {

public static final String F_DRY_RUN = "dryRun";
public static final String F_FOCUS_TYPE = "focusType";
public static final String F_KIND = "kind";
public static final String F_INTENT = "intent";
public static final String F_OBJECT_CLASS = "objectClass";
Expand Down Expand Up @@ -70,6 +71,7 @@ public class TaskAddDto implements Serializable {
private MisfireActionType misfireAction = MisfireActionType.EXECUTE_IMMEDIATELY;

private boolean dryRun;
private QName focusType;
private ShadowKindType kind;
private String intent;
private String objectClass;
Expand Down Expand Up @@ -186,6 +188,14 @@ public boolean isDryRun() {
public void setDryRun(boolean dryRun) {
this.dryRun = dryRun;
}

public QName getFocusType() {
return focusType;
}

public void setFocusType(QName focusType) {
this.focusType = focusType;
}

public ShadowKindType getKind() {
return kind;
Expand Down Expand Up @@ -246,6 +256,7 @@ public boolean equals(Object o) {
return false;
if (notStartBefore != null ? !notStartBefore.equals(that.notStartBefore) : that.notStartBefore != null)
return false;
if (focusType != null ? !focusType.equals(that.focusType) : that.focusType != null) return false;
if (objectClass != null ? !objectClass.equals(that.objectClass) : that.objectClass != null) return false;
if (objectClassList != null ? !objectClassList.equals(that.objectClassList) : that.objectClassList != null)
return false;
Expand Down Expand Up @@ -273,6 +284,7 @@ public int hashCode() {
result = 31 * result + (dryRun ? 1 : 0);
result = 31 * result + (kind != null ? kind.hashCode() : 0);
result = 31 * result + (intent != null ? intent.hashCode() : 0);
result = 31 * result + (focusType != null ? focusType.hashCode() : 0);
result = 31 * result + (objectClass != null ? objectClass.hashCode() : 0);
result = 31 * result + (objectClassList != null ? objectClassList.hashCode() : 0);
return result;
Expand Down
Expand Up @@ -43,10 +43,10 @@
import java.util.ArrayList;
import java.util.List;

public abstract class AbstractAssignableSelectionPanel extends BasePanel {
public abstract class AbstractAssignableSelectionPanel<T extends ObjectType> extends BasePanel {

private static final String ID_ADD = "add";
protected Class<? extends ObjectType> type = RoleType.class;
protected Class<T> type = (Class<T>) RoleType.class;
protected IModel<AssignmentSearchDto> searchModel;

protected Context context;
Expand Down Expand Up @@ -159,14 +159,14 @@ protected List<IColumn> createMultiSelectColumns() {
return columns;
}

public Class<? extends ObjectType> getType() {
public Class<T> getType() {
return type;
}

/**
* Override to set the type of the of assignable popup window
* */
public abstract void setType(Class<? extends ObjectType> type);
public abstract void setType(Class<T> type);

/**
* Override to provide the content of such window - this should differ
Expand All @@ -184,7 +184,7 @@ protected void handlePartialError(OperationResult result) {

protected abstract Panel getTablePanel();

protected abstract <T extends ObjectType> List<ObjectType> getSelectedObjects();
protected abstract <T extends ObjectType> List<T> getSelectedObjects();

public ObjectQuery getProviderQuery(){
return context.getProviderQuery();
Expand Down
Expand Up @@ -31,7 +31,7 @@
import java.util.ArrayList;
import java.util.List;

public class AssignableOrgSelectionPanel extends AbstractAssignableSelectionPanel {
public class AssignableOrgSelectionPanel <T extends ObjectType> extends AbstractAssignableSelectionPanel<T> {

private static final Trace LOGGER = TraceManager.getTrace(AssignableOrgSelectionPanel.class);

Expand Down Expand Up @@ -138,7 +138,7 @@ public List<ObjectType> getSelectedObjects(){
return selected;
}

public void setType(Class<? extends ObjectType> type){
public void setType(Class<T> type){
Validate.notNull(type, "Class must not be null.");
this.type = type;

Expand Down

0 comments on commit 07cc610

Please sign in to comment.