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
mederly committed Mar 2, 2016
2 parents 2e2d414 + 27b1100 commit 6c30887
Show file tree
Hide file tree
Showing 21 changed files with 416 additions and 167 deletions.
Expand Up @@ -19,9 +19,6 @@
<div class="form-object-value-binary-box">
<input wicket:id="fileInput" type="file" class="form-object-value-binary-file-input"/>
<span class="btn-group">
<a class="btn btn-success btn-xs" wicket:id="upload" wicket:message="title:UploadPanel.upload.tooltip">
<i class="fa fa-upload"/>
</a>
<a class="btn btn-success btn-xs" wicket:id="download" wicket:message="title:UploadPanel.download.tooltip">
<i class="fa fa-download"/>
</a>
Expand Down
Expand Up @@ -26,6 +26,7 @@
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormSubmitBehavior;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.FormComponent;
import org.apache.wicket.markup.html.form.upload.FileUpload;
Expand All @@ -40,7 +41,6 @@ public class UploadDownloadPanel extends InputPanel {

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

private static final String ID_BUTTON_UPLOAD = "upload";
private static final String ID_BUTTON_DOWNLOAD = "download";
private static final String ID_BUTTON_DELETE = "remove";
private static final String ID_INPUT_FILE = "fileInput";
Expand All @@ -51,7 +51,27 @@ public UploadDownloadPanel(String id, boolean isReadOnly) {
}

private void initLayout(final boolean isReadOnly) {
FileUploadField fileUpload = new FileUploadField(ID_INPUT_FILE);
final FileUploadField fileUpload = new FileUploadField(ID_INPUT_FILE);
Form form = this.findParent(Form.class);
fileUpload.add(new AjaxFormSubmitBehavior(form, "change")
{
@Override
protected void onSubmit ( AjaxRequestTarget target )
{
super.onSubmit(target);
Component input = getInputFile();
try {
FileUpload uploadedFile = getFileUpload();
updateValue(uploadedFile.getBytes());
LOGGER.trace("Upload file success.");
input.success(getString("UploadPanel.message.uploadSuccess"));
} catch (Exception e) {
LOGGER.trace("Upload file error.", e);
input.error(getString("UploadPanel.message.uploadError") + " " + e.getMessage());
}
}
} );
fileUpload.setOutputMarkupId(true);
add(fileUpload);

final AjaxDownloadBehaviorFromStream downloadBehavior = new AjaxDownloadBehaviorFromStream() {
Expand All @@ -63,27 +83,12 @@ protected InputStream initStream() {
};
add(downloadBehavior);

add(new AjaxSubmitButton(ID_BUTTON_UPLOAD) {

@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
uploadFilePerformed(target);
}

@Override
protected void onError(AjaxRequestTarget target, Form<?> form) {
uploadFileFailed(target);
}
});

add(new AjaxSubmitButton(ID_BUTTON_DOWNLOAD) {

@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
downloadPerformed(downloadBehavior, target);
}


});

add(new AjaxSubmitButton(ID_BUTTON_DELETE) {
Expand Down Expand Up @@ -154,4 +159,8 @@ private void downloadPerformed(AjaxDownloadBehaviorFromStream downloadBehavior,
AjaxRequestTarget target) {
downloadBehavior.initiate(target);
}

private FileUploadField getInputFile(){
return (FileUploadField)get(ID_INPUT_FILE);
}
}
Expand Up @@ -500,7 +500,8 @@ public Iterator<String> getIterator(String input) {

@Override
public InputStream getStream() {
return new ByteArrayInputStream((byte[]) ((PrismPropertyValue) model.getObject().getValue()).getValue());
Object object = ((PrismPropertyValue) model.getObject().getValue()).getValue();
return object != null ? new ByteArrayInputStream((byte[]) object) : new ByteArrayInputStream(new byte[0]);
// return super.getStream();
}

Expand Down
Expand Up @@ -464,7 +464,6 @@ public Uid update(ObjectClass objectClass, Uid uid, Set<Attribute> replaceAttrib
* {@inheritDoc}
*/
public Uid addAttributeValues(ObjectClass objectClass, Uid uid, Set<Attribute> valuesToAdd, OperationOptions options) {
log.info("addAttributeValues::begin");
validate(objectClass);

try {
Expand Down Expand Up @@ -501,6 +500,8 @@ public Uid addAttributeValues(ObjectClass objectClass, Uid uid, Set<Attribute> v
String name = attr.getName();
try {
account.addAttributeValues(name, attr.getValue());
log.ok("Added attribute {0} values {1} from {2}, resulting values: {3}",
name, attr.getValue(), account, account.getAttributeValues(name, Object.class));
} catch (SchemaViolationException e) {
// we cannot throw checked exceptions. But this one looks suitable.
// Note: let's do the bad thing and add exception loaded by this classloader as inner exception here
Expand Down Expand Up @@ -544,6 +545,8 @@ public Uid addAttributeValues(ObjectClass objectClass, Uid uid, Set<Attribute> v
}
try {
group.addAttributeValues(name, values);
log.ok("Added attribute {0} values {1} from {2}, resulting values: {3}",
name, attr.getValue(), group, group.getAttributeValues(name, Object.class));
} catch (SchemaViolationException e) {
// we cannot throw checked exceptions. But this one looks suitable.
// Note: let's do the bad thing and add exception loaded by this classloader as inner exception here
Expand Down Expand Up @@ -579,6 +582,8 @@ public Uid addAttributeValues(ObjectClass objectClass, Uid uid, Set<Attribute> v
String name = attr.getName();
try {
priv.addAttributeValues(name, attr.getValue());
log.ok("Added attribute {0} values {1} from {2}, resulting values: {3}",
name, attr.getValue(), priv, priv.getAttributeValues(name, Object.class));
} catch (SchemaViolationException e) {
// we cannot throw checked exceptions. But this one looks suitable.
// Note: let's do the bad thing and add exception loaded by this classloader as inner exception here
Expand All @@ -600,15 +605,13 @@ public Uid addAttributeValues(ObjectClass objectClass, Uid uid, Set<Attribute> v
throw new ConnectorIOException(e.getMessage(), e);
}

log.info("addAttributeValues::end");
return uid;
}

/**
* {@inheritDoc}
*/
public Uid removeAttributeValues(ObjectClass objectClass, Uid uid, Set<Attribute> valuesToRemove, OperationOptions options) {
log.info("removeAttributeValues::begin");
validate(objectClass);

try {
Expand Down Expand Up @@ -639,6 +642,8 @@ public Uid removeAttributeValues(ObjectClass objectClass, Uid uid, Set<Attribute
String name = attr.getName();
try {
account.removeAttributeValues(name, attr.getValue());
log.ok("Removed attribute {0} values {1} from {2}, resulting values: {3}",
name, attr.getValue(), account, account.getAttributeValues(name, Object.class));
} catch (SchemaViolationException e) {
// we cannot throw checked exceptions. But this one looks suitable.
// Note: let's do the bad thing and add exception loaded by this classloader as inner exception here
Expand Down Expand Up @@ -679,6 +684,8 @@ public Uid removeAttributeValues(ObjectClass objectClass, Uid uid, Set<Attribute
}
try {
group.removeAttributeValues(name, values);
log.ok("Removed attribute {0} values {1} from {2}, resulting values: {3}",
name, attr.getValue(), group, group.getAttributeValues(name, Object.class));
} catch (SchemaViolationException e) {
// we cannot throw checked exceptions. But this one looks suitable.
// Note: let's do the bad thing and add exception loaded by this classloader as inner exception here
Expand Down Expand Up @@ -711,6 +718,8 @@ public Uid removeAttributeValues(ObjectClass objectClass, Uid uid, Set<Attribute
String name = attr.getName();
try {
priv.removeAttributeValues(name, attr.getValue());
log.ok("Removed attribute {0} values {1} from {2}, resulting values: {3}",
name, attr.getValue(), priv, priv.getAttributeValues(name, Object.class));
} catch (SchemaViolationException e) {
// we cannot throw checked exceptions. But this one looks suitable.
// Note: let's do the bad thing and add exception loaded by this classloader as inner exception here
Expand All @@ -732,7 +741,6 @@ public Uid removeAttributeValues(ObjectClass objectClass, Uid uid, Set<Attribute
throw new ConnectorIOException(e.getMessage(), e);
}

log.info("removeAttributeValues::end");
return uid;
}

Expand Down
Expand Up @@ -300,7 +300,18 @@ public Collection<? extends RefinedAttributeDefinition<?>> getAttributeDefinitio
Collection<? extends RefinedAttributeDefinition<?>> defs = new ArrayList<>();
defs.addAll((Collection)structuralObjectClassDefinition.getAttributeDefinitions());
for(RefinedObjectClassDefinition auxiliaryObjectClassDefinition: auxiliaryObjectClassDefinitions) {
defs.addAll((Collection)auxiliaryObjectClassDefinition.getAttributeDefinitions());
for (RefinedAttributeDefinition auxRAttrDef: auxiliaryObjectClassDefinition.getAttributeDefinitions()) {
boolean add = true;
for (RefinedAttributeDefinition def: defs) {
if (def.getName().equals(auxRAttrDef.getName())) {
add = false;
break;
}
}
if (add) {
((Collection)defs).add(auxRAttrDef);
}
}
}
return defs;
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2015 Evolveum
* Copyright (c) 2010-2016 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -399,6 +399,22 @@ public boolean isExlusiveStrong() {
return refinedAttributeDefinition.isExlusiveStrong();
}

public boolean isSecondaryIdentifier() {
return refinedAttributeDefinition.isSecondaryIdentifier();
}

public boolean isInherited() {
return refinedAttributeDefinition.isInherited();
}

public boolean isVolatilityTrigger() {
return refinedAttributeDefinition.isVolatilityTrigger();
}

public boolean isDisplayNameAttribute() {
return refinedAttributeDefinition.isDisplayNameAttribute();
}

public AttributeFetchStrategyType getFetchStrategy() {
return refinedAttributeDefinition.getFetchStrategy();
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2015 Evolveum
* Copyright (c) 2010-2016 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -64,6 +64,7 @@ public class RefinedAttributeDefinition<T> extends ResourceAttributeDefinition<T
private Integer modificationPriority;
private Boolean readReplaceMode;
private PropertyAccessType accessOverride = new PropertyAccessType();
private boolean isVolatilityTrigger = false;

protected RefinedAttributeDefinition(ResourceAttributeDefinition<T> attrDef, PrismContext prismContext) {
super(attrDef.getName(), attrDef.getTypeName(), prismContext);
Expand Down Expand Up @@ -320,17 +321,23 @@ public void setMatchingRuleQName(QName matchingRuleQName) {
this.matchingRuleQName = matchingRuleQName;
}


public List<String> getTolerantValuePattern(){
return tolerantValuePattern;
}

public List<String> getIntolerantValuePattern(){
return intolerantValuePattern;

}

// schemaHandlingAttrDefType may be null if we are parsing from schema only
public boolean isVolatilityTrigger() {
return isVolatilityTrigger;
}

public void setVolatilityTrigger(boolean isVolatilityTrigger) {
this.isVolatilityTrigger = isVolatilityTrigger;
}

// schemaHandlingAttrDefType may be null if we are parsing from schema only
static <T> RefinedAttributeDefinition<T> parse(ResourceAttributeDefinition<T> schemaAttrDef, ResourceAttributeDefinitionType schemaHandlingAttrDefType,
ObjectClassComplexTypeDefinition objectClassDef, PrismContext prismContext,
String contextDescription) throws SchemaException {
Expand Down Expand Up @@ -388,6 +395,7 @@ static <T> RefinedAttributeDefinition<T> parse(ResourceAttributeDefinition<T> sc
rAttrDef.intolerantValuePattern = schemaHandlingAttrDefType.getIntolerantValuePattern();

rAttrDef.isExclusiveStrong = BooleanUtils.isTrue(schemaHandlingAttrDefType.isExclusiveStrong());
rAttrDef.isVolatilityTrigger = BooleanUtils.isTrue(schemaHandlingAttrDefType.isVolatilityTrigger());

if (schemaHandlingAttrDefType.getOutbound() != null) {
rAttrDef.setOutboundMappingType(schemaHandlingAttrDefType.getOutbound());
Expand Down Expand Up @@ -503,6 +511,7 @@ protected void copyDefinitionData(RefinedAttributeDefinition<T> clone) {
clone.inboundMappingTypes = this.inboundMappingTypes;
clone.intolerantValuePattern = this.intolerantValuePattern;
clone.isExclusiveStrong = this.isExclusiveStrong;
clone.isVolatilityTrigger = this.isVolatilityTrigger;
clone.limitationsMap = this.limitationsMap;
clone.matchingRuleQName = this.matchingRuleQName;
clone.modificationPriority = this.modificationPriority;
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2015 Evolveum
* Copyright (c) 2010-2016 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,6 +36,7 @@
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.PrettyPrinter;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.exception.SchemaException;

/**
Expand Down Expand Up @@ -1481,6 +1482,40 @@ public int hashCode() {
return result;
}

/**
* Deltas are equivalent if they have the same result when
* applied to an object. I.e. meta-data and other "decorations"
* such as old values are not considered in this comparison.
*/
public boolean equivalent(ItemDelta other) {
if (elementName == null) {
if (other.elementName != null)
return false;
} else if (!QNameUtil.match(elementName, elementName))
return false;
if (parentPath == null) {
if (other.parentPath != null)
return false;
} else if (!parentPath.equivalent(other.parentPath))
return false;
if (!equivalentSetRealValue(this.valuesToAdd, other.valuesToAdd))
return false;
if (!equivalentSetRealValue(this.valuesToDelete, other.valuesToDelete))
return false;
if (!equivalentSetRealValue(this.valuesToReplace, other.valuesToReplace))
return false;
return true;
}

public static boolean hasEquivalent(Collection<? extends ItemDelta> col, ItemDelta delta) {
for (ItemDelta colItem: col) {
if (colItem.equivalent(delta)) {
return true;
}
}
return false;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
Expand All @@ -1505,18 +1540,18 @@ public boolean equals(Object obj) {
return false;
} else if (!parentPath.equivalent(other.parentPath)) // or "equals" ?
return false;
if (!equalsSetRealValue(this.valuesToAdd, other.valuesToAdd))
if (!equivalentSetRealValue(this.valuesToAdd, other.valuesToAdd))
return false;
if (!equalsSetRealValue(this.valuesToDelete, other.valuesToDelete))
if (!equivalentSetRealValue(this.valuesToDelete, other.valuesToDelete))
return false;
if (!equalsSetRealValue(this.valuesToReplace, other.valuesToReplace))
if (!equivalentSetRealValue(this.valuesToReplace, other.valuesToReplace))
return false;
if (!equalsSetRealValue(this.estimatedOldValues, other.estimatedOldValues))
if (!equivalentSetRealValue(this.estimatedOldValues, other.estimatedOldValues))
return false;
return true;
}

private boolean equalsSetRealValue(Collection<V> thisValue, Collection<V> otherValues) {
private boolean equivalentSetRealValue(Collection<V> thisValue, Collection<V> otherValues) {
Comparator<?> comparator = new Comparator<Object>() {
@Override
public int compare(Object o1, Object o2) {
Expand Down

0 comments on commit 6c30887

Please sign in to comment.