当前位置: 首页>>代码示例>>Java>>正文


Java PreferencesService.savePreferences方法代码示例

本文整理汇总了Java中org.kuali.rice.kew.api.preferences.PreferencesService.savePreferences方法的典型用法代码示例。如果您正苦于以下问题:Java PreferencesService.savePreferences方法的具体用法?Java PreferencesService.savePreferences怎么用?Java PreferencesService.savePreferences使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.kuali.rice.kew.api.preferences.PreferencesService的用法示例。


在下文中一共展示了PreferencesService.savePreferences方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testPreferencesDefaultSave

import org.kuali.rice.kew.api.preferences.PreferencesService; //导入方法依赖的package包/类
/**
    * Test that the preferences are saved by default when going through the preferences service.  This
    * means that the preferences service will persist any user option that was not in the db when it went
    * to fetch that preferences.
    */
@Test public void testPreferencesDefaultSave() throws Exception {
      //verify that user doesn't have any preferences in the db.

      final UserOptionsService userOptionsService = KEWServiceLocator.getUserOptionsService();
      Principal principal = KEWServiceLocator.getIdentityHelperService().getPrincipalByPrincipalName("rkirkend");
      Collection userOptions = userOptionsService.findByWorkflowUser(principal.getPrincipalId());
      assertTrue("UserOptions should be empty", userOptions.isEmpty());

      PreferencesService preferencesService = KewApiServiceLocator.getPreferencesService();
      Preferences preferences = preferencesService.getPreferences(principal.getPrincipalId());
      assertTrue("Preferences should require a save.", preferences.isRequiresSave());

      userOptions = userOptionsService.findByWorkflowUser(principal.getPrincipalId());
      assertTrue("UserOptions should not empty", userOptions.isEmpty());

      preferencesService.savePreferences(principal.getPrincipalId(), preferences);
      userOptions = userOptionsService.findByWorkflowUser(principal.getPrincipalId());
      assertTrue("UserOptions should not be empty", !userOptions.isEmpty());

      preferences = preferencesService.getPreferences(principal.getPrincipalId());
      assertFalse("Preferences should NOT require a save.", preferences.isRequiresSave());

      // now delete one of the options
      final UserOptions refreshRateOption = userOptionsService.findByOptionId("REFRESH_RATE", principal.getPrincipalId());
      assertNotNull("REFRESH_RATE option should exist.", refreshRateOption);
      userOptionsService.deleteUserOptions(refreshRateOption);

      assertNull("REFRESH_RATE option should no longer exist.", userOptionsService.findByOptionId("REFRESH_RATE", principal.getPrincipalId()));

      preferences = preferencesService.getPreferences(principal.getPrincipalId());
      assertTrue("Preferences should now require a save again.", preferences.isRequiresSave());

      // save refresh rate again
      refreshRateOption.setLockVerNbr(null);
      userOptionsService.save(refreshRateOption);

      preferences = preferencesService.getPreferences(principal.getPrincipalId());
      assertFalse("Preferences should no longer require a save.", preferences.isRequiresSave());
   }
 
开发者ID:kuali,项目名称:kc-rice,代码行数:45,代码来源:PreferencesServiceTest.java

示例2: testPreferencesMarshallingWithInvalidJson

import org.kuali.rice.kew.api.preferences.PreferencesService; //导入方法依赖的package包/类
/**
 * Tests preference marshalling with invalid json.
 */
@Test
public void testPreferencesMarshallingWithInvalidJson() {
    final UserOptionsService userOptionsService = KEWServiceLocator.getUserOptionsService();
    Principal principal = KEWServiceLocator.getIdentityHelperService().getPrincipalByPrincipalName("ewestfal");
    Collection<UserOptions> userOptions = userOptionsService.findByWorkflowUser(principal.getPrincipalId());
    assertTrue("UserOptions should be empty", userOptions.isEmpty());

    PreferencesService preferencesService = KewApiServiceLocator.getPreferencesService();
    Preferences preferences = preferencesService.getPreferences(principal.getPrincipalId());
    assertTrue("Preferences should require a save.", preferences.isRequiresSave());
    preferencesService.savePreferences(principal.getPrincipalId(), preferences);
    userOptions = userOptionsService.findByWorkflowUser(principal.getPrincipalId());

    UserOptions docSearchOrder = new UserOptions();
    docSearchOrder.setOptionId("DocSearch.LastSearch.Order");
    docSearchOrder.setWorkflowId(principal.getPrincipalId());
    docSearchOrder.setOptionVal("DocSearch.LastSearch.Holding0");

    UserOptions badJsonOption = new UserOptions();
    badJsonOption.setOptionId("DocSearch.LastSearch.Holding0");
    badJsonOption.setWorkflowId(principal.getPrincipalId());

    //this be invalid
    badJsonOption.setOptionVal("{isAdvancedSearch\":\"NO\",\"dateCreatedFrom\":1339168393063,\"documentStatuses\":[],\"documentStatusCategories\":[],\"documentAttributeValues\":{},\"additionalDocumentTypeNames\":[]}");

    userOptionsService.save(docSearchOrder);
    userOptionsService.save(badJsonOption);


    userOptions = userOptionsService.findByWorkflowUser(principal.getPrincipalId());
    assertTrue("UserOptions should not empty", !userOptions.isEmpty());

    //UserOptions previousDocSearch0 = userOptionsService.findByOptionId("DocSearch.LastSearch.Holding0", principal.getPrincipalId());
    preferences = preferencesService.getPreferences(principal.getPrincipalId());
    Preferences.Builder pBuilder = Preferences.Builder.create(preferences);
    Map<String, String> docTypeNotification = new HashMap<String, String>();

    docTypeNotification.put("hello", "world");
    docTypeNotification.put("does_this_thing_have_a", "bookstore example");
    pBuilder.setDocumentTypeNotificationPreferences(docTypeNotification);

    String marshaledXml = null;
    try {
        JAXBContext jaxbContext = JAXBContext.newInstance(Preferences.class);
        Marshaller marshaller = jaxbContext.createMarshaller();

        StringWriter stringWriter = new StringWriter();

        marshaller.marshal(pBuilder.build(), stringWriter);

        marshaledXml = stringWriter.toString();

        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        Preferences actual = (Preferences)unmarshaller.unmarshal(new StringReader(marshaledXml));
        //Object expected = unmarshaller.unmarshal(new StringReader(XML))
        Assert.assertEquals(pBuilder.build(), actual);

    } catch (Throwable e) {
        e.printStackTrace();
    }


}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:67,代码来源:PreferencesServiceTest.java

