Example usage for org.apache.commons.httpclient HttpStatus SC_NOT_FOUND

List of usage examples for org.apache.commons.httpclient HttpStatus SC_NOT_FOUND

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpStatus SC_NOT_FOUND.

Prototype

int SC_NOT_FOUND

To view the source code for org.apache.commons.httpclient HttpStatus SC_NOT_FOUND.

Click Source Link

Document

<tt>404 Not Found</tt> (HTTP/1.0 - RFC 1945)

Usage

From source file:org.alfresco.bm.dataload.rm.records.ScheduleInPlaceRecordLoaders.java

/**
 * Helper method that iterates the hierarchy tree starting from a folder and caches the file ids
 * If the path doesn't exist nothing happens
 *
 * @param currentNodeId/*  ww  w  . j  ava 2  s  . co m*/
 * @param relativePath
 * @param eventOutputMsg
 * @throws Exception
 */
private void preloadExistingFiles(String currentNodeId, String relativePath, StringBuilder eventOutputMsg)
        throws Exception {
    boolean moreChildren;
    int skipCount = 0;
    do {
        ContentModel currentNodeModel = new ContentModel();
        currentNodeModel.setNodeRef(currentNodeId);
        RestNodeModelsCollection children = restCoreAPI
                .withParams("where=(isPrimary=true)", "relativePath=" + relativePath, "skipCount=" + skipCount)
                .withCoreAPI().usingNode(currentNodeModel).listChildren();
        if (Integer.parseInt(restCoreAPI.getStatusCode()) == HttpStatus.SC_NOT_FOUND) {
            return;
        }

        for (RestNodeModel child : children.getEntries()) {
            if (numberOfFilesLeftToPreload() <= 0) {
                // we have enough files
                return;
            }

            if (child.onModel().getIsFile()) {
                RecordData record = new RecordData(child.onModel().getId(), RecordContext.IN_PLACE_RECORD,
                        child.onModel().getName(), null, null, ExecutionState.SCHEDULED);
                unscheduledFilesCache.add(record);
            } else if (!fullLoadedFolders.contains(child.onModel().getId())) {
                preloadExistingFiles(child.onModel().getId(), "", eventOutputMsg);
            }
        }

        moreChildren = children.getPagination().isHasMoreItems();
        skipCount += children.getPagination().getCount();
    } while (moreChildren);

    // mark the folder as complete to avoid listing its children in a following iteration
    fullLoadedFolders.add(currentNodeId);
}

From source file:org.alfresco.bm.dataload.rm.records.ScheduleInPlaceRecordLoadersUnitTest.java

