Search in sources :

Example 16 with Property

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;
}
Also used : InputValidationException(com.willshex.gson.web.service.server.InputValidationException) Property(com.willshex.blogwt.shared.api.datatype.Property)

Example 17 with Property

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;
}
Also used : UpdatePropertiesSuccess(com.willshex.blogwt.client.api.blog.event.UpdatePropertiesEventHandler.UpdatePropertiesSuccess) UpdatePropertiesFailure(com.willshex.blogwt.client.api.blog.event.UpdatePropertiesEventHandler.UpdatePropertiesFailure) UpdatePropertiesResponse(com.willshex.blogwt.shared.api.blog.call.UpdatePropertiesResponse) UpdatePropertiesRequest(com.willshex.blogwt.shared.api.blog.call.UpdatePropertiesRequest) Property(com.willshex.blogwt.shared.api.datatype.Property)

Example 18 with Property

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);
        }
    });
}
Also used : JsonArray(com.google.gson.JsonArray) GetPropertiesRequest(com.willshex.blogwt.shared.api.blog.call.GetPropertiesRequest) GetPropertiesFailure(com.willshex.blogwt.client.api.blog.event.GetPropertiesEventHandler.GetPropertiesFailure) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) GetPropertiesSuccess(com.willshex.blogwt.client.api.blog.event.GetPropertiesEventHandler.GetPropertiesSuccess) GetPropertiesResponse(com.willshex.blogwt.shared.api.blog.call.GetPropertiesResponse) Property(com.willshex.blogwt.shared.api.datatype.Property)

Example 19 with Property

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;
}
Also used : Property(com.willshex.blogwt.shared.api.datatype.Property)

Aggregations

Property (com.willshex.blogwt.shared.api.datatype.Property)19 JsonElement (com.google.gson.JsonElement)4 InputValidationException (com.willshex.gson.web.service.server.InputValidationException)4 IPropertyService (com.willshex.blogwt.server.service.property.IPropertyService)2 HTTPMethod (com.google.appengine.api.urlfetch.HTTPMethod)1 JsonArray (com.google.gson.JsonArray)1 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 Widget (com.google.gwt.user.client.ui.Widget)1 SyndFeed (com.rometools.rome.feed.synd.SyndFeed)1 FeedException (com.rometools.rome.io.FeedException)1 SyndFeedOutput (com.rometools.rome.io.SyndFeedOutput)1 GetPropertiesFailure (com.willshex.blogwt.client.api.blog.event.GetPropertiesEventHandler.GetPropertiesFailure)1 GetPropertiesSuccess (com.willshex.blogwt.client.api.blog.event.GetPropertiesEventHandler.GetPropertiesSuccess)1 UpdatePropertiesFailure (com.willshex.blogwt.client.api.blog.event.UpdatePropertiesEventHandler.UpdatePropertiesFailure)1 UpdatePropertiesSuccess (com.willshex.blogwt.client.api.blog.event.UpdatePropertiesEventHandler.UpdatePropertiesSuccess)1 HttpHelper (com.willshex.blogwt.server.helper.HttpHelper)1 InlineHelper (com.willshex.blogwt.server.helper.InlineHelper)1 PersistenceHelper (com.willshex.blogwt.server.helper.PersistenceHelper)1 ServletHelper (com.willshex.blogwt.server.helper.ServletHelper)1 ArchiveEntryServiceProvider (com.willshex.blogwt.server.service.archiveentry.ArchiveEntryServiceProvider)1