private Object convertValue(
     final ClassAttributeAssignmentModel assignment, final String stringValue) {
   final String typeCode = assignment.getAttributeType().getCode();
   if (ClassificationAttributeTypeEnum.BOOLEAN.getCode().equals(typeCode)) {
     return Boolean.valueOf(stringValue);
   } else if (ClassificationAttributeTypeEnum.ENUM.getCode().equals(typeCode)) {
     // YTODO
     final Item item = JaloSession.getCurrentSession().getItem(PK.parse(stringValue));
     final Object value = load(item);
     validateParameterNotNull(value, "No such value with PK: " + stringValue);
     return value;
   } else if (ClassificationAttributeTypeEnum.NUMBER.getCode().equals(typeCode)) {
     return Double.valueOf(stringValue);
   } else if (ClassificationAttributeTypeEnum.STRING.getCode().equals(typeCode)) {
     return stringValue;
   } else if (ClassificationAttributeTypeEnum.DATE.getCode().equals(typeCode)) {
     try {
       return Utilities.getDateTimeInstance().parse(stringValue);
     } catch (final ParseException e) {
       throw new IllegalArgumentException(e.getMessage(), e);
     }
   } else {
     throw new IllegalArgumentException("Invalid classifcation attribute type code: " + typeCode);
   }
 }
  protected String dumpMediaMimeInfo(final MediaModel media) {
    final PK mediaPK = media.getPk();
    final Media jaloItem = JaloSession.getCurrentSession().getItem(mediaPK);

    final boolean isNew = modelService.isNew(media);
    final boolean isDirty = modelService.isModified(media);
    final boolean txRunning = Transaction.current().isRunning();
    final boolean txCacheIsolationEnabled = Config.itemCacheIsolationActivated();
    final boolean itemCacheBound = jaloItem.isCacheBound();

    return "Media(pk:"
        + media.getPk()
        + "/"
        + jaloItem.getPK()
        + ", new="
        + isNew
        + ", modified="
        + isDirty
        + ", txRunning="
        + txRunning
        + ", txCacheIsolation="
        + txCacheIsolationEnabled
        + ", cacheBound="
        + itemCacheBound;
  }
 @Override
 protected UserModel retriveCurrentFrontendUser(final String frontendUserUid) {
   UserModel ret = null;
   if (StringUtils.isNotEmpty(frontendUserUid)) {
     SessionContext ctx = null;
     try {
       ctx = JaloSession.getCurrentSession().createLocalSessionContext();
       ctx.setAttribute("disableRestrictions", Boolean.TRUE);
       ret = getUserService().getUser(frontendUserUid);
     } finally {
       if (ctx != null) {
         JaloSession.getCurrentSession().removeLocalSessionContext();
       }
     }
   }
   return ret;
 }
  public void run() {
    Registry.activateStandaloneMode();
    Registry.activateMasterTenant();

    final JaloSession jaloSession = JaloSession.getCurrentSession();
    System.out.println("Session ID: " + jaloSession.getSessionID()); // NOPMD
    System.out.println("User: " + jaloSession.getUser()); // NOPMD
    Utilities.printAppInfo();

    RedeployUtilities.shutdown();
  }