@Test
public void testDeclareRecordsColabSiteDoesNotExistsAndLoadedInDb() throws Exception {
    String numberOfRecordsToDeclare = "1";
    int maxActiveLoaders = 8;
    String siteId = "testSiteId";
    String documentLibraryId = UUID.randomUUID().toString();
    scheduleInPlaceRecordLoaders.setEnabled(true);
    scheduleInPlaceRecordLoaders.setRecordDeclarationLimit(numberOfRecordsToDeclare);
    scheduleInPlaceRecordLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleInPlaceRecordLoaders.setCollabSiteId(siteId);
    scheduleInPlaceRecordLoaders.setCollabSitePaths(null);

    RestSiteModel mockedRestSiteModel = mock(RestSiteModel.class);
    RestSiteContainerModel mockedRestSiteContainerModel = mock(RestSiteContainerModel.class);
    when(mockedRestSiteContainerModel.getId()).thenReturn(documentLibraryId);

    Site mockedSite = mock(Site.class);
    when(mockedSite.getSite()).thenReturn(null);
    when(mockedSite.createSite()).thenReturn(mockedRestSiteModel);
    when(mockedSite.getSiteContainer("documentLibrary")).thenReturn(mockedRestSiteContainerModel);

    RestCoreAPI mockedRestCoreAPI = mock(RestCoreAPI.class);
    when(mockedRestCoreAPI.usingSite(siteId.toLowerCase())).thenReturn(mockedSite);

    when(mockedRestWrapper.withCoreAPI()).thenReturn(mockedRestCoreAPI);
    when(mockedRestWrapper.getStatusCode()).thenReturn(Integer.toString(HttpStatus.SC_NOT_FOUND));

    SiteData mockedSiteData = mock(SiteData.class);
    when(mockedSiteDataService.getSite(siteId.toLowerCase())).thenReturn(mockedSiteData);

    RestPaginationModel mockedPagination = mock(RestPaginationModel.class);
    when(mockedPagination.isHasMoreItems()).thenReturn(false);
    RestNodeModelsCollection mockedCollection = mock(RestNodeModelsCollection.class);
    when(mockedCollection.getPagination()).thenReturn(mockedPagination);
    Node mockedNode = mock(Node.class);
    when(mockedNode.listChildren()).thenReturn(mockedCollection);
    RestCoreAPI mockedRestCoreAPIWithParams = mock(RestCoreAPI.class);
    when(mockedRestCoreAPIWithParams.usingNode(any(RepoTestModel.class))).thenReturn(mockedNode);
    RestWrapper mockedRestWrapperWithParams = mock(RestWrapper.class);
    when(mockedRestWrapperWithParams.withCoreAPI()).thenReturn(mockedRestCoreAPIWithParams);
    when(mockedRestWrapper.withParams(any(String.class), any(String.class), any(String.class)))
            .thenReturn(mockedRestWrapperWithParams);

    //for creating files
    NodeDetail mockedTargetNodeDetail = mock(NodeDetail.class);
    NodesBuilder mockedNodeBuilder = mock(NodesBuilder.class);
    when(mockedNodeBuilder.folder("AutoGeneratedFiles")).thenReturn(mockedTargetNodeDetail);
    when(mockedNode.defineNodes()).thenReturn(mockedNodeBuilder);
    when(mockedRestCoreAPI.usingNode(any(RepoTestModel.class))).thenReturn(mockedNode);

    NodeDetail mockedFile = mock(NodeDetail.class);
    String fileID = UUID.randomUUID().toString();
    when(mockedFile.getId()).thenReturn(fileID);
    when(mockedFile.getName()).thenReturn("fileName");
    when(mockedTargetNodeDetail.file("recordToBe")).thenReturn(mockedFile);

    EventResult result = scheduleInPlaceRecordLoaders.processEvent(null, new StopWatch());
    verify(mockedSite, times(1)).createSite();
    verify(mockedSiteDataService, never()).addSite(any(SiteData.class));
    assertEquals(true, result.isSuccess());
    String template = "Preparing files to declare: \nCreated file {0}.Sheduled file to be declared as record: {1}. Raised further {2} events and rescheduled self.";
    assertEquals(MessageFormat.format(template, fileID, fileID, 1), result.getData());
    assertEquals(2, result.getNextEvents().size());
    assertEquals(scheduleInPlaceRecordLoaders.getEventNameDeclareInPlaceRecord(),
            result.getNextEvents().get(0).getName());
    assertEquals(scheduleInPlaceRecordLoaders.getEventNameRescheduleSelf(),
            result.getNextEvents().get(1).getName());
}

From source file:org.alfresco.bm.dataload.rm.records.ScheduleInPlaceRecordLoadersUnitTest.java

