Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/users/PageUser.java
  • Loading branch information
mederly committed Nov 29, 2017
2 parents b320c56 + 503e641 commit 6bd06bd
Show file tree
Hide file tree
Showing 30 changed files with 514 additions and 88 deletions.
Expand Up @@ -1718,7 +1718,7 @@ public boolean isVisible() {

if (getPage() instanceof PageAdminFocus) {
PageAdminFocus page = (PageAdminFocus) getPage();
return page.isOidParameterExists() || page.isObjectAlreadyLoaded;
return page.isOidParameterExists() || page.isEditingFocus();
} else if (getPage() instanceof PageResourceWizard) {
PageResourceWizard page = (PageResourceWizard) getPage();
return !page.isNewResource();
Expand Down Expand Up @@ -1746,7 +1746,7 @@ protected boolean isMenuActive() {

if (PageBase.this.getPage() instanceof PageAdminFocus) {
PageAdminFocus page = (PageAdminFocus) PageBase.this.getPage();
return !page.isOidParameterExists() && !page.isObjectAlreadyLoaded;
return !page.isOidParameterExists() && !page.isEditingFocus();
} else if (PageBase.this.getPage() instanceof PageResourceWizard) {
PageResourceWizard page = (PageResourceWizard) PageBase.this.getPage();
return page.isNewResource();
Expand Down
Expand Up @@ -1877,16 +1877,20 @@ public static void dispatchToObjectDetailsPage(ObjectReferenceType objectRef, Co
dispatchToObjectDetailsPage(targetClass, objectRef.getOid(), component, failIfUnsupported);
}

// shows the actual object that is passed via parameter (not its state in repository)
public static void dispatchToObjectDetailsPage(PrismObject obj, Component component) {
dispatchToObjectDetailsPage(obj, false, component);
}

// shows the actual object that is passed via parameter (not its state in repository)
public static void dispatchToObjectDetailsPage(PrismObject obj, boolean isNewObject, Component component) {
Class newObjectPageClass = getObjectDetailsPage(obj.getCompileTimeClass());
if (newObjectPageClass == null) {
throw new IllegalArgumentException("Cannot determine details page for "+obj.getCompileTimeClass());
}

Constructor constructor;
try {
constructor = newObjectPageClass.getConstructor(PrismObject.class);
constructor = newObjectPageClass.getConstructor(PrismObject.class, boolean.class);

} catch (NoSuchMethodException | SecurityException e) {
throw new SystemException("Unable to locate constructor (PrismObject) in " + newObjectPageClass
Expand All @@ -1895,7 +1899,7 @@ public static void dispatchToObjectDetailsPage(PrismObject obj, Component compon

PageBase page;
try {
page = (PageBase) constructor.newInstance(obj);
page = (PageBase) constructor.newInstance(obj, isNewObject);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException e) {
throw new SystemException("Error instantiating " + newObjectPageClass + ": " + e.getMessage(), e);
Expand Down
Expand Up @@ -222,7 +222,7 @@ public static <T extends ObjectType> PrismObject<T> loadObject(Class<T> type, St
PageBase page, Task task, OperationResult result) {
return loadObject(type, oid, options, true, page, task, result);
}

@Nullable
public static <T extends ObjectType> PrismObject<T> loadObject(Class<T> type, String oid,
Collection<SelectorOptions<GetOperationOptions>> options, boolean allowNotFound,
Expand Down Expand Up @@ -281,6 +281,67 @@ public static <T extends ObjectType> PrismObject<T> loadObject(Class<T> type, St

return object;
}

//TODO consider using modelServiceLocator instead of PageBase in other methods.. Do we even need it? What about showResult? Should it be
// here or directly in the page? Consider usability and readabiltiy
@Nullable
public static <T extends ObjectType> PrismObject<T> loadObject(ObjectReferenceType objectReference,
ModelServiceLocator page, Task task, OperationResult result) {
Class<T> type = page.getPrismContext().getSchemaRegistry().determineClassForType(objectReference.getType());
String oid = objectReference.getOid();
Collection<SelectorOptions<GetOperationOptions>> options = null;
LOGGER.debug("Loading {} with oid {}, options {}", type.getSimpleName(), oid, options);

OperationResult subResult;
if (result != null) {
subResult = result.createMinorSubresult(OPERATION_LOAD_OBJECT);
} else {
subResult = new OperationResult(OPERATION_LOAD_OBJECT);
}
PrismObject<T> object = null;
try {
if (options == null) {
options = SelectorOptions.createCollection(GetOperationOptions.createResolveNames());
} else {
GetOperationOptions getOpts = SelectorOptions.findRootOptions(options);
if (getOpts == null) {
options.add(new SelectorOptions<>(GetOperationOptions.createResolveNames()));
} else {
getOpts.setResolveNames(Boolean.TRUE);
}
}
object = page.getModelService().getObject(type, oid, options, task, subResult);
} catch (AuthorizationException e) {
// Not authorized to access the object. This is probably caused by a reference that
// point to an object that the current user cannot read. This is no big deal.
// Just do not display that object.
subResult.recordHandledError(e);
LOGGER.debug("User {} is not authorized to read {} {}",
task.getOwner() != null ? task.getOwner().getName() : null, type.getSimpleName(), oid);
return null;
} catch (ObjectNotFoundException e) {
// Object does not exist. It was deleted in the meanwhile, or not created yet. This could happen quite often.
subResult.recordHandledError(e);
LOGGER.debug("{} {} does not exist", type.getSimpleName(), oid, e);
return null;

} catch (Exception ex) {
subResult.recordFatalError("WebModelUtils.couldntLoadObject", ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load object", ex);
} finally {
subResult.computeStatus();
}
// TODO reconsider this part: until recently, the condition was always 'false'
if (WebComponentUtil.showResultInPage(subResult)) {
if (page instanceof PageBase) {
((PageBase)page).showResult(subResult);
}
}

LOGGER.debug("Loaded {} with result {}", object, subResult);

return object;
}

public static boolean isNoFetch(Collection<SelectorOptions<GetOperationOptions>> options) {
if (options == null) {
Expand Down
Expand Up @@ -275,15 +275,15 @@ private void targetObjectDetailsPerformed(AssignmentEditorDto assignment, AjaxRe
if (AssignmentEditorDtoType.ORG_UNIT.equals(assignment.getType())){
PrismObject<OrgType> object = WebModelServiceUtils.loadObject(OrgType.class, assignment.getTargetRef().getOid(),
getPageBase(), task, result);
getPageBase().navigateToNext(new PageOrgUnit(object, true));
getPageBase().navigateToNext(new PageOrgUnit(object, false,true));
} else if (AssignmentEditorDtoType.ROLE.equals(assignment.getType())){
PrismObject<RoleType> object = WebModelServiceUtils.loadObject(RoleType.class, assignment.getTargetRef().getOid(),
getPageBase(), task, result);
getPageBase().navigateToNext(new PageRole(object, true));
getPageBase().navigateToNext(new PageRole(object, false, true));
} else if (AssignmentEditorDtoType.SERVICE.equals(assignment.getType())){
PrismObject<ServiceType> object = WebModelServiceUtils.loadObject(ServiceType.class, assignment.getTargetRef().getOid(),
getPageBase(), task, result);
getPageBase().navigateToNext(new PageService(object, true));
getPageBase().navigateToNext(new PageService(object, false,true));
}
} else {
plusIconClicked = false;
Expand Down
Expand Up @@ -16,7 +16,7 @@
-->

<wicket:panel xmlns:wicket="http://wicket.apache.org">
<div >
<div style="margin: 5px;">
<p align="center">
<select wicket:id="type" />
</p>
Expand Down
Expand Up @@ -2,9 +2,12 @@

import javax.xml.namespace.QName;

import com.evolveum.midpoint.web.component.input.QNameObjectTypeChoiceRenderer;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.IChoiceRenderer;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.StringResourceModel;

Expand All @@ -15,6 +18,8 @@
import com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnChangeAjaxFormUpdatingBehavior;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;

import java.util.List;

public class ChooseFocusTypeDialogPanel extends BasePanel implements Popupable{

private static final String ID_OBJECT_TYPE = "type";
Expand All @@ -27,7 +32,7 @@ public ChooseFocusTypeDialogPanel(String id) {

private void initLayout(){
DropDownChoice<QName> type = new DropDownChoice<QName>(ID_OBJECT_TYPE, Model.of(UserType.COMPLEX_TYPE),
WebComponentUtil.createFocusTypeList(), new QNameChoiceRenderer());
WebComponentUtil.createFocusTypeList(), new QNameObjectTypeChoiceRenderer());
type.add(new EmptyOnChangeAjaxFormUpdatingBehavior());
type.setOutputMarkupId(true);
add(type);
Expand Down Expand Up @@ -59,7 +64,7 @@ public int getWidth() {

@Override
public int getHeight() {
return 150;
return 100;
}

@Override
Expand Down
Expand Up @@ -34,6 +34,7 @@
*
* Most of the time {@link com.evolveum.midpoint.schema.constants.ObjectTypes} and such should be used.
*/
@Deprecated
public class QNameChoiceRenderer implements IChoiceRenderer<QName> {
private static final long serialVersionUID = 1L;

Expand Down
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2010-2017 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.evolveum.midpoint.web.component.input;

import org.apache.wicket.markup.html.form.IChoiceRenderer;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.ResourceModel;

import javax.xml.namespace.QName;
import java.util.List;

public class QNameObjectTypeChoiceRenderer implements IChoiceRenderer<QName> {

@Override
public Object getDisplayValue(QName qname) {
if (qname == null) {
return null;
}

String key = "ObjectType." + qname.getLocalPart();

return new ResourceModel(key, key).getObject();
}

@Override
public String getIdValue(QName object, int index) {
return Integer.toString(index);
}

@Override
public QName getObject(String id, IModel<? extends List<? extends QName>> choices) {
if (id == null) {
return null;
}

int i = Integer.parseInt(id);

return choices.getObject().get(i);
}
}
Expand Up @@ -271,7 +271,7 @@ private <O extends ObjectType, C extends Containerable> ContainerWrapper<C> crea
}
Task task = modelServiceLocator.createSimpleTask("Load resource ref");
//TODO: is it safe to case modelServiceLocator to pageBase?
PrismObject<ResourceType> resource = WebModelServiceUtils.loadObject(shadow.getResourceRef(), (PageBase) modelServiceLocator, task, result);
PrismObject<ResourceType> resource = WebModelServiceUtils.loadObject(shadow.getResourceRef(), modelServiceLocator, task, result);

result.computeStatusIfUnknown();
if (!result.isAcceptable()) {
Expand Down
Expand Up @@ -120,7 +120,7 @@ private boolean canAddDefault() {
}

private boolean canReadOrModifyAndNonEmpty() {
return getItemDefinition().canRead() && !getItem().isEmpty(); //(getItemDefinition().canModify() || getItemDefinition().canRead()) && !getItem().isEmpty();
return getItemDefinition().canRead() && (!getItem().isEmpty() || getItemDefinition().isEmphasized()); //(getItemDefinition().canModify() || getItemDefinition().canRead()) && !getItem().isEmpty();
}

private boolean canReadOrModifyAndShowEmpty() {
Expand Down
Expand Up @@ -46,14 +46,13 @@ protected void prepareObjectDeltaForModify(ObjectDelta<T> focusDelta) throws Sch
.findContainerDefinition(AbstractRoleType.F_INDUCEMENT);
}


@Override
protected void prepareObjectForAdd(PrismObject<T> focus) throws SchemaException {
super.prepareObjectForAdd(focus);
}

@Override
protected void initializeModel(final PrismObject<T> objectToEdit, boolean isReadonly) {
super.initializeModel(objectToEdit, isReadonly);
protected void initializeModel(final PrismObject<T> objectToEdit, boolean isNewObject, boolean isReadonly) {
super.initializeModel(objectToEdit, isNewObject, isReadonly);
}
}
Expand Up @@ -86,8 +86,8 @@ public abstract class PageAdminFocus<F extends FocusType> extends PageAdminObjec


@Override
protected void initializeModel(final PrismObject<F> objectToEdit, boolean isReadonly) {
super.initializeModel(objectToEdit, isReadonly);
protected void initializeModel(final PrismObject<F> objectToEdit, boolean isNewObject, boolean isReadonly) {
super.initializeModel(objectToEdit, isNewObject, isReadonly);

projectionModel = new LoadableModel<List<FocusSubwrapperDto<ShadowType>>>(false) {
private static final long serialVersionUID = 1L;
Expand Down
Expand Up @@ -102,10 +102,15 @@ public abstract class PageAdminObjectDetails<O extends ObjectType> extends PageA

private AbstractObjectMainPanel<O> mainPanel;
private boolean saveOnConfigure; // ugly hack - whether to invoke 'Save' when returning to this page
public boolean isObjectAlreadyLoaded = false; //before we got isOidParameterExists status depending only on oid parameter existence
//we should set isEdidintFocus=true not only when oid parameter exists but also

private boolean editingFocus = false; //before we got isOidParameterExists status depending only on oid parameter existence
//we should set editingFocus=true not only when oid parameter exists but also
//when object is given as a constructor parameter

public boolean isEditingFocus() {
return editingFocus;
}

@Override
protected void createBreadcrumb() {
createInstanceBreadcrumb();
Expand Down Expand Up @@ -133,7 +138,7 @@ protected IModel<String> createPageTitleModel() {

@Override
protected String load() {
if (!isOidParameterExists() && !isObjectAlreadyLoaded) {
if (!isOidParameterExists() && !editingFocus) {
String key = "PageAdminObjectDetails.title.new" + getCompileTimeClass().getSimpleName();
return createStringResource(key).getObject();
}
Expand Down Expand Up @@ -190,18 +195,23 @@ protected void reviveModels() throws SchemaException {


public void initialize(final PrismObject<O> objectToEdit) {
initialize(objectToEdit, false);
boolean isNewObject = objectToEdit == null;

initialize(objectToEdit, isNewObject, false);
}

public void initialize(final PrismObject<O> objectToEdit, boolean isReadonly) {
initializeModel(objectToEdit, isReadonly);
public void initialize(final PrismObject<O> objectToEdit, boolean isNewObject) {
initialize(objectToEdit, isNewObject, false);
}

public void initialize(final PrismObject<O> objectToEdit, boolean isNewObject, boolean isReadonly) {
initializeModel(objectToEdit, isNewObject, isReadonly);
initLayout();
}

protected void initializeModel(final PrismObject<O> objectToEdit, boolean isReadonly) {
if (objectToEdit != null){
isObjectAlreadyLoaded = true;
}
protected void initializeModel(final PrismObject<O> objectToEdit, boolean isNewObject, boolean isReadonly) {
editingFocus = !isNewObject;

objectModel = new LoadableModel<ObjectWrapper<O>>(false) {
private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -256,7 +266,7 @@ protected void setSummaryPanelVisibility(FocusSummaryPanel<O> summaryPanel){

@Override
public boolean isVisible() {
return isOidParameterExists() || isObjectAlreadyLoaded;
return isOidParameterExists() || editingFocus;
}
});
}
Expand Down Expand Up @@ -331,7 +341,7 @@ protected ObjectWrapper<O> loadObjectWrapper(PrismObject<O> objectToEdit, boolea
throw new RestartResponseException(getRestartResponsePage());
}

ContainerStatus status = isOidParameterExists() || isObjectAlreadyLoaded ? ContainerStatus.MODIFYING : ContainerStatus.ADDING;
ContainerStatus status = isOidParameterExists() || editingFocus ? ContainerStatus.MODIFYING : ContainerStatus.ADDING;
ObjectWrapper<O> wrapper;
ObjectWrapperFactory owf = new ObjectWrapperFactory(this);
try {
Expand All @@ -347,7 +357,7 @@ protected ObjectWrapper<O> loadObjectWrapper(PrismObject<O> objectToEdit, boolea

loadParentOrgs(wrapper, task, result);

wrapper.setShowEmpty(!isOidParameterExists() && !isObjectAlreadyLoaded);
wrapper.setShowEmpty(!isOidParameterExists() && !editingFocus);
wrapper.setReadonly(isReadonly);

if (LOGGER.isTraceEnabled()) {
Expand Down

0 comments on commit 6bd06bd

Please sign in to comment.