use of com.willshex.blogwt.shared.api.datatype.Property in project blogwt by billy1380.
the class PropertyValidator method lookup.
public static Property lookup(Property property, String name) throws InputValidationException {
if (property == null)
ApiValidator.throwServiceError(InputValidationException.class, ApiError.InvalidValueNull, TYPE + ": " + name);
boolean isIdLookup = false, isNameLookup = false;
if (property.id != null) {
isIdLookup = true;
} else if (property.name != null) {
isNameLookup = true;
}
if (!(isIdLookup || isNameLookup))
ApiValidator.throwServiceError(InputValidationException.class, ApiError.DataTypeNoLookup, TYPE + ": " + name);
Property lookupProperty;
if (isIdLookup) {
lookupProperty = PropertyServiceProvider.provide().getProperty(property.id);
} else {
lookupProperty = PropertyServiceProvider.provide().getNamedProperty(property.name);
}
if (lookupProperty == null)
ApiValidator.throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, TYPE + ": " + name);
return lookupProperty;
}
use of com.willshex.blogwt.shared.api.datatype.Property in project blogwt by billy1380.
the class PropertyController method updateProperties.
public boolean updateProperties(Collection<Property> properties) {
List<Property> changed = null;
String existingPropertyValue;
boolean addToChanged;
for (Property property : properties) {
addToChanged = false;
existingPropertyValue = PropertyHelper.value(propertyLookup.get(property.name));
if (!PropertyHelper.isEmpty(property)) {
if (existingPropertyValue == null) {
addToChanged = true;
} else if (!property.value.equals(existingPropertyValue)) {
addToChanged = true;
}
}
if (addToChanged) {
if (changed == null) {
changed = new ArrayList<Property>();
}
changed.add(property);
}
}
boolean updating = changed != null;
if (updating) {
final UpdatePropertiesRequest input = SessionController.get().setSession(ApiHelper.setAccessCode(new UpdatePropertiesRequest()).properties(changed));
ApiHelper.createBlogClient().updateProperties(input, new AsyncCallback<UpdatePropertiesResponse>() {
@Override
public void onSuccess(UpdatePropertiesResponse output) {
if (output != null && output.status == StatusType.StatusTypeSuccess) {
GWT.log("Properties have been updated successfully... reload to see the effects.");
}
DefaultEventBus.get().fireEventFromSource(new UpdatePropertiesSuccess(input, output), PropertyController.this);
}
@Override
public void onFailure(Throwable caught) {
DefaultEventBus.get().fireEventFromSource(new UpdatePropertiesFailure(input, caught), PropertyController.this);
}
});
}
return updating;
}
use of com.willshex.blogwt.shared.api.datatype.Property in project blogwt by billy1380.
the class PropertyController method fetchProperties.
private void fetchProperties() {
final GetPropertiesRequest input = ApiHelper.setAccessCode(new GetPropertiesRequest());
input.pager = pager;
input.session = SessionController.get().sessionForApiCall();
if (getPropertiesRequest != null) {
getPropertiesRequest.cancel();
}
getPropertiesRequest = ApiHelper.createBlogClient().getProperties(input, new AsyncCallback<GetPropertiesResponse>() {
@Override
public void onSuccess(GetPropertiesResponse output) {
getPropertiesRequest = null;
if (output.status == StatusType.StatusTypeSuccess) {
if (output.properties != null && output.properties.size() > 0) {
pager = output.pager;
JsonArray propertyArray = new JsonArray();
for (Property p : output.properties) {
propertyArray.add(p.toJson());
}
Window.get().setProperties(propertyArray.toString());
}
}
DefaultEventBus.get().fireEventFromSource(new GetPropertiesSuccess(input, output), PropertyController.this);
}
@Override
public void onFailure(Throwable caught) {
getPropertiesRequest = null;
DefaultEventBus.get().fireEventFromSource(new GetPropertiesFailure(input, caught), PropertyController.this);
}
});
}
use of com.willshex.blogwt.shared.api.datatype.Property in project blogwt by billy1380.
the class PropertyController method isConfigured.
/**
* @param values
* @return
*/
public boolean isConfigured(Collection<Property> values) {
boolean configured = true;
if (values != null) {
String ev, v;
for (Property property : values) {
ev = PropertyHelper.value(propertyLookup.get(property.name));
v = PropertyHelper.value(property);
if (ev != v || (v != null && ev != null && !ev.equals(v))) {
configured = false;
break;
}
}
}
return configured;
}
Aggregations