Alfresco using opencmis apache chemistry to create a link to a Folder - alfresco

Hi guys i am doing alfresco using opencmis apache chemistry.
I have done many services such as creating folder,subfolder,uploading,downloading with version updates.
Now i am trying to generate link of folder/document whatever the link is in
dashboard of alfresco.
Somebody is there who can help me to genrate the link using openCmis(java)??
Thanks in advance
public String dowloadingDocument(String docuementID){
Session cmisSession=new CreateSession().getSession();
Document document=(Document) cmisSession.getObject(docuementID);
String link=null;
try {
Method loadLink = AbstractAtomPubService.class.getDeclaredMethod("loadLink",
new Class[] { String.class, String.class, String.class, String.class });
try {
link=(String) loadLink.invoke(cmisSession.getBinding().getObjectService(),cmisSession.getRepositoryInfo().getId(),document.getId(),AtomPubParser.LINK_REL_CONTENT,null);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
}
return link;
}

This snippet gives you a download link for the document:
Document document= (Document)cmisSession.getObject(docuementID);
String link = document.getContentUrl();
This is not same link you'll find the Alfresco dashboard, but it also lets the user download the document. Please note, that depending on the authentication setup the user has to authenticate again before the download starts.

Related

Webscraping Firebase Page with HTMLUnit

I use htmlunit 2.36.0 and try to scrape:
https://delightful.dussmann.com/menu/B%C3%BCropark%20Bredeney/B%C3%BCropark%20Bredeney
Somehow no dynamic content fetch is executed via javascript.
Anyone any ideas how to fix it?
#Test
public void testPDFFetch() throws IOException {
String url = "https://delightful.dussmann.com/menu/B%C3%BCropark%20Bredeney/B%C3%BCropark%20Bredeney";
WebClient client = new WebClient(BrowserVersion.CHROME);
client.getOptions().setJavaScriptEnabled(true);
client.getOptions().setThrowExceptionOnScriptError(true);
client.getOptions().setCssEnabled(true);
client.getOptions().setUseInsecureSSL(true);
client.setAjaxController(new AjaxController() {
#Override
public boolean processSynchron(HtmlPage page, WebRequest request, boolean async) {
return true;
}
});
try {
HtmlPage page = client.getPage(url);
// page.wait(20000);
client.waitForBackgroundJavaScript(10000);
client.waitForBackgroundJavaScriptStartingBefore(10000);
Thread.sleep(10000);
System.out.println(page.asXml());
} catch (Exception e) {
e.printStackTrace();
} finally {
client.close();
}
}
Looks like this page uses javascript modules - this is currently not supported by HtmlUnit (Rhino)

Getting image is not saving to project directory

My folder structure is webapp-->resource--> images.
Here is my code:
public String addProductPost(#ModelAttribute("products") Product product, HttpServletRequest request) {
productDao.addProduct(product);
System.out.println(product);
MultipartFile productImage = product.getProductImage();
String rootDirectory = request.getSession().getServletContext().getRealPath("/");
path = Paths.get(rootDirectory +"webapp/resources/image"+ product.getProductId()+".png");
if (productImage !=null && !productImage.isEmpty()) {
try {
productImage.transferTo(new File(path.toString()));
/*Files.copy(Paths.get(productImage.toString()), path);*/
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Product image saving failed ", e);
}
}
Did you try System.out.println(path); ? If you're not getting any error then the image is getting saved in the said directory but doesn't show up in eclipse project manager. To see the image, navigate to the folder where you have said the image.

Xamarin Forms WinPhone 8.1 Silverlight WNS push notifications

I'm attempting to configure my app to use WNS instead of MPNS (I am using Xamarin Forms and have a Win Phone 8.1 Silverlight project with an Azure Notification hub for the back end), for that I updated my code to use the the mobile service to register the phone for push notifications and changed the Notification Service in the WMAppManifest.xml to WNS. After implementing these changes when I check the phones registration through azure it says its MPNS. Below are some screen captures of my configuration and code snippets of how im registering the app.
WMAppManifest.xml
Package.appxmanifest
NotificationManager Code
public class PushNotificationManager : IPushNotificationManager
{
private PushNotificationChannel channel;
public PushNotificationManager() { }
public static MobileServiceClient MobileService = new MobileServiceClient(Utilities.Constants.ApplicationURL, Utilities.Constants.ApplicationKey);
public async Task RegisterDevice()
{
try
{
channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
channel.PushNotificationReceived += Channel_PushNotificationReceived;
await this.RegisterWinDevice(channel.Uri);
NotificationTask.UnregisterBackgroundTask();
NotificationTask.RegisterBackgroundTask();
}
catch (Exception ex)
{
throw ex;
}
}
protected void Channel_PushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args)
{
try
{
//Create notification
}
catch (Exception ex)
{
throw ex;
}
}
public async Task UnregisterDevice()
{
if(channel != null)
{
channel.Close();
}
await MobileService.GetPush().UnregisterNativeAsync();
}
private async Task RegisterWinDevice(string channelUri)
{
try
{
var tags = new List<string>() { };
User user = LocalStorage.GetUserInfo();
tags.Add(user.Id.ToString());
await MobileService.GetPush().RegisterNativeAsync(channelUri, tags.ToArray());
}
catch (Exception ex)
{
throw ex;
}
}
private void CreateNotification(string title, string message)
{
//Show Toast
}
}
In azure I have set the windows Package SID and client secret. I also have unauthenticated push notifications enabled (Although from my understanding this is for MPNS).
And finally here's a screen capture of how it registers with the following code:
If anyone has any idea how to get it to properly register to WNS I'd greatly appreciate the help. Thanks!
Just an update as to how I resolved my problem in case anyone comes across this. I had to switch my winphone project to a non silverlight application (I'm guessing its not supported with this version). Once I did this everything started working correctly.

How do I resolve an ImageSource IRandomAccessStream seeking not supported error?

I am receiving the following runtime-error when attempting to load an image via ImageSource assignment.
Cannot use the specified Stream as a Windows Runtime IRandomAccessStream because this Stream does not support seeking.
Specifically, I am passing an ImageSource object from one page to another page.
Thus, I am surprised that I am receiving this error.
I have even tried extracting the stream object from the ImageSource object.
However, this does not appear to be supported.
Can anyone provide guidance on how I can resolve this issue?
Same problem i was facing,
Please follow following step.
1.In your xaml page add like this a img tag
Image x:Name="productImage" Source="{Binding SelectedSalesItem.Source}"
2. on any grid call ItemSelected="OnSalesItemSelected" event called bellow method.
Public async void OnSalesItemSelected(object sender, EventArgs args) {
try
{
if (SaleVm.SelectedSalesItem != null)
{
OnImages();//Call point no 3 method "OnImages"
}
}
catch (Exception ex)
{
throw ex;
}
}
3.Create a method in your xaml.cs page.
async void OnImages() {
try
{
if (SaleVm.SelectedSalesItem != null)
{
IFolder rootFolder = FileSystem.Current.LocalStorage;
IFolder imageFolder = await rootFolder.GetFolderAsync("ItemsImg");
IFile imageFile = await imageFolder.GetFileAsync(SaleVm.SelectedSalesItem.ItemCode + ".png");
var stream = await imageFile.OpenAsync(FileAccess.Read);
productImage.Source = ImageSource.FromStream(() => stream);
}
}
catch (Exception ex)
{
throw ex;
}
}
4. Call "OnImages()" method from other class like ViewModel.
and change image at run time.

Sharing SignalR hub with ASP.NET Website and a Web API Mobile Backend

I've set up SignalR Realtime communication for my ASP.NET based website. However, I need to know if it's possible to share the same SignalR Hub with a separate Mobile Backend Project which deals with the same server and database. Basically like accessing the facebook's inbox through web and mobile at the same time?
That would be a ASP.NET Web project and a Mobile Client connected to one hub.
If you want to find SignalR for Android, I suggest the following working link for your to start
SignalR/java-client at GitHub
You can refer to the following sample code (this is from my question on SO about SignalR for Android: SignalR for Android: how can I pass dynamic class to SubscriptionHandler1
public <T> void startSignalR(String transport, String serverUrl, final String userName, final Class<T> tClass) {
Platform.loadPlatformComponent(new AndroidPlatformComponent());
Credentials credentials = new Credentials() {
#Override
public void prepareRequest(Request request) {
request.addHeader(HEADER_KEY_USERNAME, userName);
}
};
mConnection = new HubConnection(serverUrl);
mConnection.setCredentials(credentials);
mHub = mConnection.createHubProxy(SERVER_HUB_CHAT);
if (transport.equals("ServerSentEvents")) {
mTransport = new ServerSentEventsTransport(mConnection.getLogger());
} else if (transport.equals("LongPolling")) {
mTransport = new LongPollingTransport(mConnection.getLogger());
}
mAwaitConnection = mConnection.start(mTransport);
try {
mAwaitConnection.get();
} catch (InterruptedException e) {
e.printStackTrace();
return;
} catch (ExecutionException e) {
e.printStackTrace();
return;
}
mHub.on("broadcastMessage",
new SubscriptionHandler1<Object>() {
#Override
public void run(final Object msg) {
final String finalMsg;
Gson gson = new Gson();
Object object = gson.fromJson(msg.toString(), tClass);
Field[] fields = object.getClass().getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
try {
System.out.println("Value = " + fields[i].get(object));
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
, Object.class);
...
}
Hope this helps!

Resources