示例3: testPreferencesMarshallingWithInvalidJson

import org.kuali.rice.kew.api.preferences.PreferencesService; //导入方法依赖的package包/类
@Test
public void testPreferencesMarshallingWithInvalidJson() {
    final UserOptionsService userOptionsService = KEWServiceLocator.getUserOptionsService();
    Principal principal = KEWServiceLocator.getIdentityHelperService().getPrincipalByPrincipalName("ewestfal");
    Collection<UserOptions> userOptions = userOptionsService.findByWorkflowUser(principal.getPrincipalId());
    assertTrue("UserOptions should be empty", userOptions.isEmpty());

    PreferencesService preferencesService = KewApiServiceLocator.getPreferencesService();
    Preferences preferences = preferencesService.getPreferences(principal.getPrincipalId());
    assertTrue("Preferences should require a save.", preferences.isRequiresSave());
    preferencesService.savePreferences(principal.getPrincipalId(), preferences);
    userOptions = userOptionsService.findByWorkflowUser(principal.getPrincipalId());

    UserOptions docSearchOrder = new UserOptions();
    docSearchOrder.setOptionId("DocSearch.LastSearch.Order");
    docSearchOrder.setWorkflowId(principal.getPrincipalId());
    docSearchOrder.setOptionVal("DocSearch.LastSearch.Holding0");

    UserOptions badJsonOption = new UserOptions();
    badJsonOption.setOptionId("DocSearch.LastSearch.Holding0");
    badJsonOption.setWorkflowId(principal.getPrincipalId());

    //this be invalid
    badJsonOption.setOptionVal("{isAdvancedSearch\":\"NO\",\"dateCreatedFrom\":1339168393063,\"documentStatuses\":[],\"documentStatusCategories\":[],\"documentAttributeValues\":{},\"additionalDocumentTypeNames\":[]}");

    userOptionsService.save(docSearchOrder);
    userOptionsService.save(badJsonOption);


    userOptions = userOptionsService.findByWorkflowUser(principal.getPrincipalId());
    assertTrue("UserOptions should not empty", !userOptions.isEmpty());

    //UserOptions previousDocSearch0 = userOptionsService.findByOptionId("DocSearch.LastSearch.Holding0", principal.getPrincipalId());
    preferences = preferencesService.getPreferences(principal.getPrincipalId());
    Preferences.Builder pBuilder = Preferences.Builder.create(preferences);
    Map<String, String> docTypeNotification = new HashMap<String, String>();

    docTypeNotification.put("hello", "world");
    docTypeNotification.put("does_this_thing_have_a", "bookstore example");
    pBuilder.setDocumentTypeNotificationPreferences(docTypeNotification);

    String marshaledXml = null;
    try {
        JAXBContext jaxbContext = JAXBContext.newInstance(Preferences.class);
        Marshaller marshaller = jaxbContext.createMarshaller();

        StringWriter stringWriter = new StringWriter();

        marshaller.marshal(pBuilder.build(), stringWriter);

        marshaledXml = stringWriter.toString();

        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        Preferences actual = (Preferences)unmarshaller.unmarshal(new StringReader(marshaledXml));
        //Object expected = unmarshaller.unmarshal(new StringReader(XML))
        Assert.assertEquals(pBuilder.build(), actual);

    } catch (Throwable e) {
        e.printStackTrace();
    }


}
 
开发者ID:aapotts,项目名称:kuali_rice,代码行数:64,代码来源:PreferencesServiceTest.java


注:本文中的org.kuali.rice.kew.api.preferences.PreferencesService.savePreferences方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。