3

I'm updating my a site property through a job. The job runs ok, it does the work right and updates the property I want it to update properly and never failed.

But, when I save the site, it mess my pages, making them vanish. Worst, it don't always happen @.@ what is driving me crazy! =(

I'm sure the job is running right because once I get all pages back (through worksite setup and site editor) thing get working all. Here the method where I update the property (I have already tried both options of property edition ways:

@Override
public void updateStringProperty(Site site, String name, String value) {
    try {
        // ResourcePropertiesEdit rpe = site.getPropertiesEdit();
        // rpe.addProperty(name, value);

        ResourceProperties rp = site.getProperties();
        rp.addProperty(name, value);

        siteService.save(site);
    } catch (IdUnusedException e) {
        e.printStackTrace();
    } catch (PermissionException e) {
        e.printStackTrace();
    }
}

It's written on the proxy layer, in which my application talks with Sakai interfaces to read/write data onto Sakai databse (You can see the instance of the site come from above) and it's how I get the list of sites to apply changes (also sakai proxy layer):

@Override
public List<Site> getReadInWebSites(Long course) {
    Map<String, String> m = new HashMap<String, String>();
    m.put(Property.COURSE.getName(), Long.toString(course));
    m.put(Property.COURSEFINISHED.getName(), Boolean.toString(false));

    return new ArrayList<Site>(siteService.getSites(SelectionType.ANY,
            null, null, m, SortType.CREATED_BY_ASC, null));
}

Thanks in advance!

EDIT: New info, when I try to access the site (before rebuild its structure through worksite setup, I get this Warn in the log:

org.sakaiproject.portal.charon.site.DefaultSiteViewImpl - Failed to set canAddSite for current user. Defaulting to false ...

Virgílio Santos
  • 412
  • 2
  • 13

1 Answers1

1

This is because when Sakai Sites are loaded with getSites they are lazy objects and don't have all their member variables loaded. This is far from ideal and the SiteService should really either throw an exception when you do this or load the required data.

However to get it working when you're modifying a site fully load the site first before you make changes.

Site site = siteService.getSite(site.getId());
ResourceProperties rp = site.getProperties();
rp.addProperty(name, value);
siteService.save(site);
Matthew Buckett
  • 4,073
  • 1
  • 36
  • 28
  • Thanks, I going to try the solution and give you feedback. I've almost tried something like this, but I was afraid to make the problem worst, since I don't know how exactly SiteSevice handle site instances (glad to know about the lazy load of it). I have already lower the problem by creating a method that updates several properties at the same time: public void updateStringProperties(Site site, Hashmap properties) – Virgílio Santos May 16 '16 at 16:29