use of org.alfresco.service.cmr.repository.ContentWriter in project acs-community-packaging by Alfresco.
the class EditSearchDialog method saveEditSearchOK.
public String saveEditSearchOK(FacesContext newContext, String newOutcome) {
String outcome = newOutcome;
final SearchContext search = this.navigator.getSearchContext();
if (search != null) {
try {
final FacesContext context = newContext;
RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {
public Object execute() throws Throwable {
// handle Edit e.g. Overwrite of existing search
// detect if was previously selected saved search (e.g.
// NodeRef not null)
NodeRef searchRef = new NodeRef(Repository.getStoreRef(), properties.getSavedSearch());
if (getNodeService().exists(searchRef)) {
Map<QName, Serializable> props = getNodeService().getProperties(searchRef);
props.put(ContentModel.PROP_NAME, properties.getSearchName());
props.put(ContentModel.PROP_DESCRIPTION, properties.getSearchDescription());
getNodeService().setProperties(searchRef, props);
ContentService contentService = Repository.getServiceRegistry(context).getContentService();
ContentWriter writer = contentService.getWriter(searchRef, ContentModel.PROP_CONTENT, true);
// get a writer to our new node ready for XML
// content
writer.setMimetype(MimetypeMap.MIMETYPE_XML);
writer.setEncoding("UTF-8");
// output an XML serialized version of the
// SearchContext object
writer.putContent(search.toXML());
}
return null;
}
};
callback.execute();
properties.getCachedSavedSearches().clear();
properties.setSavedSearch(null);
} catch (Throwable e) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(newContext, MSG_ERROR_SAVE_SEARCH), e.getMessage()), e);
outcome = null;
this.isFinished = false;
ReportedException.throwIfNecessary(e);
}
}
return outcome;
}
use of org.alfresco.service.cmr.repository.ContentWriter in project acs-community-packaging by Alfresco.
the class EditUserDetailsDialog method finishImpl.
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception {
try {
ServiceRegistry services = Repository.getServiceRegistry(FacesContext.getCurrentInstance());
DictionaryService dd = services.getDictionaryService();
Map<QName, Serializable> props = getNodeService().getProperties(getPerson().getNodeRef());
for (String key : getPerson().getProperties().keySet()) {
QName propQName = QName.createQName(key);
if (dd.getProperty(propQName) == null || dd.getProperty(propQName).isProtected() == false) {
props.put(propQName, (Serializable) getPerson().getProperties().get(key));
}
}
// persist all property changes
NodeRef personRef = getPerson().getNodeRef();
this.getNodeService().setProperties(personRef, props);
// save person description content field
if (this.personDescription != null) {
ContentService cs = services.getContentService();
ContentWriter writer = cs.getWriter(personRef, ContentModel.PROP_PERSONDESC, true);
writer.setMimetype(MimetypeMap.MIMETYPE_HTML);
writer.putContent(this.personDescription);
}
// setup user avatar association
if (this.photoRef != null) {
List<AssociationRef> refs = this.getNodeService().getTargetAssocs(personRef, ContentModel.ASSOC_AVATAR);
// remove old association if it exists
if (refs.size() == 1) {
NodeRef existingRef = refs.get(0).getTargetRef();
this.getNodeService().removeAssociation(personRef, existingRef, ContentModel.ASSOC_AVATAR);
}
// setup new association
this.getNodeService().createAssociation(personRef, this.photoRef, ContentModel.ASSOC_AVATAR);
}
// if the above calls were successful, then reset Person Node in the session
Application.getCurrentUser(context).reset();
} catch (Throwable err) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_GENERIC), err.getMessage()), err);
outcome = null;
ReportedException.throwIfNecessary(err);
}
return outcome;
}
use of org.alfresco.service.cmr.repository.ContentWriter in project acs-community-packaging by Alfresco.
the class EditPostDialog method finishImpl.
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception {
// remove link breaks and replace with <br>
this.content = Utils.replaceLineBreaks(this.content, false);
// update the content
NodeRef postNode = this.browseBean.getDocument().getNodeRef();
// check that the name of this post does not contain the :
// character (used in previous versions), if it does rename
// the post.
String name = (String) this.getNodeService().getProperty(postNode, ContentModel.PROP_NAME);
if (name.indexOf(":") != -1) {
String newName = name.replace(':', '-');
this.getFileFolderService().rename(postNode, newName);
}
ContentWriter writer = this.getContentService().getWriter(postNode, ContentModel.PROP_CONTENT, true);
if (writer != null) {
writer.putContent(this.content);
}
return outcome;
}
use of org.alfresco.service.cmr.repository.ContentWriter in project acs-community-packaging by Alfresco.
the class CheckinCheckoutDialog method updateFileOK.
/**
* Action called upon completion of the Update File page
*/
public String updateFileOK(final FacesContext context, String outcome) {
// NOTE: for update the document node _is_ the working document!
final Node node = property.getDocument();
if (node != null && this.getFileName() != null) {
try {
RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(FacesContext.getCurrentInstance());
RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {
public Object execute() throws Throwable {
if (logger.isDebugEnabled())
logger.debug("Trying to update content node Id: " + node.getId());
// get an updating writer that we can use to modify the content on the current node
ContentWriter writer = property.getContentService().getWriter(node.getNodeRef(), ContentModel.PROP_CONTENT, true);
// also update the mime type in case a different type of file is uploaded
String mimeType = Repository.getMimeTypeForFileName(context, property.getFileName());
writer.setMimetype(mimeType);
writer.putContent(property.getFile());
return null;
}
};
txnHelper.doInTransaction(callback);
// clear action context
property.setDocument(null);
resetState();
outcome = AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
} catch (Throwable err) {
Utils.addErrorMessage(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_UPDATE) + err.getMessage(), err);
ReportedException.throwIfNecessary(err);
}
} else {
logger.warn("WARNING: updateFileOK called without a current Document!");
}
return outcome;
}
use of org.alfresco.service.cmr.repository.ContentWriter in project records-management by Alfresco.
the class ApplyFixMob1573Get method writeCustomContentModel.
private void writeCustomContentModel(M2Model deserializedModel) {
ContentWriter writer = contentService.getWriter(RM_CUSTOM_MODEL_NODE_REF, ContentModel.TYPE_CONTENT, true);
writer.setMimetype(MimetypeMap.MIMETYPE_XML);
writer.setEncoding("UTF-8");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
deserializedModel.toXML(baos);
String updatedModelXml;
try {
updatedModelXml = baos.toString("UTF-8");
writer.putContent(updatedModelXml);
// putContent closes all resources.
// so we don't have to.
} catch (UnsupportedEncodingException uex) {
throw new AlfrescoRuntimeException("Exception when writing custom model xml.", uex);
}
}
Aggregations