示例#5
0
  @SuppressWarnings("deprecation")
  protected static SyncItemJob setupStoreTemplateSyncJobs(
      final CatalogVersionSyncJobModel syncJobModel, final ModelService modelService) {
    // configure root types
    final SyncItemJob syncJob = modelService.getSource(syncJobModel);
    if (syncJob == null) {
      LOG.warn(
          "Could not setup catalog version synchronization job. Reason: Synchronization job not found.");

    } else {
      final List<ComposedType> rootTypes = new ArrayList<ComposedType>(2);
      final ComposedType cmsItemType =
          TypeManager.getInstance().getComposedType(Cms2Constants.TC.CMSITEM);
      rootTypes.add(cmsItemType);
      rootTypes.add(TypeManager.getInstance().getComposedType(Cms2Constants.TC.CMSRELATION));
      rootTypes.add(TypeManager.getInstance().getComposedType(Media.class));
      syncJob.setRootTypes(JaloSession.getCurrentSession().getSessionContext(), rootTypes);
      syncJob.setSyncLanguages(
          JaloSession.getCurrentSession().getSessionContext(),
          C2LManager.getInstance().getAllLanguages());

      final Collection<SyncAttributeDescriptorConfig> syncAttributeConfigs =
          syncJob.getSyncAttributeConfigurations();
      for (final SyncAttributeDescriptorConfig syncAttributeDescriptorConfig :
          syncAttributeConfigs) {
        final Type attributeType =
            syncAttributeDescriptorConfig.getAttributeDescriptor().getAttributeType();
        if ((syncAttributeDescriptorConfig
                    .getAttributeDescriptor()
                    .getEnclosingType()
                    .isAssignableFrom(cmsItemType)
                && cmsItemType.isAssignableFrom(attributeType))
            || ((attributeType instanceof CollectionType)
                && cmsItemType.isAssignableFrom(
                    ((CollectionType) attributeType).getElementType()))) {
          syncAttributeDescriptorConfig.setCopyByValue(true);
        }
      }
    }
    return syncJob;
  }
  /** Creates some attachments and assigns them to the test workflow. */
  @Test
  public void testAttachments() {
    final PK workflowPk = testWorkflow.getPK();
    // create product attachment
    final Product product = jaloSession.getProductManager().createProduct("sabbers");
    assertNotNull("Product not null", product);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put(WorkflowItemAttachment.CODE, "productTest");
    map.put(WorkflowItemAttachment.ITEM, product);
    map.put(WorkflowItemAttachment.WORKFLOW, testWorkflow);
    final WorkflowItemAttachment attachProduct =
        WorkflowManager.getInstance().createWorkflowItemAttachment(map);
    assertNotNull("Attachment not null", attachProduct);

    // create category attachment
    final Category category =
        CategoryManager.getInstance().createCategory(PK.createUUIDPK(0).getHex());
    assertNotNull("Category not null", category);
    map = new HashMap<String, Object>();
    map.put(WorkflowItemAttachment.CODE, "categoryTest");
    map.put(WorkflowItemAttachment.ITEM, category);
    map.put(WorkflowItemAttachment.WORKFLOW, testWorkflow);
    final WorkflowItemAttachment attachCategory =
        WorkflowManager.getInstance().createWorkflowItemAttachment(map);
    assertNotNull("Attachment not null", attachCategory);

    final WorkflowAction action1 = getAction(ACTIONCODES.ACTION1.name());
    action1.setAttachments(
        Arrays.asList(new WorkflowItemAttachment[] {attachProduct, attachCategory}));

    // restart
    Registry.getCurrentTenant().getCache();

    // check attachments
    final Workflow found = JaloSession.getCurrentSession().getItem(workflowPk);
    assertEquals("Excpected number of attachments", 2, found.getAttachments().size());
    final WorkflowAction foundAction = getAction(ACTIONCODES.ACTION1.name());
    assertEquals(
        "Excpected number of attachments of action 1", 2, foundAction.getAttachments().size());
  }
  @Override
  public void beforeView(
      final HttpServletRequest request,
      final HttpServletResponse response,
      final ModelAndView modelAndView) {
    final boolean showDebug = Config.getBoolean(SHOW_STOREFRONT_DEBUG_INFO_PROPERTY_KEY, false);

    // Store the show debug flag in a request attribute
    request.setAttribute(SHOW_STOREFRONT_DEBUG_INFO, Boolean.valueOf(showDebug));

    if (showDebug) {
      final JaloSession currentSession = JaloSession.getCurrentSession();

      final TreeMap<String, Object> attributeMap = new TreeMap<String, Object>();
      // Build up the session attributes as a request attribute
      attributeMap.putAll(currentSession.getAttributes());
      // Add the session id as an attribute
      attributeMap.put("JaloSession ID", currentSession.getSessionID());

      request.setAttribute(JALO_SESSION_ATTRIBUTES, mapToString(attributeMap));
    }
  }
  @Test
  public void testTTLForItemWrappedResults() {
    assertNotNull(product);

    final FlexibleSearch flexibleSearch = FlexibleSearch.getInstance();

    final String query = "SELECT {p:" + Item.PK + "} FROM {Product AS p} WHERE {pk}=?pk";
    final Map params = Collections.singletonMap("pk", product.getPK());

    final SessionContext ctx = JaloSession.getCurrentSession().createSessionContext();
    ctx.setAttribute(FlexibleSearch.CACHE_TTL, Integer.valueOf(TTL_TIME)); // set TTL

    final long time0 = System.currentTimeMillis();
    final StandardSearchResult<Product> rsFirst =
        (StandardSearchResult<Product>) flexibleSearch.search(ctx, query, params, Product.class);
    final long time1 = System.currentTimeMillis();

    final long tOutMin = time0 + (TTL_TIME * 1000);
    final long tOutMax = time1 + (TTL_TIME * 1000);

    assertFalse(rsFirst.isFromCache()); // first raw
    assertEquals(Collections.singletonList(product), rsFirst.getResult());

    final StandardSearchResult rsSecond =
        (StandardSearchResult<Product>) flexibleSearch.search(ctx, query, params, Product.class);

    assertTrue(rsSecond.isFromCache()); // second from cache
    assertNotSame(rsFirst, rsSecond);
    assertEqualsExceptFromCacheFlag(rsFirst, rsSecond);
    assertEquals(Collections.singletonList(product), rsSecond.getResult());

    // cause invalidation by changing description
    product.setDescription("Some changes there ....");

    if (System.currentTimeMillis() > tOutMin) {
      LOG.warn("cannot continue testing since TTL time has been exceeded");
    }
    final StandardSearchResult rsThird =
        (StandardSearchResult<Product>) flexibleSearch.search(ctx, query, params, Product.class);

    assertTrue(rsThird.isFromCache()); // third from cache too, because of TTL
    assertNotSame(rsFirst, rsThird);
    assertEqualsExceptFromCacheFlag(rsFirst, rsThird);
    assertEquals(Collections.singletonList(product), rsThird.getResult());

    // search without TTL -> should get fresh result
    final StandardSearchResult rsThirdNormal =
        (StandardSearchResult<Product>) flexibleSearch.search(query, params, Product.class);

    assertFalse(rsThirdNormal.isFromCache());
    assertNotSame(rsFirst, rsThirdNormal);
    assertEquals(Collections.singletonList(product), rsThirdNormal.getResult());

    try {
      Thread.sleep(
          (tOutMax - System.currentTimeMillis()) + 100); // wait until TTL time has passed for sure
    } catch (final InterruptedException e) {
      // don't care
    }

    assertTrue(System.currentTimeMillis() > tOutMax);

    // now we should get a new result
    final StandardSearchResult rsFourth =
        (StandardSearchResult<Product>) flexibleSearch.search(ctx, query, params, Product.class);

    assertFalse(rsFourth.isFromCache()); // any way from cache because of TTL
    assertEquals(Collections.singletonList(product), rsFourth.getResult());
  }
 @Before
 public void createConfiguration1() throws Exception {
   JaloSession.getCurrentSession().setUser(UserManager.getInstance().getAdminEmployee());
   importCsv("/testdata/testdata07.csv", "UTF-8");
 }
 public static final TrainingFulfilmentProcessManager getInstance() {
   ExtensionManager em = JaloSession.getCurrentSession().getExtensionManager();
   return (TrainingFulfilmentProcessManager)
       em.getExtension(TrainingFulfilmentProcessConstants.EXTENSIONNAME);
 }