@Test
public void testDeclareRecordsColabSiteDoesNotExistsNotLoadedInDb() throws Exception {
    String numberOfRecordsToDeclare = "1";
    int maxActiveLoaders = 8;
    String siteId = "testSiteId";
    String documentLibraryId = UUID.randomUUID().toString();
    String siteTitle = "someTitle";
    String guid = UUID.randomUUID().toString();
    String description = "someDescription";
    String preset = "somePreset";
    Visibility visibility = Visibility.PUBLIC;
    scheduleInPlaceRecordLoaders.setEnabled(true);
    scheduleInPlaceRecordLoaders.setRecordDeclarationLimit(numberOfRecordsToDeclare);
    scheduleInPlaceRecordLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleInPlaceRecordLoaders.setCollabSiteId(siteId);
    scheduleInPlaceRecordLoaders.setCollabSitePaths(null);

    RestSiteModel mockedRestSiteModel = mock(RestSiteModel.class);
    when(mockedRestSiteModel.getTitle()).thenReturn(siteTitle);
    when(mockedRestSiteModel.getGuid()).thenReturn(guid);
    when(mockedRestSiteModel.getDescription()).thenReturn(description);
    when(mockedRestSiteModel.getPreset()).thenReturn(preset);
    when(mockedRestSiteModel.getVisibility()).thenReturn(visibility);

    RestSiteContainerModel mockedRestSiteContainerModel = mock(RestSiteContainerModel.class);
    when(mockedRestSiteContainerModel.getId()).thenReturn(documentLibraryId);

    Site mockedSite = mock(Site.class);
    when(mockedSite.getSite()).thenReturn(null);
    when(mockedSite.createSite()).thenReturn(mockedRestSiteModel);
    when(mockedSite.getSiteContainer("documentLibrary")).thenReturn(mockedRestSiteContainerModel);

    RestCoreAPI mockedRestCoreAPI = mock(RestCoreAPI.class);
    when(mockedRestCoreAPI.usingSite(siteId.toLowerCase())).thenReturn(mockedSite);

    when(mockedRestWrapper.withCoreAPI()).thenReturn(mockedRestCoreAPI);
    when(mockedRestWrapper.getStatusCode()).thenReturn(Integer.toString(HttpStatus.SC_NOT_FOUND));

    when(mockedSiteDataService.getSite(siteId.toLowerCase())).thenReturn(null);

    RestPaginationModel mockedPagination = mock(RestPaginationModel.class);
    when(mockedPagination.isHasMoreItems()).thenReturn(false);
    RestNodeModelsCollection mockedCollection = mock(RestNodeModelsCollection.class);
    when(mockedCollection.getPagination()).thenReturn(mockedPagination);
    Node mockedNode = mock(Node.class);
    when(mockedNode.listChildren()).thenReturn(mockedCollection);
    RestCoreAPI mockedRestCoreAPIWithParams = mock(RestCoreAPI.class);
    when(mockedRestCoreAPIWithParams.usingNode(any(RepoTestModel.class))).thenReturn(mockedNode);
    RestWrapper mockedRestWrapperWithParams = mock(RestWrapper.class);
    when(mockedRestWrapperWithParams.withCoreAPI()).thenReturn(mockedRestCoreAPIWithParams);
    when(mockedRestWrapper.withParams(any(String.class), any(String.class), any(String.class)))
            .thenReturn(mockedRestWrapperWithParams);

    //for creating files
    NodeDetail mockedTargetNodeDetail = mock(NodeDetail.class);
    NodesBuilder mockedNodeBuilder = mock(NodesBuilder.class);
    when(mockedNodeBuilder.folder("AutoGeneratedFiles")).thenReturn(mockedTargetNodeDetail);
    when(mockedNode.defineNodes()).thenReturn(mockedNodeBuilder);
    when(mockedRestCoreAPI.usingNode(any(RepoTestModel.class))).thenReturn(mockedNode);

    NodeDetail mockedFile = mock(NodeDetail.class);
    String fileID = UUID.randomUUID().toString();
    when(mockedFile.getId()).thenReturn(fileID);
    when(mockedFile.getName()).thenReturn("fileName");
    when(mockedTargetNodeDetail.file("recordToBe")).thenReturn(mockedFile);

    EventResult result = scheduleInPlaceRecordLoaders.processEvent(null, new StopWatch());
    verify(mockedSite, times(1)).createSite();
    verify(mockedSiteDataService, times(1)).addSite(any(SiteData.class));
    assertEquals(true, result.isSuccess());
    String template = "Preparing files to declare: \n Added site \"{0}\" as created.\nCreated file {1}.Sheduled file to be declared as record: {2}. Raised further {3} events and rescheduled self.";
    assertEquals(MessageFormat.format(template, siteId.toLowerCase(), fileID, fileID, 1), result.getData());
    assertEquals(2, result.getNextEvents().size());
    assertEquals(scheduleInPlaceRecordLoaders.getEventNameDeclareInPlaceRecord(),
            result.getNextEvents().get(0).getName());
    assertEquals(scheduleInPlaceRecordLoaders.getEventNameRescheduleSelf(),
            result.getNextEvents().get(1).getName());
}

From source file:org.alfresco.bm.dataload.rm.records.ScheduleInPlaceRecordLoadersUnitTest.java

