List of usage examples for java.io Serializable toString
public String toString()
From source file:org.pentaho.platform.repository2.unified.fs.FileSystemRepositoryFileDao.java
public Map<String, Serializable> getFileMetadata(final Serializable fileId) { final String metadataFilename = FilenameUtils.concat( FilenameUtils.concat(FilenameUtils.getFullPathNoEndSeparator(fileId.toString()), ".metadata"), FilenameUtils.getName(fileId.toString())); final Map<String, Serializable> metadata = new HashMap<String, Serializable>(); BufferedReader reader = null; try {/*from ww w . ja v a 2 s .c o m*/ reader = new BufferedReader(new FileReader(metadataFilename)); String data = reader.readLine(); while (data != null) { final int pos = data.indexOf('='); if (pos > 0) { final String key = data.substring(0, pos); final String value = (data.length() > pos ? data.substring(pos + 1) : null); metadata.put(key, value); } data = reader.readLine(); } } catch (FileNotFoundException e) { // Do nothing ... metadata empty } catch (IOException e) { throw new UnifiedRepositoryException("Error reading metadata [" + fileId + "]", e); } finally { IOUtils.closeQuietly(reader); } return metadata; }
From source file:org.silverpeas.core.io.temp.TemporaryWorkspaceTranslationTest.java
@Test public void testWorkspacePutKeyValueOnNotCreatedWorkspace() throws Exception { File descriptor = new File(tempPath, (SILVERPEAS_TRANSLATION_PREFIX + TEST_WORKSPACE_ID)); Serializable serializable = new SerializableClass(); TemporaryWorkspaceTranslation test = TemporaryWorkspaceTranslation.from(TEST_WORKSPACE_ID); test.put("key", "value"); test.put("otherKey", serializable); assertThat((String) test.get("key"), is("value")); assertThat(test.get("otherKey"), not(sameInstance(serializable))); assertThat(test.get("otherKey").toString(), is(serializable.toString())); assertThat(descriptor.exists(), is(false)); test = TemporaryWorkspaceTranslation.from(TEST_WORKSPACE_ID); assertThat(descriptor.exists(), is(false)); assertThat(test.get("key"), nullValue()); assertThat(test.get("otherKey"), nullValue()); }
From source file:org.egov.utils.VoucherHelper.java
public String getEg_Voucher(final String vouType, final String fiscalPeriodIdStr) throws TaskFailedException, Exception { if (LOGGER.isDebugEnabled()) LOGGER.debug(" In EGovernCommon :getEg_Voucher method "); final Query query = persistenceService.getSession().createSQLQuery( "select name from fiscalperiod where id=" + Integer.parseInt(fiscalPeriodIdStr) + ""); final List<String> fc = query.list(); // Sequence name will be SQ_U_DBP_CGVN_FP7 for vouType U/DBP/CGVN and fiscalPeriodIdStr 7 Serializable sequenceNumber; String sequenceName;/* w w w . java2s . co m*/ sequenceName = sequenceNameFor(vouType, fc.get(0).toString()); sequenceNumber = genericSequenceNumberGenerator.getNextSequence(sequenceName); return sequenceNumber.toString(); }
From source file:org.bonitasoft.forms.server.api.impl.FormExpressionsAPIImplIT.java
@Test public void testEvaluateExpressionOnProcessWithFieldAndTransiantData() throws Exception { final Map<String, FormFieldValue> fieldValues = new HashMap<String, FormFieldValue>(); fieldValues.put("application", new FormFieldValue("Excel", String.class.getName())); final Expression fieldExpression = new Expression(null, "field_application", ExpressionType.TYPE_INPUT.name(), String.class.getName(), null, null); final Expression transientDataExpression = new Expression(null, "transientData", ExpressionType.TYPE_INPUT.name(), String.class.getName(), null, null); final List<Expression> dependencies = new ArrayList<Expression>(); dependencies.add(fieldExpression);//from w w w .j a va 2 s . co m dependencies.add(transientDataExpression); final Expression expressionToEvaluate = new Expression(null, "transientData + \"-\" + field_application", ExpressionType.TYPE_READ_ONLY_SCRIPT.name(), String.class.getName(), "GROOVY", dependencies); final Map<String, Serializable> context = new HashMap<String, Serializable>(); context.put("transientData", "transientDataValue"); final Serializable result = formExpressionsAPI.evaluateProcessExpression(getSession(), processDefinition.getId(), expressionToEvaluate, fieldValues, Locale.ENGLISH, context); Assert.assertEquals("transientDataValue-Excel", result.toString()); }
From source file:org.bonitasoft.forms.server.api.impl.FormExpressionsAPIImplIT.java
@Test public void testEvaluateExpressionOnTerminatedInstanceWithInitialValues() throws Exception { // Terminate process Assert.assertTrue("no pending user task instances are found", new WaitUntil(50, 1000) { @Override//www .ja v a 2 s.c o m protected boolean check() throws Exception { return processAPI.getPendingHumanTaskInstances( FormExpressionsAPIImplIT.this.getSession().getUserId(), 0, 10, null).size() >= 1; } }.waitUntil()); HumanTaskInstance humanTaskInstance = processAPI .getPendingHumanTaskInstances(getSession().getUserId(), 0, 1, ActivityInstanceCriterion.NAME_ASC) .get(0); long activityInstanceId = humanTaskInstance.getId(); processAPI.assignUserTask(activityInstanceId, getSession().getUserId()); processAPI.executeFlowNode(activityInstanceId); processAPI.updateProcessDataInstance("application", processInstance.getId(), "Excel"); Assert.assertTrue("no pending user task instances are found", new WaitUntil(50, 3000) { @Override protected boolean check() throws Exception { return processAPI.getPendingHumanTaskInstances( FormExpressionsAPIImplIT.this.getSession().getUserId(), 0, 10, null).size() >= 1; } }.waitUntil()); humanTaskInstance = processAPI .getPendingHumanTaskInstances(getSession().getUserId(), 0, 1, ActivityInstanceCriterion.NAME_ASC) .get(0); activityInstanceId = humanTaskInstance.getId(); processAPI.assignUserTask(activityInstanceId, getSession().getUserId()); processAPI.executeFlowNode(activityInstanceId); Assert.assertTrue("Process instance still not archived", new WaitUntil(50, 3000) { @Override protected boolean check() throws Exception { try { processAPI.getProcessInstance(processInstance.getId()); return false; } catch (final ProcessInstanceNotFoundException e) { return true; } } }.waitUntil()); final List<Expression> dependencies = new ArrayList<Expression>(); dependencies.add(new Expression("application", "application", ExpressionType.TYPE_VARIABLE.name(), String.class.getName(), null, null)); final Expression expression = new Expression(null, "application", ExpressionType.TYPE_READ_ONLY_SCRIPT.name(), String.class.getName(), "GROOVY", dependencies); final ArchivedProcessInstance archivedProcessInstance = processAPI .getArchivedProcessInstances(processInstance.getId(), 0, 1).get(0); final Serializable result = formExpressionsAPI.evaluateInstanceInitialExpression(getSession(), archivedProcessInstance.getId(), expression, Locale.ENGLISH, false); Assert.assertEquals("Word", result.toString()); }
From source file:org.soybeanMilk.web.os.DefaultWebObjectSource.java
/** * ?/*from ww w . j av a2s . c o m*/ * @param key * @param expectType * @return * @throws ObjectSourceException * @date 2012-5-16 */ @SuppressWarnings("unchecked") protected Object getObject(Serializable key, Type expectType) throws ObjectSourceException { if (key == null) throw new ObjectSourceException("[key] must not be null"); Object result = null; String strKey = (key instanceof String ? (String) key : key.toString()); String[] scopedKeys = SbmUtils.splitByFirstAccessor(strKey); if (WebConstants.Scope.PARAM.equalsIgnoreCase(scopedKeys[0])) { result = getParamFilterValue(getRequest().getParameterMap(), (scopedKeys.length > 1 ? scopedKeys[1] : null), expectType); } else if (WebConstants.Scope.REQUEST.equalsIgnoreCase(scopedKeys[0])) { if (scopedKeys.length > 1) result = getRequest().getAttribute(scopedKeys[1]); else result = getRequest(); } else if (WebConstants.Scope.SESSION.equalsIgnoreCase(scopedKeys[0])) { if (scopedKeys.length > 1) result = getRequest().getSession().getAttribute(scopedKeys[1]); else result = getRequest().getSession(); } else if (WebConstants.Scope.APPLICATION.equalsIgnoreCase(scopedKeys[0])) { if (scopedKeys.length > 1) result = getApplication().getAttribute(scopedKeys[1]); else result = getApplication(); } else if (WebConstants.Scope.RESPONSE.equalsIgnoreCase(scopedKeys[0])) { if (scopedKeys.length > 1) throw new ObjectSourceException("key " + SbmUtils.toString(key) + " is illegal, get object from " + HttpServletResponse.class.getSimpleName() + " is not supported"); else result = getResponse(); } else if (WebConstants.Scope.OBJECT_SOURCE.equalsIgnoreCase(scopedKeys[0])) { if (scopedKeys.length > 1) throw new ObjectSourceException("key " + SbmUtils.toString(key) + " is illegal, get object from " + WebObjectSource.class.getSimpleName() + " is not supported"); else result = this; } else { result = getObjectWithScopeUnknownKey(strKey, expectType); } result = convertGotObject(result, expectType); if (log.isDebugEnabled()) log.debug("got object " + SbmUtils.toString(result) + " from " + SbmUtils.toString(this) + " with key " + SbmUtils.toString(strKey)); return result; }
From source file:org.pentaho.platform.repository2.unified.jcr.JcrRepositoryFileUtils.java
public static Node updateFileLocaleProperties(final Session session, final Serializable fileId, String locale, Properties properties) throws RepositoryException { PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session); Node fileNode = session.getNodeByIdentifier(fileId.toString()); String prefix = session.getNamespacePrefix(PentahoJcrConstants.PHO_NS); Assert.hasText(prefix);//from ww w . j ava 2 s . co m Node localesNode = null; if (!fileNode.hasNode(pentahoJcrConstants.getPHO_LOCALES())) { // Auto-create pho:locales node if doesn't exist localesNode = fileNode.addNode(pentahoJcrConstants.getPHO_LOCALES(), pentahoJcrConstants.getPHO_NT_LOCALE()); } else { localesNode = fileNode.getNode(pentahoJcrConstants.getPHO_LOCALES()); } try { Node localeNode = NodeHelper.checkGetNode(localesNode, locale); for (String propertyName : properties.stringPropertyNames()) { localeNode.setProperty(propertyName, properties.getProperty(propertyName)); } } catch (PathNotFoundException pnfe) { // locale doesn't exist, create a new locale node Map<String, Properties> propertiesMap = new HashMap<String, Properties>(); propertiesMap.put(locale, properties); setLocalePropertiesMap(session, pentahoJcrConstants, localesNode, propertiesMap); } return fileNode; }
From source file:org.pentaho.platform.repository2.unified.fs.FileSystemRepositoryFileDao.java
public RepositoryFile createFile(Serializable parentFolderId, RepositoryFile file, IRepositoryFileData data, RepositoryFileAcl acl, String versionMessage) { String fileNameWithPath = RepositoryFilenameUtils.concat(parentFolderId.toString(), file.getName()); FileOutputStream fos = null;/* w w w . j a v a 2s. co m*/ File f = new File(fileNameWithPath); try { f.createNewFile(); fos = new FileOutputStream(f); if (data instanceof SimpleRepositoryFileData) { fos.write(inputStreamToBytes(((SimpleRepositoryFileData) data).getInputStream())); } else if (data instanceof NodeRepositoryFileData) { fos.write(inputStreamToBytes( new ByteArrayInputStream(((NodeRepositoryFileData) data).getNode().toString().getBytes()))); } } catch (FileNotFoundException e) { throw new UnifiedRepositoryException("Error writing file [" + fileNameWithPath + "]", e); } catch (IOException e) { throw new UnifiedRepositoryException("Error writing file [" + fileNameWithPath + "]", e); } finally { IOUtils.closeQuietly(fos); } return internalGetFile(f); }
From source file:org.pentaho.platform.repository2.unified.jcr.JcrRepositoryFileUtils.java
public static void setFileMetadata(final Session session, final Serializable fileId, Map<String, Serializable> metadataMap) throws ItemNotFoundException, RepositoryException { PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session); Node fileNode = session.getNodeByIdentifier(fileId.toString()); String prefix = session.getNamespacePrefix(PentahoJcrConstants.PHO_NS); Assert.hasText(prefix);/* w w w . j a va2 s .com*/ Node metadataNode = fileNode.getNode(pentahoJcrConstants.getPHO_METADATA()); checkoutNearestVersionableNodeIfNecessary(session, pentahoJcrConstants, metadataNode); PropertyIterator propertyIter = metadataNode.getProperties(prefix + ":*"); //$NON-NLS-1$ while (propertyIter.hasNext()) { propertyIter.nextProperty().remove(); } for (String key : metadataMap.keySet()) { setMetadataItemForFile(session, key, metadataMap.get(key), metadataNode); } checkinNearestVersionableNodeIfNecessary(session, pentahoJcrConstants, metadataNode, null); }
From source file:org.pentaho.platform.repository2.unified.jcr.JcrRepositoryFileAclDao.java
/** * {@inheritDoc}/* w ww . ja va 2s . c o m*/ */ @SuppressWarnings("unchecked") public List<RepositoryFileAce> getEffectiveAces(final Serializable id, final boolean forceEntriesInheriting) { return (List<RepositoryFileAce>) jcrTemplate.execute(new JcrCallback() { public Object doInJcr(final Session session) throws RepositoryException, IOException { Node node = session.getNodeByIdentifier(id.toString()); if (node == null) { throw new RepositoryException(Messages.getInstance() .getString("JackrabbitRepositoryFileAclDao.ERROR_0001_NODE_NOT_FOUND", id.toString())); //$NON-NLS-1$ } // consult the parent node's effective policy if force is true and parent is not null if (forceEntriesInheriting && session.getNodeByIdentifier(id.toString()).getParent() != null) { node = node.getParent(); } String absPath = node.getPath(); AccessControlPolicy[] acPolicies = session.getAccessControlManager().getEffectivePolicies(absPath); // logic assumes policies are ordered from leaf to root for (AccessControlPolicy policy : acPolicies) { Assert.isTrue(policy instanceof AccessControlList); AccessControlList acList = ((AccessControlList) policy); if (!isEntriesInheriting(session, absPath, acList)) { List<RepositoryFileAce> aces = new ArrayList<RepositoryFileAce>(); AccessControlEntry[] acEntries = acList.getAccessControlEntries(); List<AccessControlEntry> cleanedAcEntries = JcrRepositoryFileAclUtils .removeAclMetadata(Arrays.asList(acEntries)); for (AccessControlEntry acEntry : cleanedAcEntries) { if (!acEntry.getPrincipal().equals(new SpringSecurityRolePrincipal( JcrTenantUtils.getTenantedRole(tenantAdminAuthorityName)))) { aces.add(toAce(session, acEntry)); } } return aces; } } // none are entriesInheriting=false so root aces are the effective aces AccessControlList acList = (AccessControlList) acPolicies[acPolicies.length - 1]; List<RepositoryFileAce> aces = new ArrayList<RepositoryFileAce>(); AccessControlEntry[] acEntries = acList.getAccessControlEntries(); List<AccessControlEntry> cleanedAcEntries = JcrRepositoryFileAclUtils .removeAclMetadata(Arrays.asList(acEntries)); for (AccessControlEntry acEntry : cleanedAcEntries) { if (!acEntry.getPrincipal().equals(new SpringSecurityRolePrincipal( JcrTenantUtils.getTenantedRole(tenantAdminAuthorityName)))) { aces.add(toAce(session, acEntry)); } } return aces; } }); }