/*
* ownCloud Android client application
*
* @author masensio
* @author David A. Velasco
* Copyright (C) 2015 ownCloud Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
*/
package com.owncloud.android.operations;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.files.FileUtils;
import com.owncloud.android.lib.resources.shares.CreateShareRemoteOperation;
import com.owncloud.android.lib.resources.shares.GetSharesForFileRemoteOperation;
import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.operations.common.SyncOperation;
import java.util.ArrayList;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* Creates a new public share for a given file
*/
@AllArgsConstructor
@Getter
public class CreateShareViaLinkOperation extends SyncOperation {
private String path;
private String password;
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
// Check if the share link already exists
RemoteOperation operation = new GetSharesForFileRemoteOperation(path, false, false);
RemoteOperationResult result = operation.execute(client);
// Create public link if doesn't exist yet
boolean publicShareExists = false;
if (result.isSuccess()) {
OCShare share;
for (int i=0 ; i 0) {
Object item = result.getData().get(0);
if (item instanceof OCShare) {
updateData((OCShare) item);
} else {
ArrayList