@Test
public void testDeclareRecordsNonExistentNodeId() throws Exception {
    String numberOfRecordsToDeclare = "1";
    int maxActiveLoaders = 8;
    String siteId = "testSiteId";
    String documentLibraryId = UUID.randomUUID().toString();
    scheduleInPlaceRecordLoaders.setEnabled(true);
    scheduleInPlaceRecordLoaders.setRecordDeclarationLimit(numberOfRecordsToDeclare);
    scheduleInPlaceRecordLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleInPlaceRecordLoaders.setCollabSiteId(siteId);
    scheduleInPlaceRecordLoaders.setCollabSitePaths(null);

    RestSiteModel mockedRestSiteModel = mock(RestSiteModel.class);
    RestSiteContainerModel mockedRestSiteContainerModel = mock(RestSiteContainerModel.class);
    when(mockedRestSiteContainerModel.getId()).thenReturn(documentLibraryId);

    Site mockedSite = mock(Site.class);
    when(mockedSite.getSite()).thenReturn(mockedRestSiteModel);
    when(mockedSite.getSiteContainer("documentLibrary")).thenReturn(mockedRestSiteContainerModel);

    RestCoreAPI mockedRestCoreAPI = mock(RestCoreAPI.class);
    when(mockedRestCoreAPI.usingSite(siteId.toLowerCase())).thenReturn(mockedSite);

    when(mockedRestWrapper.withCoreAPI()).thenReturn(mockedRestCoreAPI);
    when(mockedRestWrapper.getStatusCode()).thenReturn(Integer.toString(HttpStatus.SC_OK))
            .thenReturn(Integer.toString(HttpStatus.SC_NOT_FOUND));

    SiteData mockedSiteData = mock(SiteData.class);
    when(mockedSiteDataService.getSite(siteId.toLowerCase())).thenReturn(mockedSiteData);

    RestPaginationModel mockedPagination = mock(RestPaginationModel.class);
    when(mockedPagination.isHasMoreItems()).thenReturn(false);
    RestNodeModelsCollection mockedCollection = mock(RestNodeModelsCollection.class);
    when(mockedCollection.getPagination()).thenReturn(mockedPagination);

    Node mockedNode = mock(Node.class);
    when(mockedNode.listChildren()).thenReturn(mockedCollection);
    RestCoreAPI mockedRestCoreAPIWithParams = mock(RestCoreAPI.class);
    when(mockedRestCoreAPIWithParams.usingNode(any(RepoTestModel.class))).thenReturn(mockedNode);
    RestWrapper mockedRestWrapperWithParams = mock(RestWrapper.class);
    when(mockedRestWrapperWithParams.withCoreAPI()).thenReturn(mockedRestCoreAPIWithParams);
    when(mockedRestWrapper.withParams(any(String.class), any(String.class), any(String.class)))
            .thenReturn(mockedRestWrapperWithParams);

    //for creating files
    NodeDetail mockedTargetNodeDetail = mock(NodeDetail.class);
    NodesBuilder mockedNodeBuilder = mock(NodesBuilder.class);
    when(mockedNodeBuilder.folder("AutoGeneratedFiles")).thenReturn(mockedTargetNodeDetail);
    when(mockedNode.defineNodes()).thenReturn(mockedNodeBuilder);
    when(mockedRestCoreAPI.usingNode(any(RepoTestModel.class))).thenReturn(mockedNode);

    NodeDetail mockedFile = mock(NodeDetail.class);
    String fileID = UUID.randomUUID().toString();
    when(mockedFile.getId()).thenReturn(fileID);
    when(mockedFile.getName()).thenReturn("fileName");
    when(mockedTargetNodeDetail.file("recordToBe")).thenReturn(mockedFile);

    EventResult result = scheduleInPlaceRecordLoaders.processEvent(null, new StopWatch());
    verify(mockedSite, never()).createSite();
    verify(mockedSiteDataService, never()).addSite(any(SiteData.class));
    assertEquals(true, result.isSuccess());
    String template = "Preparing files to declare: \nCreated file {0}.Sheduled file to be declared as record: {1}. Raised further {2} events and rescheduled self.";
    assertEquals(MessageFormat.format(template, fileID, fileID, 1), result.getData());
    assertEquals(2, result.getNextEvents().size());
    assertEquals(scheduleInPlaceRecordLoaders.getEventNameDeclareInPlaceRecord(),
            result.getNextEvents().get(0).getName());
    assertEquals(scheduleInPlaceRecordLoaders.getEventNameRescheduleSelf(),
            result.getNextEvents().get(1).getName());
}

