<commit_before>/*
 * Copyright (c) 2010-2013 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.prism;

import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.delta.ChangeType;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.delta.PropertyDelta;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.path.ItemPathSegment;
import com.evolveum.midpoint.prism.path.NameItemPathSegment;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.schema.PrismSchema;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ConnectorTypeUtil;
import com.evolveum.midpoint.schema.util.ResourceTypeUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
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.util.WebMiscUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_2a.*;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_2.ActivationCapabilityType;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_2.CapabilityType;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_2.CredentialsCapabilityType;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;

import javax.xml.namespace.QName;
import java.io.Serializable;
import java.util.*;

/**
 * @author lazyman
 */
public class ObjectWrapper implements Serializable {

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

    private static final String DOT_CLASS = ObjectWrapper.class.getName() + ".";
    private static final String CREATE_CONTAINERS = DOT_CLASS + "createContainers";

	private PrismObject object;
	private ObjectDelta oldDelta;
	private ContainerStatus status;
	private HeaderStatus headerStatus;
	private String displayName;
	private String description;
	private List<ContainerWrapper> containers;

	private boolean showEmpty;
	private boolean minimalized;
	private boolean selectable;
	private boolean selected;

    private boolean showAssignments = false;
    private boolean showInheritedObjectAttributes = true;       // whether to show name and description properties and metadata container
    private boolean readonly = false;

    private static final List<QName> INHERITED_OBJECT_SUBCONTAINERS = Arrays.asList(ObjectType.F_METADATA,
            ObjectType.F_EXTENSION);

    private OperationResult result;
    private boolean protectedAccount;

    public ObjectWrapper(String displayName, String description, PrismObject object, ContainerStatus status) {
		Validate.notNull(object, "Object must not be null.");
		Validate.notNull(status, "Container status must not be null.");

		this.displayName = displayName;
		this.description = description;
		this.object = object;
		this.status = status;

        createContainers();
	}

    public OperationResult getResult() {
        return result;
    }

    public void clearResult() {
        result = null;
    }

	public HeaderStatus getHeaderStatus() {
		if (headerStatus == null) {
			headerStatus = HeaderStatus.NORMAL;
		}
		return headerStatus;
	}

	public ObjectDelta getOldDelta() {
		return oldDelta;
	}

	public void setOldDelta(ObjectDelta oldDelta) {
		this.oldDelta = oldDelta;
	}

	public void setHeaderStatus(HeaderStatus headerStatus) {
		this.headerStatus = headerStatus;
	}

	public PrismObject getObject() {
		return object;
	}

	public String getDisplayName() {
		if (displayName == null) {
			return WebMiscUtil.getName(object);
		}
		return displayName;
	}

	public ContainerStatus getStatus() {
		return status;
	}

	public String getDescription() {
		return description;
	}

	public boolean isMinimalized() {
		return minimalized;
	}

	public void setMinimalized(boolean minimalized) {
		this.minimalized = minimalized;
	}

	public boolean isShowEmpty() {
		return showEmpty;
	}

	public void setShowEmpty(boolean showEmpty) {
		this.showEmpty = showEmpty;
	}

	public boolean isSelectable() {
		return selectable;
	}

	public void setSelectable(boolean selectable) {
		this.selectable = selectable;
	}

	public boolean isSelected() {
		return selected;
	}

	public void setSelected(boolean selected) {
		this.selected = selected;
	}

	public List<ContainerWrapper> getContainers() {
		if (containers == null) {
			containers = createContainers();
		}
		return containers;
	}

	public ContainerWrapper findContainerWrapper(ItemPath path) {
		for (ContainerWrapper wrapper : getContainers()) {
			if (path != null && path.equals(wrapper.getPath())) {
				return wrapper;
			} else {
				if (wrapper.getPath() == null) {
					return wrapper;
				}
			}
		}

		return null;
	}