From source file:org.alfresco.dataprep.DataListsService.java

@SuppressWarnings("unchecked")
private List<String> getDataListIds(final String userName, final String password, final String siteName,
        final String dataListTitle) {
    List<String> ids = new ArrayList<String>();
    HttpResponse response = getDataLists(userName, password, siteName);
    switch (response.getStatusLine().getStatusCode()) {
    case HttpStatus.SC_OK:
        String strResponse = "";
        Object obj = null;//from w  w  w .  j  a v  a2s.co m
        try {
            strResponse = EntityUtils.toString(response.getEntity());
            JSONParser parser = new JSONParser();
            obj = parser.parse(strResponse);
        } catch (ParseException | IOException e) {
            throw new RuntimeException("Failed to parse the response: " + strResponse);
        }
        JSONObject jsonObject = (JSONObject) obj;
        JSONArray jArray = (JSONArray) jsonObject.get("datalists");
        Iterator<JSONObject> iterator = ((List<JSONObject>) jArray).iterator();
        while (iterator.hasNext()) {
            JSONObject factObj = (JSONObject) iterator.next();
            String theTitle = (String) factObj.get("title");
            if (dataListTitle.toString().equalsIgnoreCase(theTitle)) {
                ids.add((String) factObj.get("nodeRef"));
                ids.add((String) factObj.get("name"));
            }
        }
        return ids;
    case HttpStatus.SC_NOT_FOUND:
        throw new RuntimeException("Invalid site " + siteName);
    case HttpStatus.SC_UNAUTHORIZED:
        throw new RuntimeException("Invalid credentials");
    default:
        logger.error("Unable to find: " + dataListTitle + " " + response.toString());
        break;
    }
    return ids;
}

From source file:org.alfresco.dataprep.SitePagesService.java

/**
 * Remove an event/*from  w  ww.  j a va2 s.co m*/
 * @param userName String user name
 * @param password String user password
 * @param siteName String site name
 * @param what String what
 * @param where String event location
 * @param from Date event start date
 * @param to Date event end date
 * @param timeStart String event start time
 * @param timeEnd String event time finish
 * @param allDay boolean all day event
 * @return boolean true if event is removed
 * @throws RuntimeException if site is not found
 */
public boolean removeEvent(final String userName, final String password, final String siteName,
        final String what, final String where, Date from, Date to, String timeStart, String timeEnd,
        final boolean allDay) {
    if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(password) || StringUtils.isEmpty(siteName)
            || StringUtils.isEmpty(what) || StringUtils.isEmpty(from.toString())
            || StringUtils.isEmpty(to.toString())) {
        throw new IllegalArgumentException("Parameter missing");
    }
    String eventName = getEventName(userName, password, siteName, what, where, from, to, timeStart, timeEnd,
            allDay);
    if (StringUtils.isEmpty(eventName)) {
        throw new RuntimeException("Event not found");
    }
    AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject();
    String reqURL = client.getAlfrescoUrl() + "alfresco/s/calendar/event/" + siteName + "/" + eventName;
    HttpDelete request = new HttpDelete(reqURL);
    HttpResponse response = client.executeRequest(userName, password, request);
    switch (response.getStatusLine().getStatusCode()) {
    case HttpStatus.SC_NO_CONTENT:
        return true;
    case HttpStatus.SC_NOT_FOUND:
        throw new RuntimeException("Invalid site " + siteName);
    default:
        logger.error("Unable to delete event: " + response.toString());
        break;
    }
    return false;
}

From source file:org.alfresco.dataprep.SitePagesService.java

/**
 * Update an event/*from   w w  w  . j  a  va2s . c o  m*/
 * @param userName String user name
 * @param password String user password
 * @param siteName String site name
 * @param eventName String even name to be updated should be returned by {@link #getEventName()}
 * @param newWhat String new what
 * @param newWhere String new event location
 * @param newStartDate Date new event start date
 * @param newEndDate Date new event end date
 * @param newTimeStart String new event start time
 * @param newTimeEnd String new event time finish
 * @param newAllDay boolean new all day event
 * @return boolean true if event is updated
 */
@SuppressWarnings("unchecked")
public boolean updateEvent(final String userName, final String password, final String siteName,
        final String eventName, final String newWhat, final String newWhere, Date newStartDate, Date newEndDate,
        String newTimeStart, String newTimeEnd, final boolean newAllDay) {
    if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(password) || StringUtils.isEmpty(siteName)
            || StringUtils.isEmpty(eventName)) {
        throw new IllegalArgumentException("Parameter missing");
    }
    if (StringUtils.isEmpty(eventName)) {
        throw new RuntimeException("Event not found");
    }
    AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject();
    String reqURL = client.getAlfrescoUrl() + "alfresco/s/calendar/event/" + siteName + "/" + eventName;
    Date currentDate = new Date();
    String pattern = "yyyy-MM-dd'T'Z";
    SimpleDateFormat fulldate = new SimpleDateFormat("EEEE, dd MMMM, yyyy");
    SimpleDateFormat fullFormat = new SimpleDateFormat(pattern);
    DateTimeFormatter dtf = DateTimeFormat.forPattern(pattern);
    String fulldatefrom = "";
    String fulldateto = "";
    String timeStart24 = "";
    String startAt, endAt;
    if (newTimeStart.contains("AM") || newTimeStart.contains("PM")) {
        timeStart24 = convertTo24Hour(newTimeStart);
    } else {
        timeStart24 = newTimeStart;
    }
    String timeEnd24 = "";
    if (newTimeEnd.contains("AM") || newTimeEnd.contains("PM")) {
        timeEnd24 = convertTo24Hour(newTimeEnd);
    } else {
        timeEnd24 = newTimeEnd;
    }

    if (newStartDate == null) {
        // set the current date
        fulldatefrom = fulldate.format(currentDate);
        startAt = fullFormat.format(currentDate);
        DateTime dateTime = dtf.parseDateTime(startAt);
        startAt = dateTime.toString().replaceFirst("00:00", timeStart24);
    } else {
        fulldatefrom = fulldate.format(newStartDate);
        startAt = fullFormat.format(newStartDate);
        DateTime dateTime = dtf.parseDateTime(startAt);
        startAt = dateTime.toString().replaceFirst("00:00", timeStart24);
    }
    if (newEndDate == null) {
        // set the current date
        fulldateto = fulldate.format(currentDate);
        endAt = fullFormat.format(currentDate);
        DateTime dateTime = dtf.parseDateTime(endAt);
        endAt = dateTime.toString().replaceFirst("00:00", timeEnd24);
    } else {
        fulldateto = fulldate.format(newEndDate);
        endAt = fullFormat.format(newEndDate);
        DateTime dateTime = dtf.parseDateTime(endAt);
        endAt = dateTime.toString().replaceFirst("00:00", timeEnd24);
    }
    HttpPut put = new HttpPut(reqURL);
    JSONObject body = new JSONObject();
    body.put("fromdate", fulldatefrom);
    body.put("start", newTimeStart);
    body.put("todate", fulldateto);
    body.put("end", newTimeEnd);
    body.put("site", siteName);
    body.put("page", "calendar");
    body.put("docfolder", "");
    body.put("what", newWhat);
    body.put("where", newWhere);
    body.put("startAt", startAt);
    body.put("endAt", endAt);
    if (newAllDay) {
        body.put("allday", "on");
    }
    HttpResponse response = client.executeRequest(userName, password, body, put);
    switch (response.getStatusLine().getStatusCode()) {
    case HttpStatus.SC_OK:
        return true;
    case HttpStatus.SC_NOT_FOUND:
        throw new RuntimeException("Invalid site " + siteName);
    default:
        logger.error("Unable to update event: " + response.toString());
        break;
    }
    return false;
}

From source file:org.alfresco.dataprep.SitePagesService.java

/**
 * Create a new wiki page/*  w  w w  . ja  v a2 s . c o m*/
 * @param userName String user name
 * @param password String password
 * @param siteName String site name
 * @param wikiTitle String wiki title
 * @param content String wiki content
 * @param tags List of tags
 * @return true if wiki page is created (200 Status)
 * @throws RuntimeException if site not found
 */