	private List<ContainerWrapper> createCustomContainerWrapper(PrismObject object, QName name) {
		PrismContainer container = object.findContainer(name);
		ContainerStatus status = container == null ? ContainerStatus.ADDING : ContainerStatus.MODIFYING;
		List<ContainerWrapper> list = new ArrayList<ContainerWrapper>();
		if (container == null) {
			PrismContainerDefinition definition = object.getDefinition().findContainerDefinition(name);
			container = definition.instantiate();
		}<commit_msg>fix for user details - disabled user header. MID-1678<commit_after>/*
 * Copyright (c) 2010-2013 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.prism;

import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.delta.ChangeType;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.delta.PropertyDelta;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.path.ItemPathSegment;
import com.evolveum.midpoint.prism.path.NameItemPathSegment;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.schema.PrismSchema;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ConnectorTypeUtil;
import com.evolveum.midpoint.schema.util.ResourceTypeUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
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.util.WebMiscUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_2a.*;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_2.ActivationCapabilityType;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_2.CapabilityType;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_2.CredentialsCapabilityType;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;

import javax.xml.namespace.QName;
import java.io.Serializable;
import java.util.*;

/**
 * @author lazyman
 */
public class ObjectWrapper implements Serializable {

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

    private static final String DOT_CLASS = ObjectWrapper.class.getName() + ".";
    private static final String CREATE_CONTAINERS = DOT_CLASS + "createContainers";

	private PrismObject object;
	private ObjectDelta oldDelta;
	private ContainerStatus status;
	private HeaderStatus headerStatus;
	private String displayName;
	private String description;
	private List<ContainerWrapper> containers;

	private boolean showEmpty;
	private boolean minimalized;
	private boolean selectable;
	private boolean selected;

    private boolean showAssignments = false;
    private boolean showInheritedObjectAttributes = true;       // whether to show name and description properties and metadata container
    private boolean readonly = false;

    private static final List<QName> INHERITED_OBJECT_SUBCONTAINERS = Arrays.asList(ObjectType.F_METADATA,
            ObjectType.F_EXTENSION);

    private OperationResult result;
    private boolean protectedAccount;

    public ObjectWrapper(String displayName, String description, PrismObject object, ContainerStatus status) {
		Validate.notNull(object, "Object must not be null.");
		Validate.notNull(status, "Container status must not be null.");

		this.displayName = displayName;
		this.description = description;
		this.object = object;
		this.status = status;

        createContainers();
	}

    public OperationResult getResult() {
        return result;
    }

    public void clearResult() {
        result = null;
    }

	public HeaderStatus getHeaderStatus() {
		if (headerStatus == null) {
			headerStatus = HeaderStatus.NORMAL;
		}
		return headerStatus;
	}

	public ObjectDelta getOldDelta() {
		return oldDelta;
	}

	public void setOldDelta(ObjectDelta oldDelta) {
		this.oldDelta = oldDelta;
	}

	public void setHeaderStatus(HeaderStatus headerStatus) {
		this.headerStatus = headerStatus;
	}

	public PrismObject getObject() {
		return object;
	}

	public String getDisplayName() {
		if (displayName == null) {
			return WebMiscUtil.getName(object);
		}
		return displayName;
	}

	public ContainerStatus getStatus() {
		return status;
	}

	public String getDescription() {
		return description;
	}

	public boolean isMinimalized() {
		return minimalized;
	}

	public void setMinimalized(boolean minimalized) {
		this.minimalized = minimalized;
	}

	public boolean isShowEmpty() {
		return showEmpty;
	}

	public void setShowEmpty(boolean showEmpty) {
		this.showEmpty = showEmpty;
	}

	public boolean isSelectable() {
		return selectable;
	}

	public void setSelectable(boolean selectable) {
		this.selectable = selectable;
	}

	public boolean isSelected() {
		return selected;
	}

	public void setSelected(boolean selected) {
		this.selected = selected;
	}

	public List<ContainerWrapper> getContainers() {
		if (containers == null) {
			containers = createContainers();
		}
		return containers;
	}

	public ContainerWrapper findContainerWrapper(ItemPath path) {
		for (ContainerWrapper wrapper : getContainers()) {
            if (path != null) {
                if (path.equals(wrapper.getPath())) {
                    return wrapper;
                }
            } else {
                if (wrapper.getPath() == null) {
                    return wrapper;
                }
            }
		}

		return null;
	}

	private List<ContainerWrapper> createCustomContainerWrapper(PrismObject object, QName name) {
		PrismContainer container = object.findContainer(name);
		ContainerStatus status = container == null ? ContainerStatus.ADDING : ContainerStatus.MODIFYING;
		List<ContainerWrapper> list = new ArrayList<ContainerWrapper>();
		if (container == null) {
			PrismContainerDefinition definition = object.getDefinition().findContainerDefinition(name);
			container = definition.instantiate();
		}
{'fraction_non_alphanumeric': 0.08989782465392221, 'fraction_numerical': 0.002966381015161503, 'mean_word_length': 4.432855863921217, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6276745', 'n_tokens_mistral': 3653, 'n_tokens_neox': 3439, 'n_words': 866}