@SuppressWarnings("unchecked")
public boolean createWiki(final String userName, final String password, final String siteName, String wikiTitle,
        final String content, final List<String> tags) {
    if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(password) || StringUtils.isEmpty(siteName)
            || StringUtils.isEmpty(wikiTitle)) {
        throw new IllegalArgumentException("Null Parameters: Please correct");
    }
    if (wikiTitle.contains(" ")) {
        wikiTitle = wikiTitle.replace(" ", "%20");
    }
    AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject();
    String url = client.getAlfrescoUrl() + "alfresco/s/slingshot/wiki/page/" + siteName + "/" + wikiTitle;
    HttpPut put = new HttpPut(url);
    JSONObject body = new JSONObject();
    body.put("page", "wiki-page");
    body.put("pageTitle", wikiTitle);
    body.put("pagecontent", content);
    body.put("tags", createTagsArray(tags));
    HttpResponse response = client.executeRequest(userName, password, body, put);
    switch (response.getStatusLine().getStatusCode()) {
    case HttpStatus.SC_OK:
        if (logger.isTraceEnabled()) {
            logger.trace("Wiki page " + wikiTitle + " is created successfuly");
        }
        return true;
    case HttpStatus.SC_NOT_FOUND:
        throw new RuntimeException("Invalid site " + siteName);
    default:
        logger.error("Unable to create wiki page: " + response.toString());
        break;
    }
    return false;
}

From source file:org.alfresco.dataprep.SitePagesService.java

/**
 * Delete wiki page//from   w  w  w .j  a  v  a2s .co  m
 * @param userName String user name
 * @param password String password
 * @param siteName String site name
 * @param wikiTitle String wiki title
 * @return true if wiki is removed (204 Status)
 */
public boolean deleteWikiPage(final String userName, final String password, final String siteName,
        String wikiTitle) {
    if (wikiTitle.contains(" ")) {
        wikiTitle = wikiTitle.replaceAll(" ", "_");
    }
    AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject();
    String url = client.getAlfrescoUrl() + "alfresco/s/slingshot/wiki/page/" + siteName + "/" + wikiTitle;
    HttpDelete delete = new HttpDelete(url);
    HttpResponse response = client.executeRequest(userName, password, delete);
    switch (response.getStatusLine().getStatusCode()) {
    case HttpStatus.SC_NO_CONTENT:
        return true;
    case HttpStatus.SC_NOT_FOUND:
        throw new RuntimeException("Wiki " + wikiTitle + " or site " + siteName + " doesn't exists");
    default:
        logger.error("Unable to delete wiki page: " + response.toString());
        break;
    }
    return false;
}

From source file:org.alfresco.dataprep.SitePagesService.java

/**
 * Update wiki page/*from w w w.j  a v a 2s  . c o  m*/
 * @param userName String user name
 * @param password String password
 * @param siteName String site name
 * @param wikiTitle String wiki title to be updated
 * @param newWikiTitle String new wiki title
 * @param newContent String new wiki content
 * @param newTags new list of tags
 * @return true if wiki is updated (204 Status)
 */
@SuppressWarnings("unchecked")
public boolean updateWikiPage(final String userName, final String password, final String siteName,
        String wikiTitle, String newWikiTitle, final String newContent, final List<String> newTags) {
    if (wikiTitle.contains(" ")) {
        wikiTitle = wikiTitle.replaceAll(" ", "_");
    }
    AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject();
    String url = client.getAlfrescoUrl() + "alfresco/s/slingshot/wiki/page/" + siteName + "/" + wikiTitle;
    //updated content and tags
    HttpPut put = new HttpPut(url);
    JSONObject body = new JSONObject();
    body.put("page", "wiki-page");
    body.put("currentVersion", "1.0");
    body.put("pagecontent", newContent);
    body.put("tags", createTagsArray(newTags));
    HttpResponse response = client.executeRequest(userName, password, body, put);
    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
        throw new RuntimeException("Unable to update content and tags of wiki page.");
    }
    //update title
    HttpPost post = new HttpPost(url);
    body = new JSONObject();
    body.put("page", "wiki-page");
    body.put("name", newWikiTitle);
    response = client.executeRequest(userName, password, body, post);
    switch (response.getStatusLine().getStatusCode()) {
    case HttpStatus.SC_OK:
        return true;
    case HttpStatus.SC_NOT_FOUND:
        throw new RuntimeException("Wiki " + wikiTitle + " or site " + siteName + " doesn't exists");
    default:
        logger.error("Unable to update title of wiki page: " + response.toString());
        break;
    }
    return false;
}