From a872890a6db8241b629905bf7d8b3e8c5157111b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20S=C3=B8by?= Date: Mon, 21 Mar 2022 13:05:45 +0100 Subject: [PATCH 01/18] Performed a cleanup of documentation. --- .../access/AccessComponentFactory.java | 83 +++++++++---------- .../bitrepository/commandline/PutFileCmd.java | 68 +++++++-------- 2 files changed, 71 insertions(+), 80 deletions(-) diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/AccessComponentFactory.java b/bitrepository-client/src/main/java/org/bitrepository/access/AccessComponentFactory.java index 51570f4cb..98e35d8f1 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/AccessComponentFactory.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/AccessComponentFactory.java @@ -8,16 +8,16 @@ * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -34,101 +34,96 @@ import org.bitrepository.access.getfileids.GetFileIDsClient; import org.bitrepository.access.getstatus.ConversationBasedGetStatusClient; import org.bitrepository.access.getstatus.GetStatusClient; +import org.bitrepository.client.conversation.mediator.ConversationMediatorManager; import org.bitrepository.common.settings.Settings; import org.bitrepository.protocol.ProtocolComponentFactory; -import org.bitrepository.client.conversation.mediator.ConversationMediatorManager; import org.bitrepository.protocol.security.SecurityManager; -/** - * Factory class for the access module. - * Instantiates the instances of the interfaces within this module. - */ public final class AccessComponentFactory { - /** The singleton instance. */ private static AccessComponentFactory instance; - + /** - * Instantiation of this singleton. + * Instantiation of the class as a singleton. * * @return The singleton instance of this factory class. */ public static synchronized AccessComponentFactory getInstance() { - // ensure singleton. - if(instance == null) { + if (instance == null) { instance = new AccessComponentFactory(); } return instance; } - /** - * Private constructor for initialization of the singleton. - */ private AccessComponentFactory() { } /** * Method for getting a GetFileClient as defined in the access configuration.

* - * @param settings The settings for the GetFileClient. + * @param settings The settings for the GetFileClient. * @param securityManager The SecurityManager for the client - * @param clientID The ID of the client - * @return A GetFileClient. + * @param clientID The ID of the client + * @return A GetFileClient created form the given arguments. */ public GetFileClient createGetFileClient(Settings settings, SecurityManager securityManager, String clientID) { return new ConversationBasedGetFileClient( - ProtocolComponentFactory.getInstance().getMessageBus(settings, securityManager), - ConversationMediatorManager.getConversationMediator(settings, securityManager), + ProtocolComponentFactory.getInstance().getMessageBus(settings, securityManager), + ConversationMediatorManager.getConversationMediator(settings, securityManager), settings, clientID); } - + /** - * Method for instantiating a GetChecksumsClient as defined in the access configurations. - * @param settings The settings for the GetChecksumsClient. + * Returns a GetChecksumsClient as defined in the access configurations. + * + * @param settings The settings for the GetChecksumsClient. * @param securityManager The SecurityManager for the client - * @param clientID The ID of the client - * @return The GetChecksumsClient + * @param clientID The ID of the client + * @return The GetChecksumsClient created from the given arguments. */ public GetChecksumsClient createGetChecksumsClient(Settings settings, SecurityManager securityManager, String clientID) { return new ConversationBasedGetChecksumsClient( - ProtocolComponentFactory.getInstance().getMessageBus(settings, securityManager), + ProtocolComponentFactory.getInstance().getMessageBus(settings, securityManager), ConversationMediatorManager.getConversationMediator(settings, securityManager), settings, clientID); } /** - * Method for getting a GetFileIDsClient as defined in the access configuration.

- * @param settings The settings for the GetFileIDsClient. + * Instantiates a GetFileIDsClient as defined in the access configuration.

+ * + * @param settings The settings for the GetFileIDsClient. * @param securityManager The SecurityManager for the client - * @param clientID The ID of the client - * @return A GetFileIDsClient. + * @param clientID The ID of the client + * @return A GetFileIDsClient created from the given arguments. */ public GetFileIDsClient createGetFileIDsClient(Settings settings, SecurityManager securityManager, String clientID) { return new ConversationBasedGetFileIDsClient( - ProtocolComponentFactory.getInstance().getMessageBus(settings, securityManager), + ProtocolComponentFactory.getInstance().getMessageBus(settings, securityManager), ConversationMediatorManager.getConversationMediator(settings, securityManager), settings, clientID); } - + /** - * Method for getting a GetStatusClient as defined in the access configuration.

- * @param settings The settings for the GetStatusClient. + * Instantiates a GetStatusClient as defined in the access configuration.

+ * + * @param settings The settings for the GetStatusClient. * @param securityManager The SecurityManager for the client - * @param clientID The ID of the client - * @return A GetStatusClient. + * @param clientID The ID of the client + * @return A GetStatusClient created from the given arguments. */ public GetStatusClient createGetStatusClient(Settings settings, SecurityManager securityManager, String clientID) { return new ConversationBasedGetStatusClient( - ProtocolComponentFactory.getInstance().getMessageBus(settings, securityManager), + ProtocolComponentFactory.getInstance().getMessageBus(settings, securityManager), ConversationMediatorManager.getConversationMediator(settings, securityManager), settings, clientID); } /** - * Method for getting a AuditTrailClient as defined in the access configuration.

- * @param settings The settings for the AuditTrailClient. + * Instantiates a AuditTrailClient as defined in the access configuration.

+ * + * @param settings The settings for the AuditTrailClient. * @param securityManager The SecurityManager for the client - * @param clientID The ID of the client - * @return A AuditTrailClient. + * @param clientID The ID of the client + * @return A AuditTrailClient created from the given arguments. */ public AuditTrailClient createAuditTrailClient(Settings settings, SecurityManager securityManager, String clientID) { return new ConversationBasedAuditTrailClient( diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/PutFileCmd.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/PutFileCmd.java index 19939bc9d..614879188 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/PutFileCmd.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/PutFileCmd.java @@ -33,14 +33,9 @@ import java.net.URL; -/** - * Putting a file to the collection. - */ -public class PutFileCmd extends CommandLineClient { +import static org.bitrepository.commandline.Constants.ARGUMENT_IS_NOT_REQUIRED; - /** - * The client for performing the PutFile operation. - */ +public class PutFileCmd extends CommandLineClient { private final PutFileClient client; /** @@ -59,14 +54,14 @@ public static void main(String[] args) { } /** - * @param args The arguments: - * k = Location of file with private security key. - * s = Location of folder with setting files. - * c = ID of the Collection - * f = The actual file to put (Either this or the URL). - * u = The URL for the file (Either this or the actual file, though this requires both file id and checksum). - * i = The id of the file to put. - * C = The checksum of the file. + * @param args Valid arguments are:

+ * k = Location of file with private security key.
+ * s = Location of folder with setting files.
+ * c = ID of the Collection.
+ * f = The actual file to put (Either this or the URL).
+ * u = The URL for the file (Either this or the actual file, though this requires both file id and checksum).
+ * i = The id of the file to put.
+ * C = The checksum of the file.
*/ protected PutFileCmd(String... args) { super(args); @@ -79,7 +74,7 @@ protected boolean isFileIDArgumentRequired() { } /** - * Perform the PutFile operation. + * Performs the PutFile operation. */ @Override public void performOperation() { @@ -98,38 +93,38 @@ protected void createOptionsForCmdArgumentHandler() { super.createOptionsForCmdArgumentHandler(); Option fileOption = new Option(Constants.FILE_ARG, Constants.HAS_ARGUMENT, - "The path to the file, which needs to be uploaded. Is required, unless a URL is given."); - fileOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); + "The path to the file to be uploaded. Is required, unless a URL is given."); + fileOption.setRequired(ARGUMENT_IS_NOT_REQUIRED); cmdHandler.addOption(fileOption); Option urlOption = new Option(Constants.URL_ARG, Constants.HAS_ARGUMENT, - "The URL for the file to be put. Is required, unless the actual file is given."); - urlOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); + "The URL for the file to be uploaded. Is required, unless a local file is given."); + urlOption.setRequired(ARGUMENT_IS_NOT_REQUIRED); cmdHandler.addOption(urlOption); Option checksumOption = new Option(Constants.CHECKSUM_ARG, Constants.HAS_ARGUMENT, - "The checksum for the file to be retrieved. Required if using an URL."); - checksumOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); + "The checksum for the file to be retrieved. Is required if using a URL."); + checksumOption.setRequired(ARGUMENT_IS_NOT_REQUIRED); cmdHandler.addOption(checksumOption); Option checksumTypeOption = new Option(Constants.REQUEST_CHECKSUM_TYPE_ARG, Constants.HAS_ARGUMENT, - "[OPTIONAL] The algorithm of checksum to request in the response from the pillars."); - checksumTypeOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); + "[OPTIONAL] Used to request a specific checksum algorithm in the response from the pillars."); + checksumTypeOption.setRequired(ARGUMENT_IS_NOT_REQUIRED); cmdHandler.addOption(checksumTypeOption); Option checksumSaltOption = new Option(Constants.REQUEST_CHECKSUM_SALT_ARG, Constants.HAS_ARGUMENT, - "[OPTIONAL] The salt of checksum to request in the response. Requires the ChecksumType argument."); - checksumSaltOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); + "[OPTIONAL] Used to request a salted checksum in the response. Requires the ChecksumType argument."); + checksumSaltOption.setRequired(ARGUMENT_IS_NOT_REQUIRED); cmdHandler.addOption(checksumSaltOption); Option deleteOption = new Option(Constants.DELETE_FILE_ARG, Constants.NO_ARGUMENT, - "If this argument is present, then the file will be removed from the server, " + "when the operation is complete."); - deleteOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); + "If this argument is present, then the file will be removed from the server, when the chosen operation is complete."); + deleteOption.setRequired(ARGUMENT_IS_NOT_REQUIRED); cmdHandler.addOption(deleteOption); } /** - * Run the default validation, and validates that only file or URL is given. - * Also, if it is an URL is given, then it must also be given the checksum and the file id. + * Run the default validation, and validates that either only file or URL is given. + * Also, if it is a URL that is given, then it must also be given the checksum and the file id. */ @Override protected void validateArguments() { @@ -145,7 +140,7 @@ protected void validateArguments() { throw new IllegalArgumentException("The URL argument requires also the checksum argument (-c)."); } if (cmdHandler.hasOption(Constants.URL_ARG) && !cmdHandler.hasOption(Constants.FILE_ID_ARG)) { - throw new IllegalArgumentException("The URL argument requires also the argument for the ID of the " + "file (-i)."); + throw new IllegalArgumentException("The URL argument requires also the argument for the ID of the file (-i)."); } } @@ -179,11 +174,12 @@ private OperationEvent putTheFile() { /** - * Retrieves the Checksum for the pillars to validate, either taken from the actual file, - * or from the checksum argument. - * It will be in the default checksum spec type from settings. + * Retrieves the Checksum of the file, used by the pillars to validate. + * This checksum is either taken from the actual file, or from the checksum argument. + *

+ * The checksum will be of the default checksum spec-type, which is defined in the settings. * - * @return The checksum validation type. + * @return The spec-type of the checksum as {@link ChecksumDataForFileTYPE}. */ protected ChecksumDataForFileTYPE getValidationChecksum() { if (cmdHandler.hasOption(Constants.FILE_ARG)) { @@ -194,7 +190,7 @@ protected ChecksumDataForFileTYPE getValidationChecksum() { } /** - * @return The filename for the file to upload. + * @return The filename (FileID) for the file to upload. */ private String getFileIDForMessage() { if (cmdHandler.hasOption(Constants.URL_ARG)) { From 077b7644bc7b63ff87c6bd5e3eb8838d1c47c68c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20S=C3=B8by?= Date: Mon, 21 Mar 2022 13:59:46 +0100 Subject: [PATCH 02/18] More code cleanup. --- .../getaudittrails/AuditTrailClient.java | 30 ++++----- .../getaudittrails/AuditTrailQuery.java | 37 +++++------ .../BlockingAuditTrailClient.java | 7 +-- .../ConversationBasedAuditTrailClient.java | 56 ++++++++--------- .../client/AuditTrailConversationContext.java | 44 ++++++------- .../client/AuditTrailIdentificator.java | 41 ------------ .../client/AuditTrailResult.java | 37 ++++++----- .../client/GettingAuditTrails.java | 44 +++++++------ .../IdentifyingAuditTrailContributors.java | 12 ++-- .../BlockingGetChecksumsClient.java | 48 +++++++------- .../ConversationBasedGetChecksumsClient.java | 33 +++++----- .../getchecksums/GetChecksumsClient.java | 41 ++++++------ .../ChecksumsCompletePillarEvent.java | 44 ++++++------- .../GetChecksumsConversationContext.java | 37 +++++------ .../conversation/GettingChecksums.java | 53 ++++++++-------- .../getfileids/BlockingGetFileIDsClient.java | 7 +-- .../conversation/GettingFileIDs.java | 54 ++++++++-------- .../conversation/ConversationContext.java | 63 ++++++++----------- .../PerformingOperationState.java | 45 +++++++------ .../commandline/ReplaceFileCmd.java | 60 +++++++++--------- 20 files changed, 371 insertions(+), 422 deletions(-) delete mode 100644 bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/client/AuditTrailIdentificator.java diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/AuditTrailClient.java b/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/AuditTrailClient.java index 32cb3b3e0..3814a7b8d 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/AuditTrailClient.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/AuditTrailClient.java @@ -1,23 +1,23 @@ /* * #%L * Bitrepository Access - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -29,15 +29,15 @@ public interface AuditTrailClient extends BitrepositoryClient { /** - * @param collectionID The collection to request audit trails for. - * @param componentQueries Defines which components to retrieve audit trail from. Also defines a filter which - * can be used to limit the audit trail result from each pillar. If null all audit trails - * from all contributers are returned. - * @param fileID The optional fileID to retrieve audit trails for. If null audit trail are retrieved for - * all files. - * @param urlForResult If defined, the result is upload to this url (with a -componentID postfix) in stead of being - * returned in a completeEvent. - * @param eventHandler The handler which should receive notifications of the progress events. + * @param collectionID The collection to request auditTrails for. + * @param componentQueries Defines which components to retrieve auditTrail from. Also defines a filter which + * can be used to limit the auditTrail result from each pillar. If null all auditTrails + * from all contributors are returned. + * @param fileID The optional fileID to retrieve audit trails for. If null auditTrails are retrieved for + * all files. + * @param urlForResult If defined, the result is upload to the defined url (with a -componentID postfix) instead of being + * returned in a completeEvent. + * @param eventHandler The handler which should receive notifications of the progress events. * @param auditTrailInformation The audit information for the given operation. E.g. who is behind the operation call. */ void getAuditTrails( diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/AuditTrailQuery.java b/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/AuditTrailQuery.java index 2c01a4c55..ee1a3186a 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/AuditTrailQuery.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/AuditTrailQuery.java @@ -1,23 +1,23 @@ /* * #%L * Bitrepository Access - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -35,34 +35,35 @@ public class AuditTrailQuery extends ContributorQuery { /** * Queries for all Audit Trails with sequence number between minSequenceNumber and maxSequenceNumber. - * @param componentID The ID of the component to query. - * @param minSequenceNumber Only return audit trail event with sequence number higher than minSequenceNumber. - * @param maxSequenceNumber Only return audit trail event with sequence number lower than maxSequenceNumber. + * + * @param componentID The ID of the component to query. + * @param minSequenceNumber Only return audit trail event with sequence number higher than minSequenceNumber. + * @param maxSequenceNumber Only return audit trail event with sequence number lower than maxSequenceNumber. * @param maxNumberOfResults If set will limit the number of results returned. If the result set is limited, only - * the lowest sequence numbers are returned + * the lowest sequence numbers are returned */ public AuditTrailQuery(String componentID, Long minSequenceNumber, Long maxSequenceNumber, Integer maxNumberOfResults) { - super(componentID, null, null, maxNumberOfResults ); + super(componentID, null, null, maxNumberOfResults); if (minSequenceNumber != null && maxSequenceNumber != null && minSequenceNumber > maxSequenceNumber) throw new IllegalArgumentException( - "minSequenceNumber=" + minSequenceNumber + " can not be greater than " + - "maxSequenceNumber=" + maxSequenceNumber); + "minSequenceNumber=" + minSequenceNumber + " can not be greater than " + + "maxSequenceNumber=" + maxSequenceNumber); this.minSequenceNumber = minSequenceNumber; this.maxSequenceNumber = maxSequenceNumber; } /** - * @see AuditTrailQuery#AuditTrailQuery(String, Long, Long, Integer) * @return the minimum sequence number + * @see AuditTrailQuery#AuditTrailQuery(String, Long, Long, Integer) */ public Long getMinSequenceNumber() { return minSequenceNumber; } /** - * @see AuditTrailQuery#AuditTrailQuery(String, Long, Long, Integer) * @return the maximum sequence number + * @see AuditTrailQuery#AuditTrailQuery(String, Long, Long, Integer) */ public Long getMaxSequenceNumber() { return maxSequenceNumber; @@ -71,8 +72,8 @@ public Long getMaxSequenceNumber() { @Override public String toString() { return super.toString() + - "minSequenceNumber=" + minSequenceNumber + - ", maxSequenceNumber=" + maxSequenceNumber + - '}'; + "minSequenceNumber=" + minSequenceNumber + + ", maxSequenceNumber=" + maxSequenceNumber + + '}'; } } diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/BlockingAuditTrailClient.java b/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/BlockingAuditTrailClient.java index fd5d411bb..b82064f8c 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/BlockingAuditTrailClient.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/BlockingAuditTrailClient.java @@ -58,11 +58,6 @@ public List getAuditTrails(String collectionID, AuditTrailQuer throws NegativeResponseException { BlockingEventHandler blocker = new BlockingEventHandler(eventHandler); client.getAuditTrails(collectionID, componentQueries, fileID, urlForResult, blocker, auditTrailInformation); - OperationEvent finishEvent = blocker.awaitFinished(); - if(finishEvent.getEventType().equals(OperationEvent.OperationEventType.COMPLETE)) { - return blocker.getResults(); - } else if (finishEvent.getEventType().equals(OperationEvent.OperationEventType.FAILED)) { - throw new NegativeResponseException(finishEvent.getInfo(), null); - } else throw new RuntimeException("Received unexpected event type" + finishEvent); + return getContributorEvents(blocker); } } diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/ConversationBasedAuditTrailClient.java b/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/ConversationBasedAuditTrailClient.java index 53a319eae..8db2e806f 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/ConversationBasedAuditTrailClient.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/ConversationBasedAuditTrailClient.java @@ -1,33 +1,29 @@ /* * #%L * Bitrepository Access - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.access.getaudittrails; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - import org.bitrepository.access.ContributorQueryUtils; import org.bitrepository.access.getaudittrails.client.AuditTrailConversationContext; import org.bitrepository.access.getaudittrails.client.IdentifyingAuditTrailContributors; @@ -39,53 +35,53 @@ import org.bitrepository.common.utils.SettingsUtils; import org.bitrepository.protocol.messagebus.MessageBus; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + /** * The conversation based implementation of the {@link AuditTrailClient}. */ public class ConversationBasedAuditTrailClient extends AbstractClient implements AuditTrailClient { - public ConversationBasedAuditTrailClient(Settings settings, ConversationMediator conversationMediator, - MessageBus messageBus, String clientID) { + public ConversationBasedAuditTrailClient(Settings settings, ConversationMediator conversationMediator, MessageBus messageBus, + String clientID) { super(settings, conversationMediator, messageBus, clientID); } @Override - public void getAuditTrails( - String collectionID, - AuditTrailQuery[] componentQueries, - String fileID, - String urlForResult, - EventHandler eventHandler, String auditTrailInformation) { + public void getAuditTrails(String collectionID, AuditTrailQuery[] componentQueries, String fileID, String urlForResult, + EventHandler eventHandler, String auditTrailInformation) { ArgumentValidator.checkNotNullOrEmpty(collectionID, "collectionID"); validateFileID(fileID); if (componentQueries == null) { componentQueries = createFullAuditTrailQuery(collectionID); } - AuditTrailConversationContext context = new AuditTrailConversationContext( - collectionID, componentQueries, fileID, urlForResult, + AuditTrailConversationContext context = new AuditTrailConversationContext(collectionID, componentQueries, fileID, urlForResult, settings, messageBus, clientID, ContributorQueryUtils.getContributors(componentQueries), eventHandler, - auditTrailInformation); + auditTrailInformation); startConversation(context, new IdentifyingAuditTrailContributors(context)); } /** - * Used to create a AuditTrailQuery[] array in case no array is defined. - * @param collectionID the collection ID - * @return A AuditTrailQuery[] array requesting all audit trails from all the defined contributers. + * Used to create an {@link AuditTrailQuery AuditTrailQuery[]} in case none is defined. + * + * @param collectionID The ID of the collection. + * @return An {@link AuditTrailQuery AuditTrailQuery[]} containing auditTrails from all the defined contributors. */ private AuditTrailQuery[] createFullAuditTrailQuery(String collectionID) { if (settings.getRepositorySettings().getGetAuditTrailSettings() == null) { throw new IllegalStateException("Unable getAuditTrails both undefined GetAuditTrailSettings and undefined " + "AuditTrailQuery[] in getAuditTrails call"); } else if (SettingsUtils.getAuditContributorsForCollection(collectionID).isEmpty()) { - throw new IllegalStateException("Running AuditTrailClient without any defined contributers and undefined " + + throw new IllegalStateException("Running AuditTrailClient without any defined contributors and undefined " + "AuditTrailQuery[] in getAuditTrails call."); } - Collection contributers = SettingsUtils.getAuditContributorsForCollection(collectionID); - List componentQueryList = new ArrayList<>(contributers.size()); - for (String contributer : contributers) { - componentQueryList.add(new AuditTrailQuery(contributer, null, null, null)); + Collection contributors = SettingsUtils.getAuditContributorsForCollection(collectionID); + List componentQueryList = new ArrayList<>(contributors.size()); + for (String contributor : contributors) { + componentQueryList.add(new AuditTrailQuery(contributor, null, null, null)); } - return componentQueryList.toArray(new AuditTrailQuery[componentQueryList.size()]); + return componentQueryList.toArray(new AuditTrailQuery[0]); } } diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/client/AuditTrailConversationContext.java b/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/client/AuditTrailConversationContext.java index 4d889ef27..8e2699a51 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/client/AuditTrailConversationContext.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/client/AuditTrailConversationContext.java @@ -5,24 +5,22 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.access.getaudittrails.client; -import java.util.Collection; - import org.bitrepository.access.getaudittrails.AuditTrailQuery; import org.bitrepository.client.conversation.ConversationContext; import org.bitrepository.client.eventhandler.EventHandler; @@ -30,6 +28,8 @@ import org.bitrepository.protocol.OperationType; import org.bitrepository.protocol.messagebus.MessageSender; +import java.util.Collection; + /** * models the conversation context for the {@link org.bitrepository.access.getaudittrails.AuditTrailClient} */ @@ -38,21 +38,23 @@ public class AuditTrailConversationContext extends ConversationContext { private final String urlForResult; /** - * Extends the {@link ConversationContext} constructor with {@link org.bitrepository.access.getaudittrails.AuditTrailClient} specific parameters - * @param collectionID The ID of the collection - * @param componentQueries The queries for the components - * @param fileID The fileID - * @param urlForResult The address to deliver results if delivery is requested by url - * @param settings The settings - * @param messageSender The MessageSender to send messages with - * @param clientID The ID of the client - * @param contributors The contributors in the conversation - * @param eventHandler The EventHandler handling incoming events - * @param auditTrailInformation Audit trail information for the components + * Extends the {@link ConversationContext} constructor with {@link org.bitrepository.access.getaudittrails.AuditTrailClient} specific + * parameters + * + * @param collectionID The ID of the collection + * @param componentQueries The queries for the components + * @param fileID The fileID (usually file name) + * @param urlForResult The address to deliver results if delivery is requested by url + * @param settings The settings + * @param messageSender The MessageSender to send messages with + * @param clientID The ID of the client + * @param contributors The contributors in the conversation + * @param eventHandler The EventHandler handling incoming events + * @param auditTrailInformation Audit trail information for the components */ public AuditTrailConversationContext( String collectionID, AuditTrailQuery[] componentQueries, String fileID, String urlForResult, - Settings settings, MessageSender messageSender, String clientID, Collection contributors, + Settings settings, MessageSender messageSender, String clientID, Collection contributors, EventHandler eventHandler, String auditTrailInformation) { super(collectionID, OperationType.GET_AUDIT_TRAILS, settings, messageSender, clientID, fileID, contributors, eventHandler, auditTrailInformation); @@ -61,14 +63,14 @@ public AuditTrailConversationContext( } /** - * @return The component queries + * @return The component queries */ public AuditTrailQuery[] getComponentQueries() { return componentQueries; } /** - * @return The URL for delivery of results + * @return The URL for delivery of results */ public String getUrlForResult() { return urlForResult; diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/client/AuditTrailIdentificator.java b/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/client/AuditTrailIdentificator.java deleted file mode 100644 index e1abf543a..000000000 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/client/AuditTrailIdentificator.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * #%L - * Bitrepository Access - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * #L% - */ -package org.bitrepository.access.getaudittrails.client; - -import org.bitrepository.client.BitrepositoryClient; -import org.bitrepository.client.eventhandler.EventHandler; - -/** - * Provides functionality for retrieving the list of available audit trail contributors at a given time. - */ -public interface AuditTrailIdentificator extends BitrepositoryClient { - /** - * Returns the contributors currently available. A identify contributors request is used to lookup the contributors - * each time this method is called. - * @param eventHandler The EventHandler to handle incoming events - * @param auditTrailInformation The audittrail information to the components - */ - void getAvailableContributors(EventHandler eventHandler, String auditTrailInformation); -} diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/client/AuditTrailResult.java b/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/client/AuditTrailResult.java index 1c2a595b0..0e92af0be 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/client/AuditTrailResult.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/client/AuditTrailResult.java @@ -5,16 +5,16 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -25,37 +25,37 @@ import org.bitrepository.client.eventhandler.ContributorCompleteEvent; /** - * Returns the result of a Audit Trail final response for a single contributor. + * Returns the result of an Audit Trail final response for a single contributor. */ public class AuditTrailResult extends ContributorCompleteEvent { private final ResultingAuditTrails auditTrailEvents; private final boolean isPartialResult; /** - * @param pillarID The Id of the pillar suppying the audit trails. - * @param collectionID The ID of the collection + * @param pillarID The ID of the pillar supplying the audit trails. + * @param collectionID The ID of the collection * @param auditTrailEvents The list of audit trail events - * @param isPartialResult true if the result return encountered a maxResultLimit and therefore - * only returned a subset of results is returned. See {@link org.bitrepository.access.ContributorQuery} for - * details. + * @param isPartialResult true if the result return encountered a maxResultLimit and therefore + * only returned a subset of results is returned. See {@link org.bitrepository.access.ContributorQuery} for + * details. */ - public AuditTrailResult(String pillarID, String collectionID, ResultingAuditTrails auditTrailEvents, - boolean isPartialResult) { + public AuditTrailResult(String pillarID, String collectionID, ResultingAuditTrails auditTrailEvents, + boolean isPartialResult) { super(pillarID, collectionID); this.auditTrailEvents = auditTrailEvents; this.isPartialResult = isPartialResult; } /** - * @return The audit trails returned from the component. + * @return The auditTrails returned from the component. */ public ResultingAuditTrails getAuditTrailEvents() { return auditTrailEvents; } /** + * @return An indication of the results being partial or not. * @see #AuditTrailResult(String, String, org.bitrepository.bitrepositoryelements.ResultingAuditTrails, boolean) - * @return indication if the results are partial */ public boolean isPartialResult() { return isPartialResult; @@ -64,12 +64,11 @@ public boolean isPartialResult() { @Override public String additionalInfo() { StringBuilder infoSB = new StringBuilder(super.additionalInfo()); - if (auditTrailEvents != null && auditTrailEvents.getAuditTrailEvents() != null + if (auditTrailEvents != null && auditTrailEvents.getAuditTrailEvents() != null && auditTrailEvents.getAuditTrailEvents().getAuditTrailEvent() != null) { - infoSB.append(", NumberOfAuditTrailEvents=" + - auditTrailEvents.getAuditTrailEvents().getAuditTrailEvent().size()); + infoSB.append(", NumberOfAuditTrailEvents=").append(auditTrailEvents.getAuditTrailEvents().getAuditTrailEvent().size()); } - infoSB.append(", PartialResult=" + isPartialResult); + infoSB.append(", PartialResult=").append(isPartialResult); return infoSB.toString(); } } diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/client/GettingAuditTrails.java b/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/client/GettingAuditTrails.java index ec7629196..84773da1d 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/client/GettingAuditTrails.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/client/GettingAuditTrails.java @@ -5,25 +5,22 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.access.getaudittrails.client; -import java.math.BigInteger; -import java.util.Collection; - import org.bitrepository.access.getaudittrails.AuditTrailQuery; import org.bitrepository.bitrepositorymessages.GetAuditTrailsFinalResponse; import org.bitrepository.bitrepositorymessages.GetAuditTrailsRequest; @@ -31,13 +28,15 @@ import org.bitrepository.client.conversation.ConversationContext; import org.bitrepository.client.conversation.PerformingOperationState; import org.bitrepository.client.conversation.selector.SelectedComponentInfo; -import org.bitrepository.client.exceptions.UnexpectedResponseException; + +import java.math.BigInteger; +import java.util.Collection; public class GettingAuditTrails extends PerformingOperationState { private final AuditTrailConversationContext context; - /* - * @param context The conversation context. + /** + * @param context The conversation context. * @param contributors The list of components the audit trails should be collected from. */ public GettingAuditTrails(AuditTrailConversationContext context, Collection contributors) { @@ -45,10 +44,13 @@ public GettingAuditTrails(AuditTrailConversationContext context, Collection. * #L% @@ -40,7 +40,7 @@ protected void sendRequest() { initializeMessage(msg); msg.setDestination(context.getSettings().getCollectionDestination()); context.getMessageSender().sendMessage(msg); - context.getMonitor().identifyRequestSent("Identifying contributers for audit trails"); + context.getMonitor().identifyRequestSent("Identifying contributors for audit trails"); } @Override diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/BlockingGetChecksumsClient.java b/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/BlockingGetChecksumsClient.java index cb1e04905..417d8cf2b 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/BlockingGetChecksumsClient.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/BlockingGetChecksumsClient.java @@ -1,32 +1,29 @@ /* * #%L * Bitmagasin modify client - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.access.getchecksums; -import java.net.URL; -import java.util.List; - import org.bitrepository.access.ContributorQuery; import org.bitrepository.bitrepositoryelements.ChecksumSpecTYPE; import org.bitrepository.client.eventhandler.BlockingEventHandler; @@ -35,8 +32,11 @@ import org.bitrepository.client.eventhandler.OperationEvent; import org.bitrepository.client.exceptions.NegativeResponseException; +import java.net.URL; +import java.util.List; + /** - * Wrappes a PutFileClient to provide a blocking client. The client will block until the PutFileOperation + * Wraps a PutFileClient to provide a blocking client. The client will block until the PutFileOperation * has finished. */ public class BlockingGetChecksumsClient { @@ -47,26 +47,30 @@ public BlockingGetChecksumsClient(GetChecksumsClient client) { } /** - * @see GetChecksumsClient#getChecksums - * @param collectionID The ID of the collection - * @param contributorQueries The queries for the contributors - * @param fileID The ID of the file that the request is about - * @param checksumSpec The checksum specification for the file - * @param urlForResult The URL to deliver results - * @param eventHandler The EventHandler to handle incoming events - * @param auditTrailInformation The audittrail information for the components + * @param collectionID The ID of the collection + * @param contributorQueries The queries for the contributors + * @param fileID The ID of the file that the request is about + * @param checksumSpec The checksum specification for the file + * @param urlForResult The URL to deliver results + * @param eventHandler The EventHandler to handle incoming events + * @param auditTrailInformation The auditTrail information for the components * @return The list of ContributorEvents containing the results - * @throws NegativeResponseException in case of the operation fails. + * @throws NegativeResponseException in case of the operation fails. + * @see GetChecksumsClient#getChecksums */ public List getChecksums(String collectionID, ContributorQuery[] contributorQueries, - String fileID, ChecksumSpecTYPE checksumSpec, URL urlForResult, EventHandler eventHandler, - String auditTrailInformation) throws NegativeResponseException { + String fileID, ChecksumSpecTYPE checksumSpec, URL urlForResult, EventHandler eventHandler, + String auditTrailInformation) throws NegativeResponseException { BlockingEventHandler blocker = new BlockingEventHandler(eventHandler); client.getChecksums(collectionID, contributorQueries, fileID, checksumSpec, urlForResult, blocker, auditTrailInformation); + return getContributorEvents(blocker); + } + + public static List getContributorEvents(BlockingEventHandler blocker) throws NegativeResponseException { OperationEvent finishEvent = blocker.awaitFinished(); - if(finishEvent.getEventType().equals(OperationEvent.OperationEventType.COMPLETE)) { + if (finishEvent.getEventType().equals(OperationEvent.OperationEventType.COMPLETE)) { return blocker.getResults(); } else if (finishEvent.getEventType().equals(OperationEvent.OperationEventType.FAILED)) { throw new NegativeResponseException(finishEvent.getInfo(), null); diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/ConversationBasedGetChecksumsClient.java b/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/ConversationBasedGetChecksumsClient.java index 5ad86483a..22f543d4e 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/ConversationBasedGetChecksumsClient.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/ConversationBasedGetChecksumsClient.java @@ -1,23 +1,23 @@ /* * #%L * bitrepository-access-client - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -45,19 +45,18 @@ /** * The default GetChecksumsClient. - * - * This class is just a thin wrapper which creates a conversion each time a operation is started. The conversations - * takes over the rest of the operation handling. + *

+ * This class is just a thin wrapper which creates a conversion each time an operation is started. */ public class ConversationBasedGetChecksumsClient extends AbstractClient implements GetChecksumsClient { private final Logger log = LoggerFactory.getLogger(getClass()); /** - * @see AbstractClient - * @param messageBus The MessageBus for communication + * @param messageBus The MessageBus for communication * @param conversationMediator The ConversationMediator to keep track of conversations - * @param settings The Settings - * @param clientID The ID of the client + * @param settings The Settings + * @param clientID The ID of the client + * @see AbstractClient */ public ConversationBasedGetChecksumsClient(MessageBus messageBus, ConversationMediator conversationMediator, Settings settings, String clientID) { @@ -67,8 +66,8 @@ public ConversationBasedGetChecksumsClient(MessageBus messageBus, ConversationMe @Override public void getChecksums(String collectionID, ContributorQuery[] contributorQueries, String fileID, - ChecksumSpecTYPE checksumSpec, URL addressForResult, EventHandler eventHandler, - String auditTrailInformation) { + ChecksumSpecTYPE checksumSpec, URL addressForResult, EventHandler eventHandler, + String auditTrailInformation) { ArgumentValidator.checkNotNullOrEmpty(collectionID, "collectionID"); MessageDataTypeValidator.validate(checksumSpec, "checksumSpec"); validateFileID(fileID); @@ -76,9 +75,9 @@ public void getChecksums(String collectionID, ContributorQuery[] contributorQuer contributorQueries = ContributorQueryUtils.createFullContributorQuery( SettingsUtils.getPillarIDsForCollection(collectionID)); } - + log.info("Requesting the checksums for file '{}' with the specifications '{}' with query {}." + - (addressForResult != null ? " The result should be uploaded to '{}'." : ""), + (addressForResult != null ? " The result should be uploaded to '{}'." : ""), fileID, checksumSpec, Arrays.asList(contributorQueries), addressForResult); GetChecksumsConversationContext context = new GetChecksumsConversationContext(collectionID, diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/GetChecksumsClient.java b/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/GetChecksumsClient.java index d992d8a3f..6cc354baf 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/GetChecksumsClient.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/GetChecksumsClient.java @@ -1,36 +1,36 @@ /* * #%L * Bitrepository Access - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.access.getchecksums; -import java.net.URL; - import org.bitrepository.access.ContributorQuery; import org.bitrepository.bitrepositoryelements.ChecksumSpecTYPE; import org.bitrepository.client.BitrepositoryClient; import org.bitrepository.client.eventhandler.EventHandler; +import java.net.URL; + /** * Used for retrieving checksums for files stored on the collection pillars. */ @@ -47,18 +47,19 @@ public interface GetChecksumsClient extends BitrepositoryClient { *

* The results are returned through as a ChecksumsCompletePillarCompete event as the results are returned by the * pillars. - * @param collectionID Identifies the collection to request checksums for. - * @param contributorQueries Defines which fileIDs to retrieve. If null all fileIDs from all contributers are - * returned. - * @param fileID The optional fileID to retrieve file information for. If null file information are - * retrieved for all files. - * @param checksumSpec Specification of how the type of checksums. If no checksum spec is specified the default - * checksum type will be returned. - * @param addressForResult [OPTIONAL] The address to upload the calculated checksums to. If this is null, then the - * results will be retrieved through the message. - * @param eventHandler [OPTIONAL] The handler which should receive notifications of the events occurring in - * connection with the pillar communication. - * @param auditTrailInformation Audittrail information for the contributors + * + * @param collectionID Identifies the collection to request checksums for. + * @param contributorQueries Defines which fileIDs to retrieve. If null all fileIDs from all contributors are + * returned. + * @param fileID The optional fileID to retrieve file information for. If null file information are + * retrieved for all files. + * @param checksumSpec Specification of how the type of checksums. If no checksum spec is specified the default + * checksum type will be returned. + * @param addressForResult [OPTIONAL] The address to upload the calculated checksums to. If this is null, then the + * results will be retrieved through the message. + * @param eventHandler [OPTIONAL] The handler which should receive notifications of the events occurring in + * connection with the pillar communication. + * @param auditTrailInformation AuditTrail information for the contributors */ void getChecksums(String collectionID, ContributorQuery[] contributorQueries, String fileID, ChecksumSpecTYPE checksumSpec, URL addressForResult, EventHandler eventHandler, diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/conversation/ChecksumsCompletePillarEvent.java b/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/conversation/ChecksumsCompletePillarEvent.java index 232da2f52..90ede07ab 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/conversation/ChecksumsCompletePillarEvent.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/conversation/ChecksumsCompletePillarEvent.java @@ -1,23 +1,23 @@ /* * #%L * Bitrepository Access - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -29,38 +29,35 @@ import org.bitrepository.client.eventhandler.ContributorCompleteEvent; /** -* Contains the result of a checksum request sent to a single pillar. -*/ + * Contains the result of a checksum request sent to a single pillar. + */ public class ChecksumsCompletePillarEvent extends ContributorCompleteEvent { - /** @see #getChecksums(). */ private final ResultingChecksums result; - /** @see #getChecksumType(). */ private final ChecksumSpecTYPE checksumType; - /** Whether this complete event only contains a partail result set.*/ private final boolean isPartialResult; - + /** - * @param pillarID The pillar which generated the result - * @param collectionID The ID of the collection - * @param result The result returned by the pillar. - * @param checksumType The checksum specification type. + * @param pillarID The pillar which generated the result + * @param collectionID The ID of the collection + * @param result The result returned by the pillar. + * @param checksumType The checksum specification type. * @param isPartialResult Whether the complete event contains only a partial results set. */ - public ChecksumsCompletePillarEvent(String pillarID, String collectionID, ResultingChecksums result, - ChecksumSpecTYPE checksumType, boolean isPartialResult) { + public ChecksumsCompletePillarEvent(String pillarID, String collectionID, ResultingChecksums result, + ChecksumSpecTYPE checksumType, boolean isPartialResult) { super(pillarID, collectionID); this.result = result; this.checksumType = checksumType; this.isPartialResult = isPartialResult; } - /** - * @return The checksum result from a single pillar. + /** + * @return The checksum result from a single pillar. */ public ResultingChecksums getChecksums() { return result; } - + /** * @return The checksum calculation specifics (e.g. the algorithm and optionally salt). */ @@ -79,11 +76,10 @@ public boolean isPartialResult() { public String additionalInfo() { StringBuilder infoSB = new StringBuilder(super.additionalInfo()); if (result != null && result.getChecksumDataItems() != null) { - infoSB.append(", NumberOfChecksums=" + - result.getChecksumDataItems().size()); + infoSB.append(", NumberOfChecksums=").append(result.getChecksumDataItems().size()); } - infoSB.append(", PartialResult=" + isPartialResult); + infoSB.append(", PartialResult=").append(isPartialResult); return infoSB.toString(); } } diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/conversation/GetChecksumsConversationContext.java b/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/conversation/GetChecksumsConversationContext.java index 9006b2ac0..da338ab51 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/conversation/GetChecksumsConversationContext.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/conversation/GetChecksumsConversationContext.java @@ -5,25 +5,22 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.access.getchecksums.conversation; -import java.net.URL; -import java.util.Collection; - import org.bitrepository.access.ContributorQuery; import org.bitrepository.bitrepositoryelements.ChecksumSpecTYPE; import org.bitrepository.client.conversation.ConversationContext; @@ -32,6 +29,9 @@ import org.bitrepository.protocol.OperationType; import org.bitrepository.protocol.messagebus.MessageSender; +import java.net.URL; +import java.util.Collection; + /** * Encapsulates the context for a GetChecksums operation. */ @@ -43,16 +43,17 @@ public class GetChecksumsConversationContext extends ConversationContext { /** * Extends the {@link ConversationContext} constructor with * {@link org.bitrepository.access.getchecksums.GetChecksumsClient} specific parameters. - * @param collectionID The ID of the collection - * @param contributorQueries See {@link org.bitrepository.access.getchecksums.GetChecksumsClient} for details. - * @param fileID The ID of the file to get checksums for - * @param checksumSpec See {@link org.bitrepository.access.getchecksums.GetChecksumsClient} for details. - * @param urlForResult See {@link org.bitrepository.access.getchecksums.GetChecksumsClient} for details. - * @param settings The settings - * @param messageSender The MessageSender to send messages with - * @param clientID The ID of the client - * @param contributors The contributors for the conversation - * @param eventHandler The EventHandler to handle incoming events + * + * @param collectionID The ID of the collection + * @param contributorQueries See {@link org.bitrepository.access.getchecksums.GetChecksumsClient} for details. + * @param fileID The ID of the file to get checksums for + * @param checksumSpec See {@link org.bitrepository.access.getchecksums.GetChecksumsClient} for details. + * @param urlForResult See {@link org.bitrepository.access.getchecksums.GetChecksumsClient} for details. + * @param settings The settings + * @param messageSender The MessageSender to send messages with + * @param clientID The ID of the client + * @param contributors The contributors for the conversation + * @param eventHandler The EventHandler to handle incoming events * @param auditTrailInformation The audittrail information for the contributors */ public GetChecksumsConversationContext( diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/conversation/GettingChecksums.java b/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/conversation/GettingChecksums.java index 2c500b3de..155c22f10 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/conversation/GettingChecksums.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/conversation/GettingChecksums.java @@ -1,32 +1,29 @@ /* * #%L * Bitrepository Access - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.access.getchecksums.conversation; -import java.math.BigInteger; -import java.util.Collection; - import org.bitrepository.access.ContributorQuery; import org.bitrepository.bitrepositorymessages.GetChecksumsFinalResponse; import org.bitrepository.bitrepositorymessages.GetChecksumsRequest; @@ -38,19 +35,24 @@ import org.bitrepository.common.utils.CalendarUtils; import org.bitrepository.common.utils.FileIDsUtils; +import java.math.BigInteger; +import java.util.Collection; + +import static org.bitrepository.common.utils.FileIDsUtils.*; + /** - * Models the behavior of a GetChecksums conversation during the operation phase. That is, it begins with the - * sending of GetChecksumsRequest messages and finishes with on the reception of the - * GetChecksumsFinalResponse messages from the responding pillars. - * - * Note that this is only used by the GetChecksumsConversation in the same package, therefore the visibility is package + * Models the behavior of a GetChecksums conversation during the operation phase. That is, it begins with the + * sending of {@link GetChecksumsRequest} messages and finishes with on the retrieval of the + * {@link GetChecksumsFinalResponse} messages from the responding pillars. + *

+ * Note that this is only used by the GetChecksumsConversation in the same package, therefore the visibility is package * protected. */ public class GettingChecksums extends PerformingOperationState { private final GetChecksumsConversationContext context; - /* - * @param context The conversation context. + /** + * @param context The conversation context. * @param contributors The list of components the checksums should be collected from. */ public GettingChecksums(GetChecksumsConversationContext context, Collection contributors) { @@ -62,27 +64,27 @@ public GettingChecksums(GetChecksumsConversationContext context, Collection getGetFileIDs( throws NegativeResponseException { BlockingEventHandler blocker = new BlockingEventHandler(eventHandler); client.getFileIDs(collectionID, contributorQueries, fileID, addressForResult, blocker); - OperationEvent finishEvent = blocker.awaitFinished(); - if(finishEvent.getEventType().equals(OperationEvent.OperationEventType.COMPLETE)) { - return blocker.getResults(); - } else if (finishEvent.getEventType().equals(OperationEvent.OperationEventType.FAILED)) { - throw new NegativeResponseException(finishEvent.getInfo(), null); - } else throw new RuntimeException("Received unexpected event type" + finishEvent); + return getContributorEvents(blocker); } } diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/conversation/GettingFileIDs.java b/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/conversation/GettingFileIDs.java index 7995bbabc..1c849be8c 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/conversation/GettingFileIDs.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/conversation/GettingFileIDs.java @@ -1,32 +1,29 @@ /* * #%L * Bitrepository Access - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.access.getfileids.conversation; -import java.math.BigInteger; -import java.util.Collection; - import org.bitrepository.access.ContributorQuery; import org.bitrepository.bitrepositorymessages.GetFileIDsFinalResponse; import org.bitrepository.bitrepositorymessages.GetFileIDsRequest; @@ -34,23 +31,25 @@ import org.bitrepository.client.conversation.ConversationContext; import org.bitrepository.client.conversation.PerformingOperationState; import org.bitrepository.client.conversation.selector.SelectedComponentInfo; -import org.bitrepository.client.exceptions.UnexpectedResponseException; import org.bitrepository.common.utils.CalendarUtils; import org.bitrepository.common.utils.FileIDsUtils; +import java.math.BigInteger; +import java.util.Collection; + /** - * Models the behavior of a GetFileIDs conversation during the operation phase. That is, it begins with the - * sending of GetFileIDsRequest messages and finishes with on the reception of the + * Models the behavior of a GetFileIDs conversation during the operation phase. That is, it begins with the + * sending of GetFileIDsRequest messages and finishes with on the reception of the * GetFileIDsFinalResponse messages from the responding pillars. - * - * Note that this is only used by the GetFileIDsConversation in the same package, therefore the visibility is package + *

+ * Note that this is only used by the GetFileIDsConversation in the same package, therefore the visibility is package * protected. */ public class GettingFileIDs extends PerformingOperationState { private final GetFileIDsConversationContext context; - /* - * @param context The conversation context. + /** + * @param context The conversation context. * @param contributors The list of components the fileIDs should be collected from. */ public GettingFileIDs(GetFileIDsConversationContext context, Collection contributors) { @@ -61,12 +60,12 @@ public GettingFileIDs(GetFileIDsConversationContext context, Collection. * #L% */ package org.bitrepository.client.conversation; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; import org.bitrepository.client.eventhandler.EventHandler; import org.bitrepository.common.settings.Settings; import org.bitrepository.protocol.CorrelationIDGenerator; import org.bitrepository.protocol.OperationType; import org.bitrepository.protocol.messagebus.MessageSender; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + /** * Encapsulates the shared state for a conversation. */ @@ -49,26 +50,20 @@ public class ConversationContext { /** * Encapsulates the common state maintained in a conversation. Will typically be subclasses to provide * operation specific attributes. - * @param collectionID The collectionID to use perform the conversation for. - * @param operationType Used for logging purposes. - * @param settings The settings to use in this conversation context. - * @param messageSender The messageSender to use in this conversation context. - * @param clientID The clientID to use in this conversation context. - * @param fileID Optional fileID to use in this conversation context. - * @param contributors The contributors to use in this conversation context. - * @param eventHandler The eventHandler to use in this conversation context. + * + * @param collectionID The collectionID to use perform the conversation for. + * @param operationType Used for logging purposes. + * @param settings The settings to use in this conversation context. + * @param messageSender The messageSender to use in this conversation context. + * @param clientID The clientID to use in this conversation context. + * @param fileID Optional fileID to use in this conversation context. + * @param contributors The contributors to use in this conversation context. + * @param eventHandler The eventHandler to use in this conversation context. * @param auditTrailInformation the audit trail information */ - public ConversationContext( - String collectionID, - OperationType operationType, - Settings settings, - MessageSender messageSender, - String clientID, - String fileID, - Collection contributors, - EventHandler eventHandler, - String auditTrailInformation) { + public ConversationContext(String collectionID, OperationType operationType, Settings settings, MessageSender messageSender, + String clientID, String fileID, Collection contributors, EventHandler eventHandler, + String auditTrailInformation) { this.collectionID = collectionID; this.settings = settings; this.messageSender = messageSender; @@ -130,6 +125,7 @@ public boolean isChecksumPillar(String pillarID) { /** * Use to register checksum pillars. + * * @param pillarID The pillarID of the Checksum pillar. */ public void addChecksumPillar(String pillarID) { @@ -138,16 +134,9 @@ public void addChecksumPillar(String pillarID) { @Override public String toString() { - return this.getClass().getSimpleName()+"{" + - "collectionID='" + collectionID + '\'' + - ", conversationID='" + conversationID + '\'' + - ", clientID='" + clientID + '\'' + - ", fileID='" + fileID + '\'' + - ", contributors=" + contributors + - ", monitor=" + monitor + - ", auditTrailInformation='" + auditTrailInformation + '\'' + - ", state=" + state + - ", checksumPillars=" + checksumPillars + - '}'; + return this.getClass().getSimpleName() + "{" + "collectionID='" + collectionID + '\'' + ", conversationID='" + conversationID + + '\'' + ", clientID='" + clientID + '\'' + ", fileID='" + fileID + '\'' + ", contributors=" + contributors + ", monitor=" + + monitor + ", auditTrailInformation='" + auditTrailInformation + '\'' + ", state=" + state + ", checksumPillars=" + + checksumPillars + '}'; } } diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/conversation/PerformingOperationState.java b/bitrepository-client/src/main/java/org/bitrepository/client/conversation/PerformingOperationState.java index 1f02c4f51..40c0028e7 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/conversation/PerformingOperationState.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/conversation/PerformingOperationState.java @@ -5,39 +5,36 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.client.conversation; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; import org.bitrepository.bitrepositoryelements.ResponseCode; import org.bitrepository.bitrepositorymessages.MessageResponse; import org.bitrepository.client.conversation.selector.SelectedComponentInfo; import org.bitrepository.client.exceptions.UnexpectedResponseException; import org.bitrepository.common.exceptions.UnableToFinishException; +import java.util.*; + /** * Handles the booking of performing the request phase messaging. Only the specialized workflow steps are required to * be implemented the subclass. */ public abstract class PerformingOperationState extends GeneralConversationState { - protected Map activeContributors; + protected Map activeContributors; /** * @param expectedContributors The components to perform the actual operation for. The operation is considered @@ -52,7 +49,7 @@ protected PerformingOperationState(Collection expectedCon } protected PerformingOperationState(String componentID) { - super(Arrays.asList(componentID)); + super(List.of(componentID)); } @Override @@ -67,9 +64,9 @@ protected boolean processMessage(MessageResponse msg) throws UnableToFinishExcep if (msg.getResponseInfo().getResponseCode().equals(ResponseCode.OPERATION_COMPLETED)) { generateContributorCompleteEvent(msg); } else { - isFinalResponse = handleFailureResponse(msg); + isFinalResponse = handleFailureResponse(msg); } - } catch(UnexpectedResponseException ure ) { + } catch (UnexpectedResponseException ure) { getContext().getMonitor().warning(ure.getMessage()); } } @@ -78,8 +75,9 @@ protected boolean processMessage(MessageResponse msg) throws UnableToFinishExcep @Override protected void logStateTimeout() throws UnableToFinishException { - throw new UnableToFinishException("Failed to receive responses from all contributors before timeout(" + - getTimeoutValue() + "ms). Missing contributors " + getOutstandingComponents()); + throw new UnableToFinishException( + "Failed to receive responses from all contributors before timeout(" + getTimeoutValue() + "ms). Missing contributors " + + getOutstandingComponents()); } @Override @@ -94,13 +92,13 @@ protected GeneralConversationState completeState() throws UnableToFinishExceptio return new FinishedState(getContext()); } else { getContext().getMonitor().timeoutRemainingContributors(getOutstandingComponents()); - throw new UnableToFinishException("All contributors haven't responded. Missing contributors " + - getOutstandingComponents()); + throw new UnableToFinishException("All contributors haven't responded. Missing contributors " + getOutstandingComponents()); } } /** * Delegating the generation of the COMPLETE_EVENT to the concrete state. + * * @param msg The final response to process into result event. * @throws UnexpectedResponseException Unable to generate a result event based on the supplied message. */ @@ -108,22 +106,23 @@ protected GeneralConversationState completeState() throws UnableToFinishExceptio private static Collection toComponentIDs(Collection contributors) { Collection componentIDs = new HashSet<>(); - for (SelectedComponentInfo componentInfo: contributors) { + for (SelectedComponentInfo componentInfo : contributors) { componentIDs.add(componentInfo.getID()); } return componentIDs; } + /** * Implements the default handling of failure responses which is is to do nothing * (besides being registered in the event monitor, which is handled by the parent class). + * * @param msg The failure message to handle - * @throws UnableToFinishException if the operation is unable to finish * @return true + * @throws UnableToFinishException if the operation is unable to finish */ protected boolean handleFailureResponse(MessageResponse msg) throws UnableToFinishException { - getContext().getMonitor().contributorFailed( - msg.getResponseInfo().getResponseText(), msg.getFrom(), - msg.getResponseInfo().getResponseCode()); + getContext().getMonitor() + .contributorFailed(msg.getResponseInfo().getResponseText(), msg.getFrom(), msg.getResponseInfo().getResponseCode()); return true; } } \ No newline at end of file diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/ReplaceFileCmd.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/ReplaceFileCmd.java index bbe6cf5e1..daad363ad 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/ReplaceFileCmd.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/ReplaceFileCmd.java @@ -33,6 +33,8 @@ import org.bitrepository.modify.ModifyComponentFactory; import org.bitrepository.modify.replacefile.ReplaceFileClient; +import static org.bitrepository.commandline.Constants.*; + /** * Replace a file from the collection. * @@ -49,10 +51,10 @@ public static void main(String[] args) { ReplaceFileCmd client = new ReplaceFileCmd(args); client.runCommand(); } catch (IllegalArgumentException iae) { - System.exit(Constants.EXIT_ARGUMENT_FAILURE); + System.exit(EXIT_ARGUMENT_FAILURE); } catch (Exception e) { e.printStackTrace(); - System.exit(Constants.EXIT_OPERATION_FAILURE); + System.exit(EXIT_OPERATION_FAILURE); } } @@ -74,36 +76,36 @@ protected boolean isFileIDArgumentRequired() { protected void createOptionsForCmdArgumentHandler() { super.createOptionsForCmdArgumentHandler(); - Option checksumOption = new Option(Constants.CHECKSUM_ARG, Constants.HAS_ARGUMENT, + Option checksumOption = new Option(CHECKSUM_ARG, HAS_ARGUMENT, "[OPTIONAL] The checksum of the file to be replaced."); - checksumOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); + checksumOption.setRequired(ARGUMENT_IS_NOT_REQUIRED); cmdHandler.addOption(checksumOption); - Option fileOption = new Option(Constants.FILE_ARG, Constants.HAS_ARGUMENT, + Option fileOption = new Option(FILE_ARG, HAS_ARGUMENT, "The path to the new file for the replacement. Required unless using the URL argument."); - fileOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); + fileOption.setRequired(ARGUMENT_IS_NOT_REQUIRED); cmdHandler.addOption(fileOption); - Option urlOption = new Option(Constants.URL_ARG, Constants.HAS_ARGUMENT, + Option urlOption = new Option(URL_ARG, HAS_ARGUMENT, "The URL for the file to be retreived. Is required, unless the actual file is given."); - urlOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); + urlOption.setRequired(ARGUMENT_IS_NOT_REQUIRED); cmdHandler.addOption(urlOption); - Option replaceChecksumOption = new Option(Constants.REPLACE_CHECKSUM_ARG, Constants.HAS_ARGUMENT, + Option replaceChecksumOption = new Option(REPLACE_CHECKSUM_ARG, HAS_ARGUMENT, "The checksum for the file to replace with. Required when using the URL argument."); - replaceChecksumOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); + replaceChecksumOption.setRequired(ARGUMENT_IS_NOT_REQUIRED); cmdHandler.addOption(replaceChecksumOption); - Option checksumTypeOption = new Option(Constants.REQUEST_CHECKSUM_TYPE_ARG, Constants.HAS_ARGUMENT, + Option checksumTypeOption = new Option(REQUEST_CHECKSUM_TYPE_ARG, HAS_ARGUMENT, "[OPTIONAL] The algorithm of checksum to request in the response from the pillars."); - checksumTypeOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); + checksumTypeOption.setRequired(ARGUMENT_IS_NOT_REQUIRED); cmdHandler.addOption(checksumTypeOption); - Option checksumSaltOption = new Option(Constants.REQUEST_CHECKSUM_SALT_ARG, Constants.HAS_ARGUMENT, + Option checksumSaltOption = new Option(REQUEST_CHECKSUM_SALT_ARG, HAS_ARGUMENT, "[OPTIONAL] The salt of checksum to request in the response. Requires the ChecksumType argument."); - checksumSaltOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); + checksumSaltOption.setRequired(ARGUMENT_IS_NOT_REQUIRED); cmdHandler.addOption(checksumSaltOption); - Option deleteOption = new Option(Constants.DELETE_FILE_ARG, Constants.NO_ARGUMENT, + Option deleteOption = new Option(DELETE_FILE_ARG, NO_ARGUMENT, "If this argument is present, then the file will be removed from the server, " + "when the operation is complete."); - deleteOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); + deleteOption.setRequired(ARGUMENT_IS_NOT_REQUIRED); cmdHandler.addOption(deleteOption); } @@ -119,27 +121,27 @@ protected void createOptionsForCmdArgumentHandler() { @Override protected void validateArguments() { super.validateArguments(); - if(!cmdHandler.hasOption(Constants.PILLAR_ARG)) { + if(!cmdHandler.hasOption(PILLAR_ARG)) { throw new IllegalArgumentException("The pillar argument (-p) must defined for the Replace operation, " + "only single pillar Replaces are allowed"); } - if (!cmdHandler.hasOption(Constants.CHECKSUM_ARG) && + if (!cmdHandler.hasOption(CHECKSUM_ARG) && settings.getRepositorySettings().getProtocolSettings().isRequireChecksumForDestructiveRequests()) { throw new IllegalArgumentException("Checksum argument (-C) are mandatory for Replace and replace " + "operations as defined in RepositorySettings."); } - if(cmdHandler.hasOption(Constants.FILE_ARG) && cmdHandler.hasOption(Constants.URL_ARG)) { + if(cmdHandler.hasOption(FILE_ARG) && cmdHandler.hasOption(URL_ARG)) { throw new IllegalArgumentException("Cannot take both a file (-f) and an URL (-u) as argument."); } - if(!cmdHandler.hasOption(Constants.FILE_ARG) && !cmdHandler.hasOption(Constants.URL_ARG)) { + if(!cmdHandler.hasOption(FILE_ARG) && !cmdHandler.hasOption(URL_ARG)) { throw new IllegalArgumentException("Requires either the file argument (-f) or the URL argument (-u)."); } - if(cmdHandler.hasOption(Constants.URL_ARG) && !cmdHandler.hasOption(Constants.REPLACE_CHECKSUM_ARG)) { + if(cmdHandler.hasOption(URL_ARG) && !cmdHandler.hasOption(REPLACE_CHECKSUM_ARG)) { throw new IllegalArgumentException("The URL argument requires also the checksum argument for the file " + "to replace with (-r)."); } - if(cmdHandler.hasOption(Constants.URL_ARG) && !cmdHandler.hasOption(Constants.FILE_ID_ARG)) { + if(cmdHandler.hasOption(URL_ARG) && !cmdHandler.hasOption(FILE_ID_ARG)) { throw new IllegalArgumentException("The URL argument requires also the argument for the ID of the " + "file (-i)."); } @@ -150,12 +152,12 @@ public void performOperation() { output.debug("Performing the ReplaceFile operation."); OperationEvent finalEvent = replaceTheFile(); output.completeEvent("Results of the ReplaceFile operation for the file '" - + cmdHandler.getOptionValue(Constants.FILE_ID_ARG) + "'" + + cmdHandler.getOptionValue(FILE_ID_ARG) + "'" + ": ", finalEvent); if(finalEvent.getEventType() == OperationEventType.COMPLETE) { - System.exit(Constants.EXIT_SUCCESS); + System.exit(EXIT_SUCCESS); } else { - System.exit(Constants.EXIT_OPERATION_FAILURE); + System.exit(EXIT_OPERATION_FAILURE); } } @@ -173,7 +175,7 @@ private OperationEvent replaceTheFile() { output.debug("Initiating the ReplaceFile conversation."); CompleteEventAwaiter eventHandler = new ReplaceFileEventHandler(settings, output); - String pillarID = cmdHandler.getOptionValue(Constants.PILLAR_ARG); + String pillarID = cmdHandler.getOptionValue(PILLAR_ARG); if (requestChecksum != null) { output.resultHeader("PillarId results"); @@ -185,7 +187,7 @@ requestChecksum, url, getSizeOfFileOrZero(), newValidationChecksum, OperationEvent finalEvent = eventHandler.getFinish(); - if(cmdHandler.hasOption(Constants.DELETE_FILE_ARG)) { + if(cmdHandler.hasOption(DELETE_FILE_ARG)) { deleteFileAfterwards(url); } @@ -200,10 +202,10 @@ requestChecksum, url, getSizeOfFileOrZero(), newValidationChecksum, * @return The checksum validation type. */ protected ChecksumDataForFileTYPE getValidationChecksum() { - if(cmdHandler.hasOption(Constants.FILE_ARG)) { + if(cmdHandler.hasOption(FILE_ARG)) { return getValidationChecksumDataForFile(findTheFile()); } else { - return getValidationChecksumDataFromArgument(Constants.REPLACE_CHECKSUM_ARG); + return getValidationChecksumDataFromArgument(REPLACE_CHECKSUM_ARG); } } } From e3faa8f3fd9a3db2f3a601f9b4af68c4eb8f76fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20S=C3=B8by?= Date: Mon, 21 Mar 2022 15:21:55 +0100 Subject: [PATCH 03/18] Cleaned up all of referene-client. --- .../access/ContributorQuery.java | 40 ++- .../access/ContributorQueryUtils.java | 26 +- .../getaudittrails/AuditTrailClient.java | 4 +- .../BlockingAuditTrailClient.java | 9 +- .../BlockingGetChecksumsClient.java | 12 +- .../getchecksums/GetChecksumsClient.java | 4 +- .../access/getfile/BlockingGetFileClient.java | 87 +++--- .../ConversationBasedGetFileClient.java | 93 ++++--- .../access/getfile/GetFileClient.java | 58 ++-- .../GetFileConversationContext.java | 45 +-- .../getfile/conversation/GettingFile.java | 39 +-- .../IdentifyingPillarsForGetFile.java | 19 +- .../FastestPillarSelectorForGetFile.java | 20 +- .../SelectedPillarForGetFileInfo.java | 53 ---- .../getfileids/BlockingGetFileIDsClient.java | 48 ++-- .../ConversationBasedGetFileIDsClient.java | 50 ++-- .../access/getfileids/GetFileIDsClient.java | 42 ++- .../FileIDsCompletePillarEvent.java | 32 +-- .../GetFileIDsConversationContext.java | 41 +-- .../conversation/GettingFileIDs.java | 6 +- .../IdentifyPillarsForGetFileIDs.java | 14 +- .../ConversationBasedGetStatusClient.java | 10 +- .../access/getstatus/GetStatusClient.java | 24 +- .../GetStatusConversationContext.java | 13 +- .../getstatus/conversation/GettingStatus.java | 26 +- .../IdentifyingContributorsForGetStatus.java | 16 +- .../StatusCompleteContributorEvent.java | 25 +- .../bitrepository/access/package-info.java | 16 +- .../bitrepository/client/AbstractClient.java | 51 ++-- ...ryClient.java => BitRepositoryClient.java} | 14 +- .../client/CommandLineSettingsProvider.java | 19 +- .../componentid/ComponentIDFactory.java | 8 +- .../client/componentid/ComponentIDHelper.java | 24 +- .../DefaultCommandlineComponentID.java | 8 +- .../UniqueCommandlineComponentID.java | 14 +- .../client/conversation/Conversation.java | 50 ++-- .../ConversationEventMonitor.java | 260 ++++++++++-------- .../conversation/ConversationState.java | 15 +- .../client/conversation/FinishedState.java | 24 +- .../GeneralConversationState.java | 4 +- .../client/conversation/IdentifyingState.java | 34 ++- .../PerformingOperationState.java | 2 +- .../conversation/StateBasedConversation.java | 18 +- .../CollectionBasedConversationMediator.java | 98 ++++--- .../mediator/ConversationMediator.java | 18 +- .../mediator/ConversationMediatorManager.java | 38 ++- .../selector/ComponentSelector.java | 26 +- .../selector/ContributorResponseStatus.java | 46 ++-- .../selector/SelectedComponentInfo.java | 36 ++- .../eventhandler/AbstractOperationEvent.java | 47 ++-- .../eventhandler/BlockingEventHandler.java | 40 ++- .../client/eventhandler/CompleteEvent.java | 22 +- .../ContributorCompleteEvent.java | 12 +- .../client/eventhandler/ContributorEvent.java | 16 +- .../eventhandler/ContributorFailedEvent.java | 16 +- .../client/eventhandler/DefaultEvent.java | 18 +- .../client/eventhandler/EventHandler.java | 19 +- .../IdentificationCompleteEvent.java | 18 +- .../client/eventhandler/OperationEvent.java | 44 ++- .../eventhandler/OperationFailedEvent.java | 20 +- .../exceptions/NegativeResponseException.java | 31 ++- .../UnexpectedResponseException.java | 20 +- .../commandline/CommandLineClient.java | 145 +++++----- .../bitrepository/commandline/Constants.java | 73 +++-- .../commandline/DeleteFileCmd.java | 21 +- .../commandline/GetChecksumsCmd.java | 33 +-- .../bitrepository/commandline/GetFileCmd.java | 25 +- .../commandline/GetFileIDsCmd.java | 21 +- .../bitrepository/commandline/PutFileCmd.java | 1 - .../commandline/ReplaceFileCmd.java | 90 +++--- .../clients/PagingGetChecksumsClient.java | 36 ++- .../clients/PagingGetFileIDsClient.java | 44 ++- .../eventhandler/CompleteEventAwaiter.java | 56 ++-- .../eventhandler/DeleteFileEventHandler.java | 19 +- .../GetChecksumsEventHandler.java | 22 +- .../eventhandler/GetFileEventHandler.java | 13 +- .../eventhandler/GetFileIDsEventHandler.java | 22 +- .../eventhandler/PagingEventHandler.java | 53 ++-- .../eventhandler/PutFileEventHandler.java | 27 +- .../eventhandler/ReplaceFileEventHandler.java | 36 +-- .../output/DefaultOutputHandler.java | 22 +- .../commandline/output/OutputHandler.java | 47 ++-- .../GetChecksumDistributionFormatter.java | 54 ++-- .../GetChecksumsInfoFormatter.java | 26 +- .../GetChecksumsOutputFormatter.java | 25 +- .../GetFileIDsInfoFormatter.java | 32 +-- .../GetFileIDsOutputFormatter.java | 23 +- .../resultmodel/ChecksumResult.java | 57 ++-- .../resultmodel/FileIDsResult.java | 71 +++-- .../resultmodel/GetChecksumsResultModel.java | 89 +++--- .../resultmodel/GetFileIDsResultModel.java | 89 +++--- .../utils/ChecksumExtractionUtils.java | 37 +-- .../utils/CommandLineArgumentsHandler.java | 72 +++-- .../modify/ModifyComponentFactory.java | 48 ++-- .../deletefile/BlockingDeleteFileClient.java | 50 ++-- .../ConversationBasedDeleteFileClient.java | 41 +-- .../modify/deletefile/DeleteFileClient.java | 45 ++- .../DeleteFileCompletePillarEvent.java | 37 +-- .../DeleteFileConversationContext.java | 24 +- .../deletefile/conversation/DeletingFile.java | 32 +-- .../IdentifyPillarsForDeleteFile.java | 33 ++- .../bitrepository/modify/package-info.java | 18 +- .../modify/putfile/BlockingPutFileClient.java | 34 +-- .../ConversationBasedPutFileClient.java | 40 ++- .../modify/putfile/PutFileClient.java | 4 +- .../IdentifyPillarsForPutFile.java | 64 +++-- .../PutFileCompletePillarEvent.java | 37 +-- .../PutFileConversationContext.java | 39 ++- .../putfile/conversation/PuttingFile.java | 4 +- .../BlockingReplaceFileClient.java | 50 ++-- .../ConversationBasedReplaceFileClient.java | 58 ++-- .../modify/replacefile/ReplaceFileClient.java | 69 ++--- .../IdentifyPillarsForReplaceFile.java | 19 +- .../ReplaceFileCompletePillarEvent.java | 43 ++- .../ReplaceFileConversationContext.java | 41 +-- .../conversation/ReplacingFile.java | 34 +-- .../getfile/GetFileClientComponentTest.java | 2 +- .../NegativeResponseExceptionTest.java | 24 +- 118 files changed, 2153 insertions(+), 2120 deletions(-) delete mode 100644 bitrepository-client/src/main/java/org/bitrepository/access/getfile/selectors/SelectedPillarForGetFileInfo.java rename bitrepository-client/src/main/java/org/bitrepository/client/{BitrepositoryClient.java => BitRepositoryClient.java} (93%) diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/ContributorQuery.java b/bitrepository-client/src/main/java/org/bitrepository/access/ContributorQuery.java index 3bd354ec2..103921a0f 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/ContributorQuery.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/ContributorQuery.java @@ -1,23 +1,23 @@ /* * #%L * Bitrepository Access - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -31,9 +31,8 @@ *

The ContributorQuery functionality can be used to request results in chunks. This is useful if the number of * potential results might be very large, which might cause OutOfMemory problems. A full result can be listed though * paging through the chunks by:

    - *
  1. Making a request with maxNumberOfResults set to the
  2. + *
  3. Making a request with maxNumberOfResults set to the
  4. *
- * */ public class ContributorQuery { private final String componentID; @@ -42,13 +41,13 @@ public class ContributorQuery { private final Integer maxNumberOfResults; /** - * @param componentID If set, only results from the indicated component is requested. - * @param minTimestamp If set, only elements with timestamp later than or equal to minTimestamp are - * requested. - * @param maxTimestamp If set, only elements with timestamp earlier than or equal to maxTimestamp are - * requested. + * @param componentID If set, only results from the indicated component is requested. + * @param minTimestamp If set, only elements with timestamp later than or equal to minTimestamp are + * requested. + * @param maxTimestamp If set, only elements with timestamp earlier than or equal to maxTimestamp are + * requested. * @param maxNumberOfResults If set will limit the number of results returned. If the result set is limited, only - * the oldest timestamps are returned + * the oldest timestamps are returned */ public ContributorQuery(String componentID, Date minTimestamp, Date maxTimestamp, Integer maxNumberOfResults) { if (minTimestamp != null && maxTimestamp != null && minTimestamp.after(maxTimestamp)) { @@ -80,7 +79,7 @@ public Integer getMaxNumberOfResults() { @Override public String toString() { return getClass().getSimpleName() + "{" + - "componentID='" + componentID + + "componentID='" + componentID + "', minTimestamp=" + minTimestamp + ", maxTimestamp=" + maxTimestamp + ", maxNumberOfResults=" + maxNumberOfResults + @@ -96,7 +95,7 @@ public int hashCode() { result = prime * result + ((maxNumberOfResults == null) ? 0 : maxNumberOfResults - .hashCode()); + .hashCode()); result = prime * result + ((maxTimestamp == null) ? 0 : maxTimestamp.hashCode()); result = prime * result @@ -129,10 +128,9 @@ public boolean equals(Object obj) { } else if (!maxTimestamp.equals(other.maxTimestamp)) return false; if (minTimestamp == null) { - if (other.minTimestamp != null) - return false; - } else if (!minTimestamp.equals(other.minTimestamp)) - return false; - return true; + return other.minTimestamp == null; + } else { + return minTimestamp.equals(other.minTimestamp); + } } } diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/ContributorQueryUtils.java b/bitrepository-client/src/main/java/org/bitrepository/access/ContributorQueryUtils.java index 103a13b6c..5e17ad9a2 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/ContributorQueryUtils.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/ContributorQueryUtils.java @@ -1,20 +1,20 @@ package org.bitrepository.access;/* * #%L - * Bitrepository Integrity Service + * BitRepository Integrity Service * %% * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -29,25 +29,27 @@ public class ContributorQueryUtils { /** * Used to create a AuditTrailQuery[] array in case no array is defined. + * * @param contributorIDs The collection of contributor IDs to create ContributorQueries for - * @return A AuditTrailQuery[] array requesting all audit trails from all the defined contributers. + * @return A AuditTrailQuery[] array requesting all audit trails from all the defined contributors. */ public static ContributorQuery[] createFullContributorQuery(Collection contributorIDs) { List componentQueryList = new ArrayList<>(contributorIDs.size()); - for (String contributer : contributorIDs) { - componentQueryList.add(new ContributorQuery(contributer, null, null, null)); + for (String contributor : contributorIDs) { + componentQueryList.add(new ContributorQuery(contributor, null, null, null)); } - return componentQueryList.toArray(new ContributorQuery[componentQueryList.size()]); + return componentQueryList.toArray(new ContributorQuery[0]); } /** - * Extracts the collection of ContributorIDs from the ContribytorQueries. + * Extracts the collection of ContributorIDs from the ContributorQueries. + * * @param queries The contributor queries to extract nonPillarContributors from * @return The list of ContributorIDs in the supplied queries */ public static Collection getContributors(ContributorQuery[] queries) { Collection contributors = new HashSet<>(); - for (ContributorQuery query: queries) { + for (ContributorQuery query : queries) { contributors.add(query.getComponentID()); } return contributors; diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/AuditTrailClient.java b/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/AuditTrailClient.java index 3814a7b8d..6d855a6f7 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/AuditTrailClient.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/AuditTrailClient.java @@ -24,10 +24,10 @@ */ package org.bitrepository.access.getaudittrails; -import org.bitrepository.client.BitrepositoryClient; +import org.bitrepository.client.BitRepositoryClient; import org.bitrepository.client.eventhandler.EventHandler; -public interface AuditTrailClient extends BitrepositoryClient { +public interface AuditTrailClient extends BitRepositoryClient { /** * @param collectionID The collection to request auditTrails for. * @param componentQueries Defines which components to retrieve auditTrail from. Also defines a filter which diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/BlockingAuditTrailClient.java b/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/BlockingAuditTrailClient.java index b82064f8c..f98c9ddf2 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/BlockingAuditTrailClient.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getaudittrails/BlockingAuditTrailClient.java @@ -32,7 +32,7 @@ import org.bitrepository.client.exceptions.NegativeResponseException; /** - * Wrappes a PutFileClient to provide a blocking client. The client will block until the PutFileOperation + * Wraps a PutFileClient to provide a blocking client. The client will block until the PutFileOperation * has finished. */ public class BlockingAuditTrailClient { @@ -58,6 +58,11 @@ public List getAuditTrails(String collectionID, AuditTrailQuer throws NegativeResponseException { BlockingEventHandler blocker = new BlockingEventHandler(eventHandler); client.getAuditTrails(collectionID, componentQueries, fileID, urlForResult, blocker, auditTrailInformation); - return getContributorEvents(blocker); + OperationEvent finishEvent = blocker.awaitFinished(); + if(finishEvent.getEventType().equals(OperationEvent.OperationEventType.COMPLETE)) { + return blocker.getResults(); + } else if (finishEvent.getEventType().equals(OperationEvent.OperationEventType.FAILED)) { + throw new NegativeResponseException(finishEvent.getInfo(), null); + } else throw new RuntimeException("Received unexpected event type" + finishEvent); } } diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/BlockingGetChecksumsClient.java b/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/BlockingGetChecksumsClient.java index 417d8cf2b..529006c8f 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/BlockingGetChecksumsClient.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/BlockingGetChecksumsClient.java @@ -58,17 +58,11 @@ public BlockingGetChecksumsClient(GetChecksumsClient client) { * @throws NegativeResponseException in case of the operation fails. * @see GetChecksumsClient#getChecksums */ - public List getChecksums(String collectionID, ContributorQuery[] contributorQueries, - String fileID, ChecksumSpecTYPE checksumSpec, URL urlForResult, EventHandler eventHandler, + public List getChecksums(String collectionID, ContributorQuery[] contributorQueries, String fileID, + ChecksumSpecTYPE checksumSpec, URL urlForResult, EventHandler eventHandler, String auditTrailInformation) throws NegativeResponseException { - BlockingEventHandler blocker = new BlockingEventHandler(eventHandler); - client.getChecksums(collectionID, contributorQueries, fileID, checksumSpec, urlForResult, blocker, - auditTrailInformation); - return getContributorEvents(blocker); - } - - public static List getContributorEvents(BlockingEventHandler blocker) throws NegativeResponseException { + client.getChecksums(collectionID, contributorQueries, fileID, checksumSpec, urlForResult, blocker, auditTrailInformation); OperationEvent finishEvent = blocker.awaitFinished(); if (finishEvent.getEventType().equals(OperationEvent.OperationEventType.COMPLETE)) { return blocker.getResults(); diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/GetChecksumsClient.java b/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/GetChecksumsClient.java index 6cc354baf..04958e0cf 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/GetChecksumsClient.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getchecksums/GetChecksumsClient.java @@ -26,7 +26,7 @@ import org.bitrepository.access.ContributorQuery; import org.bitrepository.bitrepositoryelements.ChecksumSpecTYPE; -import org.bitrepository.client.BitrepositoryClient; +import org.bitrepository.client.BitRepositoryClient; import org.bitrepository.client.eventhandler.EventHandler; import java.net.URL; @@ -34,7 +34,7 @@ /** * Used for retrieving checksums for files stored on the collection pillars. */ -public interface GetChecksumsClient extends BitrepositoryClient { +public interface GetChecksumsClient extends BitRepositoryClient { /** * Retrieves the checksums for a set of files. diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getfile/BlockingGetFileClient.java b/bitrepository-client/src/main/java/org/bitrepository/access/getfile/BlockingGetFileClient.java index bbb8a2d7c..9b3063dcd 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getfile/BlockingGetFileClient.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getfile/BlockingGetFileClient.java @@ -1,40 +1,40 @@ /* * #%L * Bitmagasin modify client - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.access.getfile; -import java.net.URL; - import org.bitrepository.bitrepositoryelements.FilePart; import org.bitrepository.client.eventhandler.BlockingEventHandler; import org.bitrepository.client.eventhandler.EventHandler; import org.bitrepository.client.eventhandler.OperationEvent; import org.bitrepository.client.exceptions.NegativeResponseException; +import java.net.URL; + /** - * Wrappes a PutFileClient to provide a blocking client. The client will block until the PutFileOperation - * has finished. + * Wraps a {@link org.bitrepository.modify.putfile.PutFileClient} to provide a blocking client. The client will block until the + * PutFileOperation has finished. */ public class BlockingGetFileClient { private final GetFileClient client; @@ -44,60 +44,47 @@ public BlockingGetFileClient(GetFileClient client) { } /** - * @see GetFileClient#getFileFromFastestPillar - * @param collectionID The ID of the collection - * @param fileID The ID of the file to get - * @param filePart The FilePart specification if only requesting parts of a file - * @param uploadUrl The URL to upload the file to - * @param eventHandler The EventHandler to handle incoming events - * @param auditTrailInformation The audittrail information for the contributors + * @param collectionID The ID of the collection + * @param fileID The ID of the file to get + * @param filePart The FilePart specification if only requesting parts of a file + * @param uploadUrl The URL to upload the file to + * @param eventHandler The EventHandler to handle incoming events + * @param auditTrailInformation The auditTrail information for the contributors * @throws NegativeResponseException in case the operation fails + * @see GetFileClient#getFileFromFastestPillar */ - public void getFileFromFastestPillar( - String collectionID, - String fileID, - FilePart filePart, - URL uploadUrl, - EventHandler eventHandler, - String auditTrailInformation) - throws NegativeResponseException { + public void getFileFromFastestPillar(String collectionID, String fileID, FilePart filePart, URL uploadUrl, EventHandler eventHandler, + String auditTrailInformation) throws NegativeResponseException { BlockingEventHandler blocker = new BlockingEventHandler(eventHandler); client.getFileFromFastestPillar(collectionID, fileID, filePart, uploadUrl, blocker, auditTrailInformation); OperationEvent finishEvent = blocker.awaitFinished(); - if(finishEvent.getEventType().equals(OperationEvent.OperationEventType.COMPLETE)) { - return; - } else if (finishEvent.getEventType().equals(OperationEvent.OperationEventType.FAILED)) { + if (finishEvent.getEventType().equals(OperationEvent.OperationEventType.FAILED)) { throw new NegativeResponseException(finishEvent.getInfo(), null); - } else throw new RuntimeException("Received unexpected event type" + finishEvent); + } else if (!finishEvent.getEventType().equals(OperationEvent.OperationEventType.COMPLETE)) { + throw new RuntimeException("Received unexpected event type" + finishEvent); + } } /** - * @see GetFileClient#getFileFromSpecificPillar - * @param collectionID The ID of the collection - * @param fileID The ID of the file to get - * @param filePart The FilePart specification if only requesting parts of a file - * @param uploadUrl The URL to upload the file to - * @param pillarID The ID of the specific pillar to get the file from - * @param eventHandler The EventHandler to handle incoming events - * @param auditTrailInformation The audittrail information for the contributors + * @param collectionID The ID of the collection + * @param fileID The ID of the file to get + * @param filePart The FilePart specification if only requesting parts of a file + * @param uploadUrl The URL to upload the file to + * @param pillarID The ID of the specific pillar to get the file from + * @param eventHandler The EventHandler to handle incoming events + * @param auditTrailInformation The auditTrail information for the contributors * @throws NegativeResponseException in case the operation fails + * @see GetFileClient#getFileFromSpecificPillar */ - public void getFileFromSpecificPillar( - String collectionID, - String fileID, - FilePart filePart, - URL uploadUrl, - String pillarID, - EventHandler eventHandler, - String auditTrailInformation) - throws NegativeResponseException { + public void getFileFromSpecificPillar(String collectionID, String fileID, FilePart filePart, URL uploadUrl, String pillarID, + EventHandler eventHandler, String auditTrailInformation) throws NegativeResponseException { BlockingEventHandler blocker = new BlockingEventHandler(eventHandler); client.getFileFromSpecificPillar(collectionID, fileID, filePart, uploadUrl, pillarID, blocker, auditTrailInformation); OperationEvent finishEvent = blocker.awaitFinished(); - if(finishEvent.getEventType().equals(OperationEvent.OperationEventType.COMPLETE)) { - return; - } else if (finishEvent.getEventType().equals(OperationEvent.OperationEventType.FAILED)) { + if (finishEvent.getEventType().equals(OperationEvent.OperationEventType.FAILED)) { throw new NegativeResponseException(finishEvent.getInfo(), null); - } else throw new RuntimeException("Received unexpected event type" + finishEvent); + } else if (!finishEvent.getEventType().equals(OperationEvent.OperationEventType.COMPLETE)) { + throw new RuntimeException("Received unexpected event type" + finishEvent); + } } } diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getfile/ConversationBasedGetFileClient.java b/bitrepository-client/src/main/java/org/bitrepository/access/getfile/ConversationBasedGetFileClient.java index fa4616ae0..165938ce6 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getfile/ConversationBasedGetFileClient.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getfile/ConversationBasedGetFileClient.java @@ -1,23 +1,23 @@ /* * #%L * Bitrepository Access Client - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -38,24 +38,23 @@ import org.slf4j.LoggerFactory; import java.net.URL; -import java.util.Arrays; import java.util.Collection; +import java.util.List; /** * The default GetFileClient. - * - * This class is just a thin wrapper which creates a conversion each time a operation is started. The conversations - * takes over the rest of the operation handling. + *

+ * This class is just a thin wrapper which creates a conversion each time an operation is started. */ public class ConversationBasedGetFileClient extends AbstractClient implements GetFileClient { private final Logger log = LoggerFactory.getLogger(getClass()); /** - * @see AbstractClient - * @param messageBus The MessageBus for communication + * @param messageBus The MessageBus for communication * @param conversationMediator The ConversationMediator to keep track of conversations - * @param settings The settings - * @param clientID The ID of the client + * @param settings The settings + * @param clientID The ID of the client + * @see AbstractClient */ public ConversationBasedGetFileClient(MessageBus messageBus, ConversationMediator conversationMediator, Settings settings, String clientID) { @@ -64,43 +63,73 @@ public ConversationBasedGetFileClient(MessageBus messageBus, ConversationMediato ArgumentValidator.checkNotNull(settings, "settings"); } + /** + * Attempts to get the file fom the fastest pillar (decided using the pillars' timeToDeliver ID). + * + * @param collectionID Identifies the collection the file should be retrieved from. + * @param fileID The id of the file to retrieve. + * @param filePart The part of the file, which is wanted. If null, then the whole file is retrieved. + * @param uploadUrl The url the pillar should upload the file to. + * @param eventHandler The handler which should receive notifications of the progress events. + * @param auditTrailInformation Additional information to add to the audit trail created because of this operation. + */ @Override - public void getFileFromFastestPillar(String collectionID, - String fileID, FilePart filePart, URL uploadUrl, EventHandler eventHandler, String auditTrailInformation) { + public void getFileFromFastestPillar(String collectionID, String fileID, FilePart filePart, URL uploadUrl, EventHandler eventHandler, + String auditTrailInformation) { ArgumentValidator.checkNotNullOrEmpty(collectionID, "collectionID"); ArgumentValidator.checkNotNull(fileID, "fileID"); ArgumentValidator.checkNotNull(uploadUrl, "uploadUrl"); ArgumentValidator.checkNotNull(eventHandler, "eventHandler"); validateFileID(fileID); - + log.info("Requesting the file '" + fileID + " from the fastest pillar"); - getFile(collectionID, messageBus, settings, fileID, filePart, - SettingsUtils.getPillarIDsForCollection(collectionID), uploadUrl, eventHandler, auditTrailInformation); + getFile(collectionID, messageBus, settings, fileID, filePart, SettingsUtils.getPillarIDsForCollection(collectionID), uploadUrl, + eventHandler, auditTrailInformation); } + /** + * Attempts to get the file from a specific pillar. + * + * @param collectionID Identifies the collection the file should be retrieved from. + * @param fileID The id of the file to retrieve. + * @param filePart The part of the file, which is wanted. If null, then the whole file is retrieved. + * @param uploadUrl The url the pillar should upload the file to. + * @param pillarID The id of pillar, where the file should be retrieved from. + * @param eventHandler The handler which should receive notifications of the events occurring in connection with + * the pillar communication. + * @param auditTrailInformation Additional information to add to the audit trail created because of this operation. + */ @Override - public void getFileFromSpecificPillar(String collectionID, - String fileID, FilePart filePart, URL uploadUrl, String pillarID, EventHandler eventHandler, - String auditTrailInformation) { + public void getFileFromSpecificPillar(String collectionID, String fileID, FilePart filePart, URL uploadUrl, String pillarID, + EventHandler eventHandler, String auditTrailInformation) { ArgumentValidator.checkNotNullOrEmpty(collectionID, "collectionID"); ArgumentValidator.checkNotNull(fileID, "fileID"); ArgumentValidator.checkNotNull(uploadUrl, "uploadUrl"); ArgumentValidator.checkNotNullOrEmpty(pillarID, "pillarID"); ArgumentValidator.checkNotNull(eventHandler, "eventHandler"); validateFileID(fileID); - + log.info("Requesting the file '" + fileID + "' from pillar '" + pillarID + "'."); - getFile(collectionID, messageBus, settings, fileID, filePart, Arrays.asList(pillarID), - uploadUrl, eventHandler, auditTrailInformation); + getFile(collectionID, messageBus, settings, fileID, filePart, List.of(pillarID), uploadUrl, eventHandler, auditTrailInformation); } - private void getFile(String collectionID, MessageBus messageBus, Settings settings, - String fileID, FilePart filePart, Collection contributors, URL uploadUrl, EventHandler eventHandler, - String auditTrailInformation) { - GetFileConversationContext context = new GetFileConversationContext(collectionID, - fileID, uploadUrl, filePart, contributors, settings, messageBus, clientID, eventHandler, - auditTrailInformation - ); + /** + * Starts a conversation with GetFileConversationContext which is created using the given parameters. + * + * @param collectionID The ID of the collection. + * @param messageBus The messageBus to use. + * @param settings The settings. + * @param fileID The ID of the file (usually the file-name). + * @param filePart The {@link FilePart} if only a file-part is requested. + * @param contributors A list of the contributors (pillars). + * @param uploadUrl The URL to upload to. + * @param eventHandler An EventHandler used to track the progress events, and await a final event. + * @param auditTrailInformation The information given to the AuditTrail. + */ + private void getFile(String collectionID, MessageBus messageBus, Settings settings, String fileID, FilePart filePart, + Collection contributors, URL uploadUrl, EventHandler eventHandler, String auditTrailInformation) { + GetFileConversationContext context = new GetFileConversationContext(collectionID, fileID, uploadUrl, filePart, contributors, + settings, messageBus, clientID, eventHandler, auditTrailInformation); startConversation(context, new IdentifyingPillarsForGetFile(context)); } } diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getfile/GetFileClient.java b/bitrepository-client/src/main/java/org/bitrepository/access/getfile/GetFileClient.java index 6a5a1a3b4..4f6585224 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getfile/GetFileClient.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getfile/GetFileClient.java @@ -1,51 +1,50 @@ /* * #%L * bitrepository-access-client - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.access.getfile; -import java.net.URL; - import org.bitrepository.bitrepositoryelements.FilePart; -import org.bitrepository.client.BitrepositoryClient; +import org.bitrepository.client.BitRepositoryClient; import org.bitrepository.client.eventhandler.EventHandler; +import java.net.URL; + /** - * The GetFileClient is used as a handle for the Bit Repository getFile operation. - * + * The {@link GetFileClient} is used as a handle for the BitRepository getFile operation. */ -public interface GetFileClient extends BitrepositoryClient { +public interface GetFileClient extends BitRepositoryClient { /** - * Method for retrieving a file from the pillar able to deliver the file fastest. - * - * The method will return as soon as the communication has been setup. + * Method for retrieving a file from the pillar able to deliver the file fastest. + *

+ * The method will return as soon as the communication has been initialized. * - * @param collectionID Identifies the collection the file should be retrieved from. - * @param fileID The id of the file to retrieve. - * @param filePart The part of the file, which is wanted. If null, then the whole file is retrieved. - * @param uploadUrl The url the pillar should upload the file to. - * @param eventHandler The handler which should receive notifications of the progress events. + * @param collectionID Identifies the collection the file should be retrieved from. + * @param fileID The id of the file to retrieve. + * @param filePart The part of the file, which is wanted. If null, then the whole file is retrieved. + * @param uploadUrl The url the pillar should upload the file to. + * @param eventHandler The handler which should receive notifications of the progress events. * @param auditTrailInformation Additional information to add to the audit trail created because of this operation. */ void getFileFromFastestPillar(String collectionID, String fileID, FilePart filePart, URL uploadUrl, @@ -53,16 +52,17 @@ void getFileFromFastestPillar(String collectionID, String fileID, FilePart fileP String auditTrailInformation); /** - * Method for retrieving a file from a specific pillar. + * Method for retrieving a file from a specific pillar. + *

+ * The method will return as soon as the communication has been initialized. * - * The method will return as soon as the communication has been setup. - * @param collectionID Identifies the collection the file should be retrieved from. - * @param fileID The id of the file to retrieve. - * @param filePart The part of the file, which is wanted. If null, then the whole file is retrieved. - * @param uploadUrl The url the pillar should upload the file to. - * @param pillarID The id of pillar, where the file should be retrieved from. - * @param eventHandler The handler which should receive notifications of the events occurring in connection with - * the pillar communication. + * @param collectionID Identifies the collection the file should be retrieved from. + * @param fileID The id of the file to retrieve. + * @param filePart The part of the file, which is wanted. If null, then the whole file is retrieved. + * @param uploadUrl The url the pillar should upload the file to. + * @param pillarID The id of pillar, where the file should be retrieved from. + * @param eventHandler The handler which should receive notifications of the events occurring in connection with + * the pillar communication. * @param auditTrailInformation Additional information to add to the audit trail created because of this operation. */ void getFileFromSpecificPillar(String collectionID, String fileID, FilePart filePart, URL uploadUrl, diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getfile/conversation/GetFileConversationContext.java b/bitrepository-client/src/main/java/org/bitrepository/access/getfile/conversation/GetFileConversationContext.java index 07afe1eac..19356921f 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getfile/conversation/GetFileConversationContext.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getfile/conversation/GetFileConversationContext.java @@ -5,24 +5,22 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.access.getfile.conversation; -import java.net.URL; -import java.util.Collection; import org.bitrepository.bitrepositoryelements.FilePart; import org.bitrepository.client.conversation.ConversationContext; import org.bitrepository.client.eventhandler.EventHandler; @@ -30,30 +28,33 @@ import org.bitrepository.protocol.OperationType; import org.bitrepository.protocol.messagebus.MessageSender; +import java.net.URL; +import java.util.Collection; + /** * The context for the conversation for the GetFile operation. */ public class GetFileConversationContext extends ConversationContext { - private FilePart filePart; + private final FilePart filePart; private final URL urlForResult; /** - * @see ConversationContext for general parameter documentation. - * @param collectionID The ID of the collection - * @param fileID The ID of the file - * @param urlForResult The URL to deliver the results to - * @param filePart The part of the file. Null if whole file is wanted. - * @param contributors The contributors used in the conversation - * @param settings The settings - * @param messageSender The MessageSender for sending messages - * @param clientID The ID of the client - * @param eventHandler The EventHandler for handling incoming events + * @param collectionID The ID of the collection + * @param fileID The ID of the file + * @param urlForResult The URL to deliver the results to + * @param filePart The part of the file. Null if whole file is wanted. + * @param contributors The contributors used in the conversation + * @param settings The settings + * @param messageSender The MessageSender for sending messages + * @param clientID The ID of the client + * @param eventHandler The EventHandler for handling incoming events * @param auditTrailInformation The audittrail information for the contributors + * @see ConversationContext for general parameter documentation. */ public GetFileConversationContext(String collectionID, - String fileID, URL urlForResult, FilePart filePart, Collection contributors, - Settings settings, MessageSender messageSender, String clientID, EventHandler eventHandler, - String auditTrailInformation) { + String fileID, URL urlForResult, FilePart filePart, Collection contributors, + Settings settings, MessageSender messageSender, String clientID, EventHandler eventHandler, + String auditTrailInformation) { super(collectionID, OperationType.GET_FILE, settings, messageSender, clientID, fileID, contributors, eventHandler, auditTrailInformation); this.filePart = filePart; @@ -66,7 +67,7 @@ public GetFileConversationContext(String collectionID, public FilePart getFilePart() { return filePart; } - + /** * @return The URL for the results to be delivered. */ diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getfile/conversation/GettingFile.java b/bitrepository-client/src/main/java/org/bitrepository/access/getfile/conversation/GettingFile.java index c3508efed..59bd4a63b 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getfile/conversation/GettingFile.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getfile/conversation/GettingFile.java @@ -1,31 +1,29 @@ /* * #%L * Bitrepository Access - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.access.getfile.conversation; -import java.util.Collection; -import java.util.HashSet; import org.bitrepository.bitrepositorymessages.GetFileRequest; import org.bitrepository.bitrepositorymessages.MessageResponse; import org.bitrepository.client.conversation.ConversationContext; @@ -34,26 +32,30 @@ import org.bitrepository.client.eventhandler.ContributorCompleteEvent; import org.bitrepository.common.exceptions.UnableToFinishException; +import java.util.Collection; +import java.util.HashSet; + /** * Models the behavior of a GetFile conversation during the file exchange phase. That is, it begins with the sending of * a GetFileRequest and finishes with on the reception of a GetFileFinalResponse message. - * - * Note that this is only used by the GetFileConversation in the same package, therefore the visibility is package + *

+ * Note that this is only used by the GetFileConversation in the same package, therefore the visibility is package * protected. */ class GettingFile extends PerformingOperationState { private final GetFileConversationContext context; private final SelectedComponentInfo selectedPillar; + private final Collection contributors; /** * @param context The related conversation containing context information. - * @param pillar The pillar the file should be requested from. + * @param pillar The pillar the file should be requested from. */ public GettingFile(GetFileConversationContext context, SelectedComponentInfo pillar) { super(pillar.getID()); this.context = context; this.selectedPillar = pillar; - Collection contributors = new HashSet<>(); + contributors = new HashSet<>(); contributors.add(pillar.getID()); } @@ -72,10 +74,9 @@ protected void sendRequest() { @Override protected boolean handleFailureResponse(MessageResponse msg) throws UnableToFinishException { - getContext().getMonitor().contributorFailed( - msg.getResponseInfo().getResponseText(), msg.getFrom(), msg.getResponseInfo().getResponseCode()); - throw new UnableToFinishException("Failed to get file from " + msg.getFrom() + - ", " + msg.getResponseInfo()); + getContext().getMonitor() + .contributorFailed(msg.getResponseInfo().getResponseText(), msg.getFrom(), msg.getResponseInfo().getResponseCode()); + throw new UnableToFinishException("Failed to get file from " + msg.getFrom() + ", " + msg.getResponseInfo()); } @Override @@ -87,9 +88,13 @@ protected void generateContributorCompleteEvent(MessageResponse msg) { protected ConversationContext getContext() { return context; } - + @Override protected String getPrimitiveName() { return "GetFile"; } + + protected Collection getContributors() { + return contributors; + } } diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getfile/conversation/IdentifyingPillarsForGetFile.java b/bitrepository-client/src/main/java/org/bitrepository/access/getfile/conversation/IdentifyingPillarsForGetFile.java index d9a08a0e8..b3e9182b2 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getfile/conversation/IdentifyingPillarsForGetFile.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getfile/conversation/IdentifyingPillarsForGetFile.java @@ -1,23 +1,23 @@ /* * #%L * Bitrepository Access - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -38,8 +38,9 @@ public class IdentifyingPillarsForGetFile extends IdentifyingState { private final GetFileConversationContext context; - /** + /** * The constructor for the indicated conversation. + * * @param context The related context related to the conversation containing information. */ public IdentifyingPillarsForGetFile(GetFileConversationContext context) { @@ -65,7 +66,7 @@ protected void sendRequest() { msg.setFileID(context.getFileID()); context.getMessageSender().sendMessage(msg); context.getMonitor().identifyRequestSent("Identifying pillars for GetFile"); - + } @Override @@ -79,7 +80,7 @@ protected String getPrimitiveName() { } /** - * @return the single selected pillar fron the generic selector's SelectedComponents list. + * @return the single selected pillar from the generic selector's SelectedComponents list. */ private SelectedComponentInfo getSelectedPillar() { return getSelector().getSelectedComponents().iterator().next(); diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getfile/selectors/FastestPillarSelectorForGetFile.java b/bitrepository-client/src/main/java/org/bitrepository/access/getfile/selectors/FastestPillarSelectorForGetFile.java index 67064ccaa..64cd19187 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getfile/selectors/FastestPillarSelectorForGetFile.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getfile/selectors/FastestPillarSelectorForGetFile.java @@ -5,16 +5,16 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -29,16 +29,16 @@ import org.bitrepository.common.utils.TimeMeasurementUtils; /** - * GetFile specific selector for situations, when the getFile can chose between multiple pillars. The selector will - * chose the pillar able to return a file fastest, eg. the timeToDeliver id is the smallest. + * GetFile specific selector for situations where the GetFile method can choose between multiple pillars. The selector will + * choose the pillar able to return the file fastest, i.e. where the timeToDeliver ID is the smallest. */ public class FastestPillarSelectorForGetFile extends ComponentSelector { private TimeMeasureTYPE fastestTimeToDeliver; - @Override + @Override public synchronized void selectComponent(MessageResponse message) throws UnexpectedResponseException { - IdentifyPillarsForGetFileResponse response = (IdentifyPillarsForGetFileResponse)message; - if (fastestTimeToDeliver == null ) { + IdentifyPillarsForGetFileResponse response = (IdentifyPillarsForGetFileResponse) message; + if (fastestTimeToDeliver == null) { fastestTimeToDeliver = response.getTimeToDeliver(); } if (isFaster(response)) { diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getfile/selectors/SelectedPillarForGetFileInfo.java b/bitrepository-client/src/main/java/org/bitrepository/access/getfile/selectors/SelectedPillarForGetFileInfo.java deleted file mode 100644 index 6e6e25800..000000000 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getfile/selectors/SelectedPillarForGetFileInfo.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * #%L - * Bitrepository Access - * %% - * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * #L% - */ -package org.bitrepository.access.getfile.selectors; - -import org.bitrepository.bitrepositoryelements.TimeMeasureTYPE; -import org.bitrepository.client.conversation.selector.SelectedComponentInfo; - -/** - * Container for information about a pillar which as been identified and are marked as - * selected for a GetFile request. - */ -public class SelectedPillarForGetFileInfo extends SelectedComponentInfo { - /** @see #getTimeToDeliver() */ - private final TimeMeasureTYPE timeToDeliver; - - /** - * Delegates to SelectedPillarInfo construct. - * @see #getTimeToDeliver() - * @param pillarID The ID of the pillar - * @param pillarTopic The pillar specific topic - * @param timeToDeliver The time the pillar is to start delivery - */ - public SelectedPillarForGetFileInfo(String pillarID, String pillarTopic, TimeMeasureTYPE timeToDeliver) { - super(pillarID, pillarTopic); - this.timeToDeliver = timeToDeliver; - } - - /** - * @return The estimated time to deliver for the selected pillar as specified in the identify response. - */ - public TimeMeasureTYPE getTimeToDeliver() { - return timeToDeliver; - } -} \ No newline at end of file diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/BlockingGetFileIDsClient.java b/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/BlockingGetFileIDsClient.java index 03e487626..af39f2280 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/BlockingGetFileIDsClient.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/BlockingGetFileIDsClient.java @@ -1,32 +1,29 @@ /* * #%L * Bitmagasin modify client - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.access.getfileids; -import java.net.URL; -import java.util.List; - import org.bitrepository.access.ContributorQuery; import org.bitrepository.client.eventhandler.BlockingEventHandler; import org.bitrepository.client.eventhandler.ContributorEvent; @@ -34,8 +31,11 @@ import org.bitrepository.client.eventhandler.OperationEvent; import org.bitrepository.client.exceptions.NegativeResponseException; +import java.net.URL; +import java.util.List; + /** - * Wrappes a PutFileClient to provide a blocking client. The client will block until the PutFileOperation + * Wraps a PutFileClient to provide a blocking client. The client will block until the PutFileOperation * has finished. */ public class BlockingGetFileIDsClient { @@ -46,24 +46,24 @@ public BlockingGetFileIDsClient(GetFileIDsClient client) { } /** - * @see GetFileIDsClient#getFileIDs - * @param collectionID The ID of the collection + * @param collectionID The ID of the collection * @param contributorQueries The {@link ContributorQuery} for the GetFileIDs request - * @param fileID The ID of the file that the request is about - * @param addressForResult The address of where to deliver the result - * @param eventHandler The event handler to handle incoming events - * @return The list of {@link ContributorEvent}'s + * @param fileID The ID of the file that the request is about + * @param addressForResult The address of where to deliver the result + * @param eventHandler The event handler to handle incoming events + * @return The list of {@link ContributorEvent}'s * @throws NegativeResponseException if the operation failed + * @see GetFileIDsClient#getFileIDs */ - public List getGetFileIDs( - String collectionID, - ContributorQuery[] contributorQueries, - String fileID, - URL addressForResult, - EventHandler eventHandler) - throws NegativeResponseException { + public List getGetFileIDs(String collectionID, ContributorQuery[] contributorQueries, String fileID, + URL addressForResult, EventHandler eventHandler) throws NegativeResponseException { BlockingEventHandler blocker = new BlockingEventHandler(eventHandler); client.getFileIDs(collectionID, contributorQueries, fileID, addressForResult, blocker); - return getContributorEvents(blocker); + OperationEvent finishEvent = blocker.awaitFinished(); + if (finishEvent.getEventType().equals(OperationEvent.OperationEventType.COMPLETE)) { + return blocker.getResults(); + } else if (finishEvent.getEventType().equals(OperationEvent.OperationEventType.FAILED)) { + throw new NegativeResponseException(finishEvent.getInfo(), null); + } else throw new RuntimeException("Received unexpected event type" + finishEvent); } } diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/ConversationBasedGetFileIDsClient.java b/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/ConversationBasedGetFileIDsClient.java index 7950e05a6..07b1e2d4b 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/ConversationBasedGetFileIDsClient.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/ConversationBasedGetFileIDsClient.java @@ -1,23 +1,23 @@ /* * #%L * Bitrepository Access - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -44,46 +44,38 @@ /** * The reference implementation of the client side of the GetFileIDs identification and operation. * The default GetFileIDsClient - * - * This class is just a thin wrapper which creates a conversion each time a operation is started. The conversations - * takes over the rest of the operation handling. + *

+ * This class is just a thin wrapper which creates a conversion each time a operation is started. */ public class ConversationBasedGetFileIDsClient extends AbstractClient implements GetFileIDsClient { private final Logger log = LoggerFactory.getLogger(getClass()); /** - * @see AbstractClient - * @param messageBus The message bus used in the communication + * @param messageBus The message bus used in the communication * @param conversationMediator The {@link ConversationMediator} used to keep track of conversations - * @param settings The settings for the client - * @param clientID The ID of the client + * @param settings The settings for the client + * @param clientID The ID of the client + * @see AbstractClient */ - public ConversationBasedGetFileIDsClient(MessageBus messageBus, ConversationMediator conversationMediator, - Settings settings, String clientID) { + public ConversationBasedGetFileIDsClient(MessageBus messageBus, ConversationMediator conversationMediator, Settings settings, + String clientID) { super(settings, conversationMediator, messageBus, clientID); } @Override - public void getFileIDs( - String collectionID, - ContributorQuery[] contributorQueries, - String fileID, - URL addressForResult, - EventHandler eventHandler) { + public void getFileIDs(String collectionID, ContributorQuery[] contributorQueries, String fileID, URL addressForResult, + EventHandler eventHandler) { ArgumentValidator.checkNotNullOrEmpty(collectionID, "collectionID"); validateFileID(fileID); if (contributorQueries == null) { - contributorQueries = ContributorQueryUtils.createFullContributorQuery( - SettingsUtils.getPillarIDsForCollection(collectionID)); + contributorQueries = ContributorQueryUtils.createFullContributorQuery(SettingsUtils.getPillarIDsForCollection(collectionID)); } - log.info("Requesting the fileIDs for file '" + fileID + "' with query "+ - Arrays.asList(contributorQueries) + ". " + - (addressForResult != null ? "The result should be uploaded to '" + addressForResult + "'." : "")); + log.info("Requesting the fileIDs for file '" + fileID + "' with query " + Arrays.asList(contributorQueries) + ". " + + (addressForResult != null ? "The result should be uploaded to '" + addressForResult + "'." : "")); - GetFileIDsConversationContext context = new GetFileIDsConversationContext( - collectionID, contributorQueries, fileID, addressForResult, settings, messageBus, clientID, - ContributorQueryUtils.getContributors(contributorQueries), eventHandler); + GetFileIDsConversationContext context = new GetFileIDsConversationContext(collectionID, contributorQueries, fileID, + addressForResult, settings, messageBus, clientID, ContributorQueryUtils.getContributors(contributorQueries), eventHandler); startConversation(context, new IdentifyPillarsForGetFileIDs(context)); } diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/GetFileIDsClient.java b/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/GetFileIDsClient.java index 91776c1ed..c924220c4 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/GetFileIDsClient.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/GetFileIDsClient.java @@ -8,32 +8,32 @@ * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.access.getfileids; -import java.net.URL; - import org.bitrepository.access.ContributorQuery; import org.bitrepository.client.eventhandler.EventHandler; +import java.net.URL; + /** - * Interface for GetFileIDs client exposing the bit repository org.bitrepository.org.bitrepository.protocol GetFileIDs functionality. + * Interface for GetFileIDs client exposing the GetFileIDs functionality. */ public interface GetFileIDsClient { - + /** * Method for requesting a given list of FileIDs from the pillars. Thus requesting validation of the existence of * the files at the given pillars. @@ -46,21 +46,17 @@ public interface GetFileIDsClient { * Since every pillar cannot upload their fileids to the same URL, it is extended with the pillarID for the given * pillar, e.g.: 'http://upload.url/mypath' + '-pillarID'. *

- * The results are returned through as an special event through the eventHandler, the FileIDsCompletePillarCompete. + * The results are returned through as an special event through the eventHandler, the FileIDsCompletePillarCompete. * - * @param collectionID Identifies the collection the fileIDs should be retrived from. - * @param contributorQueries Defines which fileIDs to retrieve. If null all fileIDs from all contributers are + * @param collectionID Identifies the collection the fileIDs should be retrieved from. + * @param contributorQueries Defines which fileIDs to retrieve. If null all fileIDs from all contributors are * returned. Note that - * @param fileID The optional fileID to retrieve file information for. If null file information are - * retrieved for all files. - * @param addressForResult The address for delivering the results of the operation. If this is null, then it is - * returned through the messages. - * @param eventHandler The eventHandler to keep track of the operation. + * @param fileID The optional fileID to retrieve file information for. If null file information are + * retrieved for all files. + * @param addressForResult The address for delivering the results of the operation. If this is null, then it is + * returned through the messages. + * @param eventHandler The eventHandler to keep track of the operation. */ - void getFileIDs( - String collectionID, - ContributorQuery[] contributorQueries, - String fileID, - URL addressForResult, - EventHandler eventHandler); + void getFileIDs(String collectionID, ContributorQuery[] contributorQueries, String fileID, URL addressForResult, + EventHandler eventHandler); } diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/conversation/FileIDsCompletePillarEvent.java b/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/conversation/FileIDsCompletePillarEvent.java index 64ef2debd..0963f3440 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/conversation/FileIDsCompletePillarEvent.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/conversation/FileIDsCompletePillarEvent.java @@ -1,23 +1,23 @@ /* * #%L * Bitrepository Access - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -28,17 +28,16 @@ import org.bitrepository.client.eventhandler.ContributorCompleteEvent; /** -* Contains the result of a GetFileIDs request sent to a single pillar. -*/ + * Contains the result of a GetFileIDs request sent to a single pillar. + */ public class FileIDsCompletePillarEvent extends ContributorCompleteEvent { - /** The result from the pillar.*/ - private final ResultingFileIDs result; + private final ResultingFileIDs result; // The Result from the pillar. private final boolean isPartialResult; /** - * @param pillarID The pillar which generated the result - * @param collectionID The ID of the collection - * @param result The result returned by the pillar. + * @param pillarID The pillar which generated the result + * @param collectionID The ID of the collection + * @param result The result returned by the pillar. * @param isPartialResult Indication if the event contains partial results */ public FileIDsCompletePillarEvent(String pillarID, String collectionID, ResultingFileIDs result, boolean isPartialResult) { @@ -55,7 +54,7 @@ public ResultingFileIDs getFileIDs() { } /** - * @return Indication if the results are partial + * @return Indication if the results are partial */ public boolean isPartialResult() { return isPartialResult; @@ -66,11 +65,10 @@ public String additionalInfo() { StringBuilder infoSB = new StringBuilder(super.additionalInfo()); if (result != null && result.getFileIDsData() != null) { - infoSB.append(", NumberOfFileIDs=" + - result.getFileIDsData().getFileIDsDataItems().getFileIDsDataItem().size()); + infoSB.append(", NumberOfFileIDs=").append(result.getFileIDsData().getFileIDsDataItems().getFileIDsDataItem().size()); } - infoSB.append(", PartialResult=" + isPartialResult); + infoSB.append(", PartialResult=").append(isPartialResult); return infoSB.toString(); } } diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/conversation/GetFileIDsConversationContext.java b/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/conversation/GetFileIDsConversationContext.java index c896706bf..c3c599e05 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/conversation/GetFileIDsConversationContext.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/conversation/GetFileIDsConversationContext.java @@ -5,25 +5,22 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.access.getfileids.conversation; -import java.net.URL; -import java.util.Collection; - import org.bitrepository.access.ContributorQuery; import org.bitrepository.client.conversation.ConversationContext; import org.bitrepository.client.eventhandler.EventHandler; @@ -31,6 +28,9 @@ import org.bitrepository.protocol.OperationType; import org.bitrepository.protocol.messagebus.MessageSender; +import java.net.URL; +import java.util.Collection; + /** * Encapsulates the context for a GetFileIDs operation. */ @@ -41,19 +41,20 @@ public class GetFileIDsConversationContext extends ConversationContext { /** * Extends the {@link ConversationContext} constructor with * {@link org.bitrepository.access.getfileids.GetFileIDsClient} specific parameters. - * @param collectionID The ID for the collection + * + * @param collectionID The ID for the collection * @param contributorQueries See {@link org.bitrepository.access.getfileids.GetFileIDsClient} for details. - * @param fileID The ID of the file to get - * @param urlForResult See {@link org.bitrepository.access.getfileids.GetFileIDsClient} for details. - * @param settings The settings for the context - * @param messageSender MessageSender to send messages - * @param clientID The ID of the client - * @param contributors The expected contributors - * @param eventHandler EventHandler to handle incoming events + * @param fileID The ID of the file to get + * @param urlForResult See {@link org.bitrepository.access.getfileids.GetFileIDsClient} for details. + * @param settings The settings for the context + * @param messageSender MessageSender to send messages + * @param clientID The ID of the client + * @param contributors The expected contributors + * @param eventHandler EventHandler to handle incoming events */ public GetFileIDsConversationContext(String collectionID, ContributorQuery[] contributorQueries, String fileID, - URL urlForResult, Settings settings, MessageSender messageSender, String clientID, - Collection contributors, EventHandler eventHandler) { + URL urlForResult, Settings settings, MessageSender messageSender, String clientID, + Collection contributors, EventHandler eventHandler) { super(collectionID, OperationType.GET_FILE_IDS, settings, messageSender, clientID, fileID, contributors, eventHandler, null); this.contributorQueries = contributorQueries; @@ -61,14 +62,14 @@ public GetFileIDsConversationContext(String collectionID, ContributorQuery[] con } /** - * @return The contextual {@link ContributorQuery}'s + * @return The contextual {@link ContributorQuery}'s */ public ContributorQuery[] getContributorQueries() { return contributorQueries; } /** - * @return The URL where the results are placed (if using URL delivery) + * @return The URL where the results are placed (if using URL delivery) */ public URL getUrlForResult() { return urlForResult; diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/conversation/GettingFileIDs.java b/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/conversation/GettingFileIDs.java index 1c849be8c..a21a339bc 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/conversation/GettingFileIDs.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/conversation/GettingFileIDs.java @@ -39,9 +39,9 @@ /** * Models the behavior of a GetFileIDs conversation during the operation phase. That is, it begins with the - * sending of GetFileIDsRequest messages and finishes with on the reception of the - * GetFileIDsFinalResponse messages from the responding pillars. - *

+ * sending of {@link GetFileIDsRequest} messages and finishes with on the reception of the + * {@link GetFileIDsFinalResponse} messages from the responding pillars. + *

* Note that this is only used by the GetFileIDsConversation in the same package, therefore the visibility is package * protected. */ diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/conversation/IdentifyPillarsForGetFileIDs.java b/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/conversation/IdentifyPillarsForGetFileIDs.java index 5a1e7c229..4f4c0b31b 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/conversation/IdentifyPillarsForGetFileIDs.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getfileids/conversation/IdentifyPillarsForGetFileIDs.java @@ -1,23 +1,23 @@ /* * #%L * Bitrepository Access - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -51,7 +51,7 @@ protected void sendRequest() { msg.setFileIDs(FileIDsUtils.createFileIDs(context.getFileID())); msg.setDestination(context.getSettings().getCollectionDestination()); context.getMessageSender().sendMessage(msg); - context.getMonitor().identifyRequestSent("Identifying contributers for get fileIDs"); + context.getMonitor().identifyRequestSent("Identifying contributors for get fileIDs"); } @Override diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getstatus/ConversationBasedGetStatusClient.java b/bitrepository-client/src/main/java/org/bitrepository/access/getstatus/ConversationBasedGetStatusClient.java index 5f1efa6f7..ca6197979 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getstatus/ConversationBasedGetStatusClient.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getstatus/ConversationBasedGetStatusClient.java @@ -5,16 +5,16 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getstatus/GetStatusClient.java b/bitrepository-client/src/main/java/org/bitrepository/access/getstatus/GetStatusClient.java index 79340eaaf..60e83a7ba 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getstatus/GetStatusClient.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getstatus/GetStatusClient.java @@ -5,33 +5,33 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.access.getstatus; -import org.bitrepository.client.BitrepositoryClient; +import org.bitrepository.client.BitRepositoryClient; import org.bitrepository.client.eventhandler.EventHandler; -public interface GetStatusClient extends BitrepositoryClient { - +public interface GetStatusClient extends BitRepositoryClient { + /** - * Method for retrieving statuses for all components in the system. - * - * The method will return as soon as the communication has been setup. + * Method for retrieving statuses for all components in the system. + *

+ * The method will return as soon as the communication has been initialized. * - * @param eventHandler The handler which should receive notifications of the progress events. + * @param eventHandler The handler which should receive notifications of the progress events. */ void getStatus(EventHandler eventHandler); diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getstatus/conversation/GetStatusConversationContext.java b/bitrepository-client/src/main/java/org/bitrepository/access/getstatus/conversation/GetStatusConversationContext.java index 30ace5c0a..70d4da524 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getstatus/conversation/GetStatusConversationContext.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getstatus/conversation/GetStatusConversationContext.java @@ -5,29 +5,30 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.access.getstatus.conversation; -import java.util.Collection; import org.bitrepository.client.conversation.ConversationContext; import org.bitrepository.client.eventhandler.EventHandler; import org.bitrepository.common.settings.Settings; import org.bitrepository.protocol.OperationType; import org.bitrepository.protocol.messagebus.MessageSender; +import java.util.Collection; + public class GetStatusConversationContext extends ConversationContext { public GetStatusConversationContext(Settings settings, MessageSender messageSender, EventHandler eventHandler, diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getstatus/conversation/GettingStatus.java b/bitrepository-client/src/main/java/org/bitrepository/access/getstatus/conversation/GettingStatus.java index 08f21ae45..5aea763ed 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getstatus/conversation/GettingStatus.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getstatus/conversation/GettingStatus.java @@ -5,45 +5,45 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.access.getstatus.conversation; -import java.util.Collection; import org.bitrepository.bitrepositorymessages.GetStatusFinalResponse; import org.bitrepository.bitrepositorymessages.GetStatusRequest; import org.bitrepository.bitrepositorymessages.MessageResponse; import org.bitrepository.client.conversation.ConversationContext; import org.bitrepository.client.conversation.PerformingOperationState; import org.bitrepository.client.conversation.selector.SelectedComponentInfo; -import org.bitrepository.client.exceptions.UnexpectedResponseException; + +import java.util.Collection; public class GettingStatus extends PerformingOperationState { private final GetStatusConversationContext context; - /* - * @param context The conversation context. - * @param contributors The list of components the fileIDs should be collected from. - */ + /** + * @param context The conversation context. + * @param contributors The list of components the fileIDs should be collected from. + */ public GettingStatus(GetStatusConversationContext context, Collection contributors) { super(contributors); this.context = context; } @Override - protected void generateContributorCompleteEvent(MessageResponse msg) throws UnexpectedResponseException { + protected void generateContributorCompleteEvent(MessageResponse msg) { GetStatusFinalResponse response = (GetStatusFinalResponse) msg; getContext().getMonitor().contributorComplete( new StatusCompleteContributorEvent(msg.getFrom(), response.getCollectionID(), response.getResultingStatus())); @@ -52,7 +52,7 @@ protected void generateContributorCompleteEvent(MessageResponse msg) throws Unex @Override protected void sendRequest() { context.getMonitor().requestSent("Sending GetStatusRequest", activeContributors.keySet().toString()); - for(String ID : activeContributors.keySet()) { + for (String ID : activeContributors.keySet()) { GetStatusRequest request = new GetStatusRequest(); initializeMessage(request); request.setContributor(ID); diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getstatus/conversation/IdentifyingContributorsForGetStatus.java b/bitrepository-client/src/main/java/org/bitrepository/access/getstatus/conversation/IdentifyingContributorsForGetStatus.java index 5fd66c7c6..c42a2c0fb 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getstatus/conversation/IdentifyingContributorsForGetStatus.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getstatus/conversation/IdentifyingContributorsForGetStatus.java @@ -5,16 +5,16 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -33,17 +33,17 @@ public IdentifyingContributorsForGetStatus(GetStatusConversationContext context) super(context.getContributors()); this.context = context; } - + @Override protected void sendRequest() { IdentifyContributorsForGetStatusRequest request = new IdentifyContributorsForGetStatusRequest(); initializeMessage(request); request.setDestination(context.getSettings().getCollectionDestination()); - + context.getMonitor().identifyRequestSent("Identifying contributors for getting status"); context.getMessageSender().sendMessage(request); } - + @Override protected ConversationContext getContext() { return context; diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/getstatus/conversation/StatusCompleteContributorEvent.java b/bitrepository-client/src/main/java/org/bitrepository/access/getstatus/conversation/StatusCompleteContributorEvent.java index f45b830ca..98cdc2ccb 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/getstatus/conversation/StatusCompleteContributorEvent.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/getstatus/conversation/StatusCompleteContributorEvent.java @@ -5,16 +5,16 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -29,27 +29,30 @@ */ public class StatusCompleteContributorEvent extends ContributorCompleteEvent { - /** The status for the contributor.*/ + /** + * The status for the contributor. + */ private final ResultingStatus status; - + /** * Constructor. + * * @param contributorID The ID of the contributor - * @param collectionID The ID of the collection - * @param status The status for the contributor. + * @param collectionID The ID of the collection + * @param status The status for the contributor. */ public StatusCompleteContributorEvent(String contributorID, String collectionID, ResultingStatus status) { super(contributorID, collectionID); this.status = status; } - + /** * @return The status of for the contributor. */ public ResultingStatus getStatus() { return status; } - + @Override public String additionalInfo() { return super.additionalInfo() + ", resulting status: " + status; diff --git a/bitrepository-client/src/main/java/org/bitrepository/access/package-info.java b/bitrepository-client/src/main/java/org/bitrepository/access/package-info.java index ce9a78975..6a076760b 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/access/package-info.java +++ b/bitrepository-client/src/main/java/org/bitrepository/access/package-info.java @@ -1,29 +1,29 @@ /* * #%L - * Bitrepository Access Client - * + * BitRepository Access Client + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ /** - * Contains functionality for reading from a Bitrepository system. + * Contains functionality for reading from a BitRepository system. * This includes Get File, Get Checksums and Get File IDs. */ package org.bitrepository.access; \ No newline at end of file diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/AbstractClient.java b/bitrepository-client/src/main/java/org/bitrepository/client/AbstractClient.java index 05064f159..26a1be28d 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/AbstractClient.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/AbstractClient.java @@ -1,23 +1,23 @@ /* * #%L * Bitrepository Protocol - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -38,24 +38,35 @@ /** * Implements the generic functionality for a reference client */ -public class AbstractClient implements BitrepositoryClient { - /** The settings for this instance.*/ +public class AbstractClient implements BitRepositoryClient { + /** + * The settings for this instance. + */ protected final Settings settings; - /** The messagebus for communication.*/ + /** + * The messageBus for communication. + */ protected final MessageBus messageBus; - /** The mediator which should manage the conversations. */ + /** + * The mediator which should manage the conversations. + */ protected final String clientID; - /** The mediator which should manage the conversations. */ + /** + * The mediator which should manage the conversations. + */ private final ConversationMediator conversationMediator; - /** The FileIDValidator.*/ + /** + * The FileIDValidator. + */ private final FileIDValidator validator; - + /** * Constructor. - * @param settings The settings. + * + * @param settings The settings. * @param conversationMediator The mediator. - * @param messageBus The messagebus. - * @param clientID The id of the client. + * @param messageBus The messageBus. + * @param clientID The id of the client. */ public AbstractClient(Settings settings, ConversationMediator conversationMediator, MessageBus messageBus, String clientID) { ArgumentValidator.checkNotNull(clientID, "clientID"); @@ -66,18 +77,20 @@ public AbstractClient(Settings settings, ConversationMediator conversationMediat validator = new FileIDValidator(settings); SettingsUtils.initialize(settings); } - + /** * Validates the id of a file. + * * @param fileID The file id to validate. */ protected void validateFileID(String fileID) { validator.checkFileID(fileID); } - + /** * Starts the conversation. - * @param context The context for the new conversion. + * + * @param context The context for the new conversion. * @param startState The starting state */ protected void startConversation(ConversationContext context, GeneralConversationState startState) { diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/BitrepositoryClient.java b/bitrepository-client/src/main/java/org/bitrepository/client/BitRepositoryClient.java similarity index 93% rename from bitrepository-client/src/main/java/org/bitrepository/client/BitrepositoryClient.java rename to bitrepository-client/src/main/java/org/bitrepository/client/BitRepositoryClient.java index 1f75fdea3..aa83f7901 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/BitrepositoryClient.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/BitRepositoryClient.java @@ -1,23 +1,23 @@ /* * #%L * Bitrepository Protocol - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -27,5 +27,5 @@ /** * Defines the general functionality of Bit Repository reference client classes. */ -public interface BitrepositoryClient { +public interface BitRepositoryClient { } diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/CommandLineSettingsProvider.java b/bitrepository-client/src/main/java/org/bitrepository/client/CommandLineSettingsProvider.java index f95d8f23e..e4cb8b300 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/CommandLineSettingsProvider.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/CommandLineSettingsProvider.java @@ -5,16 +5,16 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -31,10 +31,9 @@ public class CommandLineSettingsProvider extends SettingsProvider { /** * Creates a SettingsProvider which will use the provided SettingsLoader for loading the * settings. - * Sets the componentID to one generated by a ComponentIDFactory depending on what is set in + * Sets the componentID to one generated by a ComponentIDFactory depending on what is set in * ReferenceSettings - ClientSettings - ComponentIDFactory. - * If none ComponentIDFactory is set, the default is to use DefaultCommandlineComponentID - * + * If none ComponentIDFactory is set, the default is to use DefaultCommandlineComponentID * * @param settingsReader Use for loading the settings. */ @@ -47,9 +46,9 @@ protected String getComponentID(ReferenceSettings referenceSettings) { if (referenceSettings.getClientSettings().getComponentIDFactoryClass() != null) { componentIDFactoryClass = referenceSettings.getClientSettings().getComponentIDFactoryClass(); } - + ComponentIDHelper helper = new ComponentIDHelper(componentIDFactoryClass); - + return helper.getComponentID(); } } diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/componentid/ComponentIDFactory.java b/bitrepository-client/src/main/java/org/bitrepository/client/componentid/ComponentIDFactory.java index ab3ea70b3..191898222 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/componentid/ComponentIDFactory.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/componentid/ComponentIDFactory.java @@ -8,12 +8,12 @@ * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * + * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . @@ -22,10 +22,10 @@ package org.bitrepository.client.componentid; /** - * Defines the interface for implementing the generation of client IDs + * Defines the interface for implementing the generation of client IDs */ public interface ComponentIDFactory { - + String getComponentID(); } diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/componentid/ComponentIDHelper.java b/bitrepository-client/src/main/java/org/bitrepository/client/componentid/ComponentIDHelper.java index bdd60c0c2..3cb49be41 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/componentid/ComponentIDHelper.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/componentid/ComponentIDHelper.java @@ -1,39 +1,37 @@ /* -* #%L + * #%L * * Bitmagasin integrationstest - * + * * %% * Copyright (C) 2010 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% -*/ + */ package org.bitrepository.client.componentid; -import org.bitrepository.client.componentid.ComponentIDFactory; -import org.bitrepository.client.componentid.DefaultCommandlineComponentID; - /** * Provides destination utilities. */ public class ComponentIDHelper { - private ComponentIDFactory clientIDFactory; + private final ComponentIDFactory clientIDFactory; /** * Create a ClientIDHelper object with the specified charactaristica + * * @param clientIDFactoryClass The class to use for constructing clientID. */ public ComponentIDHelper(String clientIDFactoryClass) { @@ -52,7 +50,7 @@ private ComponentIDFactory createClientIDFactory(String clientIDFactoryClass) { return new DefaultCommandlineComponentID(); } else { try { - return (ComponentIDFactory)Class.forName(clientIDFactoryClass).getDeclaredConstructor().newInstance(); + return (ComponentIDFactory) Class.forName(clientIDFactoryClass).getDeclaredConstructor().newInstance(); } catch (Exception e) { throw new RuntimeException("Unable to instantiate ClientIDFactory " + clientIDFactoryClass + diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/componentid/DefaultCommandlineComponentID.java b/bitrepository-client/src/main/java/org/bitrepository/client/componentid/DefaultCommandlineComponentID.java index 29e139ee3..e535c298a 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/componentid/DefaultCommandlineComponentID.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/componentid/DefaultCommandlineComponentID.java @@ -8,12 +8,12 @@ * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * + * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . @@ -21,10 +21,8 @@ */ package org.bitrepository.client.componentid; -import org.bitrepository.client.componentid.ComponentIDFactory; - /** - * Delivers the default commandline client ID. + * Delivers the default commandline client ID. */ public class DefaultCommandlineComponentID implements ComponentIDFactory { diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/componentid/UniqueCommandlineComponentID.java b/bitrepository-client/src/main/java/org/bitrepository/client/componentid/UniqueCommandlineComponentID.java index 626edcd9c..af0ed0e11 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/componentid/UniqueCommandlineComponentID.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/componentid/UniqueCommandlineComponentID.java @@ -8,12 +8,12 @@ * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * + * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . @@ -25,10 +25,8 @@ import java.net.InetAddress; import java.net.UnknownHostException; -import org.bitrepository.client.componentid.ComponentIDFactory; - /** - * Delivers a client ID that is unique to the host, user and process that runs the client. + * Delivers a client ID that is unique to the host, user and process that runs the client. */ public class UniqueCommandlineComponentID implements ComponentIDFactory { @@ -36,10 +34,10 @@ public class UniqueCommandlineComponentID implements ComponentIDFactory { public String getComponentID() { try { String hostname = InetAddress.getLocalHost().getHostName(); - String username = System.getProperty("user.name"); + String username = System.getProperty("user.name"); String PID = ManagementFactory.getRuntimeMXBean().getName().split("@")[0]; - - return hostname + "-" + username + "-" + PID; + + return hostname + "-" + username + "-" + PID; } catch (UnknownHostException e) { throw new RuntimeException("Failed to lookup hostname", e); } diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/conversation/Conversation.java b/bitrepository-client/src/main/java/org/bitrepository/client/conversation/Conversation.java index 2aa1774af..3d3e763be 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/conversation/Conversation.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/conversation/Conversation.java @@ -1,23 +1,23 @@ /* * #%L * Bitrepository Protocol - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -29,46 +29,49 @@ /** * A conversation models the messaging based workflow used to accomplish a operation called on a client interface. - * + *

* The interface primarily consists of sending and receiving message functionality. - * + * *

Implementation considerations

- * + *

* The following concerns needs to be addressed by classes implementing this interface. - * + * *

Threadsafe

- * Note that conversation needs to be thread safe as multiple messages and timer event may occur in parallel. - * + * Note that conversation needs to be thread safe as multiple messages and timer event may occur in parallel. + * *

Timeouts

* The conversation implementation should include timeouts for the different conversation phases. - * + * *

Error handling

- * As conversation will normally be called in either a asynchronously manor using a callback listener or synchronous, - * the error handling needs to behave differently in the two cases. This means a error handling block will typically - * contain a if (callbackListener == null) { ... } else {...} block. + * As a conversation will normally be called in either an asynchronous way, using a callback listener, or synchronous; + * the error handling needs to behave differently in the two cases. This means an error handling block will typically + * contain a + *

if (callbackListener == null) { ... } else {...}

+ * block. */ public interface Conversation extends MessageListener { /** * Get the conversation ID for this conversation. - * + *

* Implementations must ensure that conversation IDs are unique, and that this ID is always used when sending * messages. * * @return The conversation ID. */ String getConversationID(); - + /** * Returns the start time for the conversation. Main use is to timeout conversations, which have lasted too long. + * * @return The start time of the conversation as set by the System.currentTimeMillis(). */ long getStartTime(); - + /** * Starts the conversation. */ void startConversation(); - + /** * Ends the conversation. This means setting any relevant conversation state. */ @@ -81,10 +84,11 @@ public interface Conversation extends MessageListener { * @return Whether this conversation has ended. */ boolean hasEnded(); - + /** - * Can be used to fail an conversation. This might be caused by a timeout or other event. - * @param operationFailedEvent Contains information regarding the cause for the failure. + * Can be used to fail a conversation. This might be caused by a timeout or other event. + * + * @param operationFailedEvent Contains information regarding the cause for the failure. */ void failConversation(OperationFailedEvent operationFailedEvent); } diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/conversation/ConversationEventMonitor.java b/bitrepository-client/src/main/java/org/bitrepository/client/conversation/ConversationEventMonitor.java index 86d70f300..3ad48f567 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/conversation/ConversationEventMonitor.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/conversation/ConversationEventMonitor.java @@ -1,91 +1,85 @@ /* * #%L * Bitrepository Protocol - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.client.conversation; -import java.util.Collection; -import java.util.LinkedList; -import java.util.List; - import org.bitrepository.bitrepositoryelements.ResponseCode; import org.bitrepository.bitrepositorymessages.Message; import org.bitrepository.bitrepositorymessages.MessageResponse; -import org.bitrepository.client.eventhandler.AbstractOperationEvent; -import org.bitrepository.client.eventhandler.CompleteEvent; -import org.bitrepository.client.eventhandler.ContributorCompleteEvent; -import org.bitrepository.client.eventhandler.ContributorEvent; -import org.bitrepository.client.eventhandler.ContributorFailedEvent; -import org.bitrepository.client.eventhandler.DefaultEvent; -import org.bitrepository.client.eventhandler.EventHandler; -import org.bitrepository.client.eventhandler.IdentificationCompleteEvent; -import org.bitrepository.client.eventhandler.OperationEvent; -import org.bitrepository.client.eventhandler.OperationFailedEvent; +import org.bitrepository.client.eventhandler.*; import org.bitrepository.protocol.OperationType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.bitrepository.client.eventhandler.OperationEvent.OperationEventType.COMPONENT_IDENTIFIED; -import static org.bitrepository.client.eventhandler.OperationEvent.OperationEventType.IDENTIFY_REQUEST_SENT; -import static org.bitrepository.client.eventhandler.OperationEvent.OperationEventType.IDENTIFY_TIMEOUT; -import static org.bitrepository.client.eventhandler.OperationEvent.OperationEventType.PROGRESS; -import static org.bitrepository.client.eventhandler.OperationEvent.OperationEventType.REQUEST_SENT; -import static org.bitrepository.client.eventhandler.OperationEvent.OperationEventType.WARNING; +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; + +import static org.bitrepository.client.eventhandler.OperationEvent.OperationEventType.*; /** * Encapsulates the concrete handling of conversation events. Should be called every time a conversation event happens. */ public class ConversationEventMonitor { - /** The general logger.*/ + /** + * The general logger. + */ private final ConversationLogger log; - /** The event logger. Adds context information to the log entry. */ + /** + * The event logger. Adds context information to the log entry. + */ private final Logger eventLogger = LoggerFactory.getLogger(getClass()); private final String collectionID; private final String conversationID; private final OperationType operationType; private final String fileID; private final EventHandler eventHandler; - /** Used to aggregate the conversation complete events, so these can be added to the final complete event. */ + /** + * Used to aggregate the conversation complete events, so these can be added to the final complete event. + */ private final List contributorCompleteEvents = new LinkedList<>(); - /** Used to aggregate the conversation failed events, so these can be added to the final failed event. */ + /** + * Used to aggregate the conversation failed events, so these can be added to the final failed event. + */ private final List contributorFailedEvents = new LinkedList<>(); /** * Indicated whether the final operation event should be a complete event or a failed event in case of individual * component failures. - */ + */ private boolean failOnComponentFailure = true; /** - * @param collectionID The Collection ID + * @param collectionID The Collection ID * @param conversationID Used for adding conversation context information to the information distributed. Will be * shorted to increase readability. - * @param operationType The operation type to include in the events og logs. - * @param fileID Optional file ID to include in the events and logs. - * @param eventHandler The eventHandler to send updates to. + * @param operationType The operation type to include in the events og logs. + * @param fileID Optional file ID to include in the events and logs. + * @param eventHandler The eventHandler to send updates to. */ - public ConversationEventMonitor(String collectionID, String conversationID, OperationType operationType, String fileID, - EventHandler eventHandler) { + public ConversationEventMonitor(String collectionID, String conversationID, OperationType operationType, String fileID, + EventHandler eventHandler) { log = new ConversationLogger(); this.collectionID = collectionID; this.conversationID = getShortConversationID(conversationID); @@ -95,156 +89,170 @@ public ConversationEventMonitor(String collectionID, String conversationID, Oper } /** - * Indicates a identify request has been sent to the contributors. + * Indicates that an identify request has been sent to the contributors. + * * @param info Description */ public void identifyRequestSent(String info) { - notifyEventListerners(createDefaultEvent(IDENTIFY_REQUEST_SENT, info)); + notifyEventListeners(createDefaultEvent(IDENTIFY_REQUEST_SENT, info)); } /** * Indicates a contributor has been identified and considered for selection. - * @param response The identify response. + * + * @param response An identify response. */ public void contributorIdentified(MessageResponse response) { - notifyEventListerners(createContributorEvent(COMPONENT_IDENTIFIED, null, response.getFrom())); + notifyEventListeners(createContributorEvent(COMPONENT_IDENTIFIED, null, response.getFrom())); } /** - * Indicates a identify request has timeout without all contributors responding. - * @param unrespondingContributors the unresponding contributors + * Indicates an identify request has timeout without all contributors responding. + * + * @param unresponsiveContributors The unresponsive contributors */ - public void identifyContributorsTimeout(Collection unrespondingContributors) { + public void identifyContributorsTimeout(Collection unresponsiveContributors) { StringBuilder failureMessage = new StringBuilder("Time has run out for looking up contributors"); - if (!unrespondingContributors.isEmpty()) { - failureMessage.append("\nThe following contributors didn't respond: " + unrespondingContributors); + if (!unresponsiveContributors.isEmpty()) { + failureMessage.append("\nThe following contributors didn't respond: ").append(unresponsiveContributors); } - notifyEventListerners(createDefaultEvent(IDENTIFY_TIMEOUT, failureMessage.toString())); + notifyEventListeners(createDefaultEvent(IDENTIFY_TIMEOUT, failureMessage.toString())); - for (String contributorID : unrespondingContributors) { + for (String contributorID : unresponsiveContributors) { contributorFailed("Timeout for identifying contributor", contributorID, null); } } /** * Indicates a contributor has been selected for a operation request. + * * @param contributorIDList The contributors identified */ public void contributorsSelected(List contributorIDList) { - notifyEventListerners(createContributorsIdentifiedEvent(contributorIDList)); + notifyEventListeners(createContributorsIdentifiedEvent(contributorIDList)); } /** * A request has been sent to a contributor. - * @param info Description of the context. + * + * @param info Description of the context. * @param contributorID The ID of the contributor */ public void requestSent(String info, String contributorID) { - notifyEventListerners(createContributorEvent(REQUEST_SENT, info, contributorID)); + notifyEventListeners(createContributorEvent(REQUEST_SENT, info, contributorID)); } /** * New information regarding the progress of the operation has been received + * * @param progressEvent Contains information regarding the progress */ public void progress(AbstractOperationEvent progressEvent) { addContextInfo(progressEvent); - notifyEventListerners(progressEvent); + notifyEventListeners(progressEvent); } /** * New information regarding the progress of the operation has been received - * @param progressInfo Contains information regarding the progress + * + * @param progressInfo Contains information regarding the progress * @param contributorID the contributor that is progressed */ public void progress(String progressInfo, String contributorID) { - notifyEventListerners(createContributorEvent(PROGRESS, progressInfo, contributorID)); + notifyEventListeners(createContributorEvent(PROGRESS, progressInfo, contributorID)); } - + /** - * Notify that a contributor has failed in a way resulting in a retry attempt. - * @param info Information regarding the retry attempt - * @param contributorID the contributor that is retried. + * Notify that a contributor has failed in a way resulting in a retry attempt. + * + * @param info Information regarding the retry attempt + * @param contributorID the contributor that is retried. */ public void retry(String info, String contributorID) { - notifyEventListerners(createContributorEvent(WARNING, info, contributorID)); + notifyEventListeners(createContributorEvent(WARNING, info, contributorID)); } /** * A pillar has completed the operation. + * * @param completeEvent Event containing any additional information regarding the completion. Might contain the - * return value from the operation, in which case the event will be a DefafaultEvent subclass. + * return value from the operation, in which case the event will be a DefaultEvent subclass. */ public void contributorComplete(ContributorCompleteEvent completeEvent) { contributorCompleteEvents.add(completeEvent); addContextInfo(completeEvent); - notifyEventListerners(completeEvent); + notifyEventListeners(completeEvent); } /** * A pillar has failed to handle a request successfully. - * @param info Cause information + * + * @param info Cause information * @param contributorID The ID of the contributor - * @param responseCode the response code of the contributor + * @param responseCode the response code of the contributor */ public void contributorFailed(String info, String contributorID, ResponseCode responseCode) { ContributorFailedEvent failedEvent = createContributorFailedEvent(info, contributorID, responseCode); contributorFailedEvents.add(failedEvent); - notifyEventListerners(failedEvent); + notifyEventListeners(failedEvent); } - + /** * Timeout contributors that have not responded in the performing state + * * @param contributorIDs The collection of IDs for the contributors */ public void timeoutRemainingContributors(Collection contributorIDs) { - for(String contributorID : contributorIDs) { - contributorFailed("Contributor timedout performing operation", contributorID, null); + for (String contributorID : contributorIDs) { + contributorFailed("Contributor timed out while performing operation", contributorID, null); } } /** - * An operation has completed. Will generate a failed event, if any of the contributers have failed. + * An operation has completed. Will generate a failed event, if any of the contributors have failed. */ public void complete() { if (contributorFailedEvents.isEmpty() || !failOnComponentFailure) { - notifyEventListerners(createCompleteEvent()); + notifyEventListeners(createCompleteEvent()); } else { String info = "Failed operation. Cause(s):\n" + contributorFailedEvents; - notifyEventListerners(createOperationFailedEvent(info)); + notifyEventListeners(createOperationFailedEvent(info)); } } /** * General failure to complete the operation. + * * @param info Encapsulates the cause. */ public void operationFailed(String info) { - notifyEventListerners(createOperationFailedEvent(info)); + notifyEventListeners(createOperationFailedEvent(info)); } /** * General failure to complete the operation. + * * @param event Encapsulates the cause. */ public void operationFailed(OperationFailedEvent event) { addContextInfo(event); - notifyEventListerners(event); + notifyEventListeners(event); } /** * An invalid messages has been received + * * @param message the invalid message - * @param e Description of the context + * @param e Description of the context */ public void invalidMessage(Message message, Exception e) { - log.warn("Received invalid " + message.getClass().getSimpleName() + " from " + message.getFrom() + - "\nMessage: " + message, e); - notifyEventListerners((createContributorEvent(WARNING, e.getMessage(), message.getFrom()))); + log.warn("Received invalid " + message.getClass().getSimpleName() + " from " + message.getFrom() + "\nMessage: " + message, e); + notifyEventListeners((createContributorEvent(WARNING, e.getMessage(), message.getFrom()))); } /** * A message has been received with isn't consistent with the current conversation state. + * * @param message the message */ public void outOfSequenceMessage(Message message) { @@ -253,26 +261,30 @@ public void outOfSequenceMessage(Message message) { /** * Signifies a non-fatal event + * * @param info Problem description */ public void warning(String info) { - notifyEventListerners(createDefaultEvent(WARNING, info)); + notifyEventListeners(createDefaultEvent(WARNING, info)); } /** * Signifies a non-fatal event + * * @param info Problem description - * @param e The cause + * @param e The cause */ public void warning(String info, Exception e) { if (e == null) { warning(info); + } else { + notifyEventListeners(createDefaultEvent(WARNING, info + ", " + e.getMessage())); } - notifyEventListerners(createDefaultEvent(WARNING, info + ", " + e.getMessage())); } /** * Logs debug information. + * * @param info The debug info to log. */ public void debug(String info) { @@ -281,17 +293,18 @@ public void debug(String info) { /** * Logs debug information. + * * @param info The debug info to log. - * @param e the Exception to log + * @param e the Exception to log */ public void debug(String info, Exception e) { log.debug(info, e); } /** - * @return a shorted conversationID. Only the first part up til the first '-' is used - * (but at least 4 long). * @param fullConversationID the full conversationID to shorten + * @return a shorted conversationID. Only the first part up til the first '-' is used + * (but at least 4 long). */ private String getShortConversationID(String fullConversationID) { return fullConversationID.substring(0, fullConversationID.indexOf("-", 4)); @@ -304,16 +317,16 @@ private DefaultEvent createDefaultEvent(OperationEvent.OperationEventType eventT addContextInfo(event); return event; } - private ContributorEvent createContributorEvent( - OperationEvent.OperationEventType eventType, String info, String contributorID) { + + private ContributorEvent createContributorEvent(OperationEvent.OperationEventType eventType, String info, String contributorID) { ContributorEvent event = new ContributorEvent(contributorID, collectionID); event.setEventType(eventType); event.setInfo(info); addContextInfo(event); return event; } - private ContributorFailedEvent createContributorFailedEvent(String info, String contributorID, - ResponseCode responseCode) { + + private ContributorFailedEvent createContributorFailedEvent(String info, String contributorID, ResponseCode responseCode) { ContributorFailedEvent event = new ContributorFailedEvent(contributorID, collectionID, responseCode); event.setInfo(info); addContextInfo(event); @@ -340,20 +353,21 @@ private CompleteEvent createCompleteEvent() { /** * Adds the general operation context information for the conversation to the event. + * * @param event the event to update - * @return the updated event */ - private AbstractOperationEvent addContextInfo(AbstractOperationEvent event) { + private void addContextInfo(AbstractOperationEvent event) { event.setConversationID(conversationID); event.setFileID(fileID); event.setOperationType(operationType); - return event; } + /** - * Indicates whether a operation should be consider failed because one or more of the contributors have failed. + * Indicates whether an operation should be considered failed because one or more of the contributors have failed. * This is true by default. - *

- * Note that the operation can be falied explicitly by calling the operationFailed method. + *

+ * Note that the operation can be failed explicitly by calling the operationFailed method. + * * @param failOnComponentFailure true if the conversation should be marked as failed if a contributor have failed */ public void markAsFailedOnContributorFailure(boolean failOnComponentFailure) { @@ -365,61 +379,71 @@ public void markAsFailedOnContributorFailure(boolean failOnComponentFailure) { */ protected class ConversationLogger { - /** Delegates to the normal logger debug + /** + * Delegates to the normal logger debug + * * @param msg the message to log - * */ + */ public void debug(String msg) { - eventLogger.debug(conversationID + ": " + contextInfo() + ":" +msg); + eventLogger.debug(conversationID + ": " + contextInfo() + ":" + msg); } - /** Delegates to the normal logger debug + /** + * Delegates to the normal logger debug + * * @param msg the message to log - * @param e the Exception to log - * */ + * @param e the Exception to log + */ public void debug(String msg, Exception e) { eventLogger.debug(conversationID + ": " + contextInfo() + ":" + msg, e); } - /** Delegates to the normal logger info + /** + * Delegates to the normal logger info + * * @param msg the message to log - * */ + */ public void info(String msg) { - eventLogger.info(conversationID + ": " + contextInfo() + ":" +msg); + eventLogger.info(conversationID + ": " + contextInfo() + ":" + msg); } - /** Delegates to the normal logger warn + /** + * Delegates to the normal logger warn + * * @param msg the message to log - * @param e throwable to log - * */ + * @param e throwable to log + */ public void warn(String msg, Throwable e) { - eventLogger.warn(conversationID + ": " + contextInfo() + ":" +msg, e); + eventLogger.warn(conversationID + ": " + contextInfo() + ":" + msg, e); } - /** Delegates to the normal logger warn + /** + * Delegates to the normal logger warn + * * @param msg the message to log - * */ + */ public void warn(String msg) { - eventLogger.warn(conversationID + ": " + contextInfo() + ":" +msg); + eventLogger.warn(conversationID + ": " + contextInfo() + ":" + msg); } private String contextInfo() { StringBuilder sb = new StringBuilder(); sb.append(operationType); if (fileID != null) { - sb.append(" for file " + fileID); + sb.append(" for file ").append(fileID); } return sb.toString(); } } - private void notifyEventListerners(OperationEvent event) { + private void notifyEventListeners(OperationEvent event) { eventLogger.trace(event.toString()); if (eventHandler != null) { try { eventHandler.handleEvent(event); } catch (Throwable thr) { - log.warn("The eventhandler (" + eventHandler + ") failed when called with event " + event, thr); + log.warn("The eventHandler (" + eventHandler + ") failed when called with event " + event, thr); } } } @@ -427,15 +451,9 @@ private void notifyEventListerners(OperationEvent event) { @Override public String toString() { - return "ConversationEventMonitor{" + - ", collectionID='" + collectionID + '\'' + - ", conversationID='" + conversationID + '\'' + - ", operationType=" + operationType + - ", fileID='" + fileID + '\'' + - ", eventHandler=" + eventHandler + - ", contributorCompleteEvents=" + contributorCompleteEvents + - ", contributorFailedEvents=" + contributorFailedEvents + - ", failOnComponentFailure=" + failOnComponentFailure + - '}'; + return "ConversationEventMonitor{" + ", collectionID='" + collectionID + '\'' + ", conversationID='" + conversationID + '\'' + + ", operationType=" + operationType + ", fileID='" + fileID + '\'' + ", eventHandler=" + eventHandler + + ", contributorCompleteEvents=" + contributorCompleteEvents + ", contributorFailedEvents=" + contributorFailedEvents + + ", failOnComponentFailure=" + failOnComponentFailure + '}'; } } diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/conversation/ConversationState.java b/bitrepository-client/src/main/java/org/bitrepository/client/conversation/ConversationState.java index d0543b3fd..a652900f4 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/conversation/ConversationState.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/conversation/ConversationState.java @@ -1,23 +1,23 @@ /* * #%L * Bitrepository Protocol - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -38,8 +38,9 @@ public interface ConversationState { /** * The general message handler for this state. Will only accept MessageResponses. - * Takes care of the general message bookkepping and delegates the specifics of the message handling to the + * Takes care of the general message bookkeeping and delegates the specifics of the message handling to the * concrete states. + * * @param message The message to handle. */ void handleMessage(Message message); diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/conversation/FinishedState.java b/bitrepository-client/src/main/java/org/bitrepository/client/conversation/FinishedState.java index ef7b6b9dc..f30a6ef79 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/conversation/FinishedState.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/conversation/FinishedState.java @@ -1,39 +1,40 @@ /* * #%L * Bitrepository Protocol - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.client.conversation; -import java.util.LinkedList; import org.bitrepository.bitrepositorymessages.MessageResponse; import org.bitrepository.common.exceptions.UnableToFinishException; +import java.util.LinkedList; + /** * Marker interface to indicate that this is the finished state for a conversation. */ public class FinishedState extends GeneralConversationState { protected final ConversationContext context; - + public FinishedState(ConversationContext context) { super(new LinkedList<>()); this.context = context; @@ -45,17 +46,14 @@ protected ConversationContext getContext() { } @Override - public void start(){} + public void start() {} @Override - protected GeneralConversationState completeState() throws UnableToFinishException { + protected GeneralConversationState completeState() { throw new UnsupportedOperationException("No state exists after finished state"); } @Override - /** - * Never timeout. - */ protected long getTimeoutValue() { return 0; } diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/conversation/GeneralConversationState.java b/bitrepository-client/src/main/java/org/bitrepository/client/conversation/GeneralConversationState.java index 17f691111..089d1d179 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/conversation/GeneralConversationState.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/conversation/GeneralConversationState.java @@ -70,7 +70,7 @@ protected GeneralConversationState(Collection expectedContributors) { */ public void start() { try { - if (!responseStatus.getOutstandComponents().isEmpty()) { + if (!responseStatus.getOutstandingComponents().isEmpty()) { if (getTimeoutValue() > 0) { scheduledTimeout = timer.schedule(new TimeoutHandler(), getTimeoutValue(), TimeUnit.MILLISECONDS); } @@ -176,7 +176,7 @@ protected void initializeMessage(MessageRequest msg) { * @return the list of components where a identify response hasn't been received. */ protected Collection getOutstandingComponents() { - return responseStatus.getOutstandComponents(); + return responseStatus.getOutstandingComponents(); } /** Must be implemented by subclasses to log informative timeout information diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/conversation/IdentifyingState.java b/bitrepository-client/src/main/java/org/bitrepository/client/conversation/IdentifyingState.java index a9a763eb3..8e596e76a 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/conversation/IdentifyingState.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/conversation/IdentifyingState.java @@ -5,25 +5,22 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.client.conversation; -import java.util.Collection; -import java.util.LinkedList; -import java.util.List; import org.bitrepository.bitrepositoryelements.ResponseCode; import org.bitrepository.bitrepositorymessages.MessageResponse; import org.bitrepository.client.conversation.selector.ComponentSelector; @@ -31,10 +28,14 @@ import org.bitrepository.client.exceptions.UnexpectedResponseException; import org.bitrepository.common.exceptions.UnableToFinishException; +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; + /** * Handles the general identifying state functionality. For common usage this class handles all messages by using - * the sub classe defined selector. - * + * the subclass defined selector. + *

* This class also has a default implementation for the handleStateTimeout(), getNextState() * and getTimeoutValue() operations. * getNextState() @@ -92,7 +93,8 @@ protected final ComponentSelector getSelector() { /** * Set the concrete selector from the implementing subclass. - * @param customSelector The concrete selector + * + * @param customSelector The concrete selector */ protected void setSelector(ComponentSelector customSelector) { selector = customSelector; @@ -107,25 +109,26 @@ protected void setSelector(ComponentSelector customSelector) { /** * Implements the default handling of failure responses. May be overridden by operation specific behavior, * idempotent behavior f.ex,. + * * @param msg The failure response to handle * @throws UnableToFinishException When unable to finish */ protected void handleFailureResponse(MessageResponse msg) throws UnableToFinishException { getContext().getMonitor().contributorFailed( - msg.getResponseInfo().getResponseText(), msg.getFrom(), + msg.getResponseInfo().getResponseText(), msg.getFrom(), msg.getResponseInfo().getResponseCode()); } private void generateContributorsSelectedEvent(Collection selectedComponentInfo) { List selectedComponentIDs = new LinkedList<>(); - for (SelectedComponentInfo componentInfo:selectedComponentInfo) { + for (SelectedComponentInfo componentInfo : selectedComponentInfo) { selectedComponentIDs.add(componentInfo.getID()); } getContext().getMonitor().contributorsSelected(selectedComponentIDs); } /** - * @return An indication whether the identification state can finish, eg. can continue to the operation phase. + * @return An indication whether the identification state can finish, e.g. can continue to the operation phase. * The default implementation is to return true if at least one a contributor has identified. * has been selected. May be overridden by concrete classes. */ @@ -136,7 +139,8 @@ protected boolean canFinish() { /** * Can be used by some operation to mark the responding pillar as checksum pillar if this is relevant for the * operation. The default implementation is to do nothing - * @param msg The message to check if is coming from a checksumpillar + * + * @param msg The message to be checked if it is coming from a checksumPillar */ protected void checkForChecksumPillar(MessageResponse msg) { diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/conversation/PerformingOperationState.java b/bitrepository-client/src/main/java/org/bitrepository/client/conversation/PerformingOperationState.java index 40c0028e7..643ae5aa1 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/conversation/PerformingOperationState.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/conversation/PerformingOperationState.java @@ -113,7 +113,7 @@ private static Collection toComponentIDs(Collection. * #L% @@ -35,8 +35,8 @@ * receiving specific messages. */ public class StateBasedConversation implements Conversation { - private long startTime; - private ConversationContext context; + private final long startTime; + private final ConversationContext context; /** * Initialize a conversation on the given message bus. @@ -57,7 +57,7 @@ public synchronized void onMessage(Message message, MessageContext messageContex public String getConversationID() { return context.getConversationID(); } - + @Override public long getStartTime() { return startTime; diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/conversation/mediator/CollectionBasedConversationMediator.java b/bitrepository-client/src/main/java/org/bitrepository/client/conversation/mediator/CollectionBasedConversationMediator.java index 8ee672e92..be90bc726 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/conversation/mediator/CollectionBasedConversationMediator.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/conversation/mediator/CollectionBasedConversationMediator.java @@ -1,36 +1,29 @@ /* * #%L * Bitrepository Protocol - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.client.conversation.mediator; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Timer; -import java.util.TimerTask; -import java.util.concurrent.ThreadFactory; - import org.bitrepository.bitrepositorymessages.Message; import org.bitrepository.client.conversation.Conversation; import org.bitrepository.client.eventhandler.ContributorEvent; @@ -44,28 +37,27 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.*; +import java.util.concurrent.ThreadFactory; + /** * Conversation handler that delegates messages to registered conversations. */ public class CollectionBasedConversationMediator implements ConversationMediator { - /** Logger for this class. */ private final Logger log = LoggerFactory.getLogger(getClass()); - /** Registered conversations, mapping from correlation ID to conversation. */ private final Map conversations; - /** The injected settings defining the mediator behavior */ private final Settings settings; - /** Defines that the timer is a daemon thread. */ private static final Boolean TIMER_IS_DAEMON = true; - /** The name of the timer.*/ private static final String NAME_OF_TIMER = "Collection based conversation timer"; - /** The timer used to schedule cleaning of conversations. - * @see ConversationCleaner + /** + * The timer used to schedule cleaning of conversations. + * + * @see ConversationCleaner */ private static final Timer cleanTimer = new Timer(NAME_OF_TIMER, TIMER_IS_DAEMON); private final MessageBus messagebus; - - /** ThreadFactory for any threads the mediator needs to create*/ - private static final ThreadFactory threadFactory = new DefaultThreadFactory(CollectionBasedConversationMediator.class.getSimpleName()+"-", Thread.NORM_PRIORITY , false); + private static final ThreadFactory threadFactory = new DefaultThreadFactory( + CollectionBasedConversationMediator.class.getSimpleName() + "-", Thread.NORM_PRIORITY, false); @Override public void start() { @@ -81,9 +73,9 @@ public void shutdown() { /** * Create a mediator that handles conversations and mediates messages sent on the - * given destination on the given messagebus. + * given destination on the given messageBus. * - * @param settings The general client settings. + * @param settings The general client settings. * @param securityManager Used by the message bus to authenticate messages. */ public CollectionBasedConversationMediator(Settings settings, SecurityManager securityManager) { @@ -103,11 +95,12 @@ public void addConversation(Conversation conversation) { * Will try to fail a conversation gracefully. This entitles: *

    *
  • Removing the conversation from the list of conversations. - *
  • Attempt to call the failConversation operation on the conversation. The call is made in a separate thread to + *
  • Attempt to call the failConversation operation on the conversation. The call is made in a separate thread to * avoid having the failing conversation blocking the calling thread. *
+ * * @param conversation The conversation to fail. - * @param message A message describing the failure symptoms. + * @param message A message describing the failure symptoms. */ private void failConversation(final Conversation conversation, final String message) { String conversationID = conversation.getConversationID(); @@ -118,14 +111,13 @@ private void failConversation(final Conversation conversation, final String mess t.start(); } } - + /** * @param message The message with the unknown conversation ID. */ private void handleUnknownConversation(Message message) { - log.debug(message.getClass().getSimpleName() + " from " + message.getFrom() + - " with correlationID '" + message.getCorrelationID() + "' could not be delegated to any " + - "conversation."); + log.debug(message.getClass().getSimpleName() + " from " + message.getFrom() + " with correlationID '" + message.getCorrelationID() + + "' could not be delegated to any " + "conversation."); } @Override @@ -138,58 +130,60 @@ public void onMessage(Message message, MessageContext messageContext) { handleUnknownConversation(message); } } - + /** - * Will clean out obsolete conversations in each run. An obsolete conversation is a conversation which satisfies on + * Will clean out obsolete conversations in each run. An obsolete conversation is a conversation which satisfies on * of the following criterias:
    *
  1. Returns true for the hasEnded() method. *
  2. Is older than the conversationTImeout limit allows. *
- * + *

* A copy of the current conversations is created before running through the conversations to avoid having to lock * the conversations map while cleaning. */ private final class ConversationCleaner extends TimerTask { @Override public void run() { - Conversation[] conversationArray = - conversations.values().toArray(new Conversation[conversations.size()]); + Conversation[] conversationArray = conversations.values().toArray(new Conversation[0]); long currentTime = System.currentTimeMillis(); - for (Conversation conversation: conversationArray) { - if (conversation.hasEnded()) { + for (Conversation conversation : conversationArray) { + if (conversation.hasEnded()) { conversations.remove(conversation.getConversationID()); - } else if (currentTime - conversation.getStartTime() > - settings.getReferenceSettings().getClientSettings().getConversationTimeout().longValue()) { - log.warn("Failing timed out conversation " + conversation.getConversationID() + " " + - "(Age " + (currentTime - conversation.getStartTime()) + "ms)"); - failConversation(conversation, - "Failing timed out conversation " + conversation.getConversationID()); + } else if (currentTime - conversation.getStartTime() > + settings.getReferenceSettings().getClientSettings().getConversationTimeout().longValue()) { + log.warn("Failing timed out conversation " + conversation.getConversationID() + " " + "(Age " + + (currentTime - conversation.getStartTime()) + "ms)"); + failConversation(conversation, "Failing timed out conversation " + conversation.getConversationID()); } } - } + } } - + /** * Thread for handling the failing of a conversation. */ private static class FailingConversation implements Runnable { - /** The conversation to fail.*/ + /** + * The conversation to fail. + */ private final Conversation conversation; - /** The message telling the reason for the conversation to fail.*/ + /** + * The message telling the reason for the conversation to fail. + */ private final String message; + /** * @param conversation The conversation to fail. - * @param message The reason for the conversation to fail. + * @param message The reason for the conversation to fail. */ FailingConversation(Conversation conversation, String message) { this.conversation = conversation; this.message = message; } - + @Override public void run() { - OperationFailedEvent failedEvent = new OperationFailedEvent(null, message, - Collections.emptyList()); + OperationFailedEvent failedEvent = new OperationFailedEvent(null, message, Collections.emptyList()); failedEvent.setConversationID(conversation.getConversationID()); conversation.failConversation(failedEvent); } diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/conversation/mediator/ConversationMediator.java b/bitrepository-client/src/main/java/org/bitrepository/client/conversation/mediator/ConversationMediator.java index a0fe33304..afa8d93c6 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/conversation/mediator/ConversationMediator.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/conversation/mediator/ConversationMediator.java @@ -1,23 +1,23 @@ /* * #%L * Bitrepository Protocol - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -29,17 +29,17 @@ /** * Keeps track of conversations. - * + *

* Must listen delegate messages to the correct conversations. */ public interface ConversationMediator extends MessageListener { /** - * Will begin listning for messages on the message bus. + * Will begin listening for messages on the message bus. */ void start(); /** - * Will stop this ConversationMediator from listening to the message bus. + * Will stop this {@link ConversationMediator} from listening to the message bus. */ void shutdown(); diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/conversation/mediator/ConversationMediatorManager.java b/bitrepository-client/src/main/java/org/bitrepository/client/conversation/mediator/ConversationMediatorManager.java index 9eb393203..be2bbeeb9 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/conversation/mediator/ConversationMediatorManager.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/conversation/mediator/ConversationMediatorManager.java @@ -1,53 +1,49 @@ /* * #%L * Bitrepository Protocol - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.client.conversation.mediator; -import java.util.HashMap; -import java.util.Map; - import org.bitrepository.common.settings.Settings; import org.bitrepository.protocol.security.SecurityManager; -/** +import java.util.HashMap; +import java.util.Map; + +/** * Get your ConversationMediator here. */ public class ConversationMediatorManager { public static final String DEFAULT_MEDIATOR = "Default mediator"; + private static final Map mediatorMap = new HashMap<>(); + + private ConversationMediatorManager() {} - /** Map of the loaded mediators */ - private static final Map mediatorMap = new HashMap<>(); - - /** - * Private constructor. To prevent instantiation of this utility class. - */ - private ConversationMediatorManager() { } - /** - * Will return a the ConversationMediator for the collection indicated in the settings. + * Will return a the ConversationMediator for the collection indicated in the settings. * If the mediator does doesn't exist, it will be created. - * @param settings The settings to use for this mediator. + * + * @param settings The settings to use for this mediator. * @param securityManager The securityManager to use for this conversation mediator. * @return The settings for the indicated CollectionID. */ @@ -59,9 +55,9 @@ public static synchronized ConversationMediator getConversationMediator(Settings return mediatorMap.get(DEFAULT_MEDIATOR); } - /** * Can be used to inject a custom messageBus for the efault mediator. + * * @param mediator The custom instance of the mediator. */ public static void injectCustomConversationMediator(ConversationMediator mediator) { diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/conversation/selector/ComponentSelector.java b/bitrepository-client/src/main/java/org/bitrepository/client/conversation/selector/ComponentSelector.java index 78e2bdd0a..ad19571ff 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/conversation/selector/ComponentSelector.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/conversation/selector/ComponentSelector.java @@ -1,42 +1,46 @@ /* * #%L * Bitrepository Protocol - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.client.conversation.selector; -import java.util.HashSet; -import java.util.Set; import org.bitrepository.bitrepositorymessages.MessageResponse; import org.bitrepository.client.exceptions.UnexpectedResponseException; -/** Can be used to select a single component to run an operation on by handling the identify responses.

+import java.util.HashSet; +import java.util.Set; + +/** + * Can be used to select a single component to run an operation on, by handling identify responses.

* The algorithm for selecting the component is implemented in the concrete classes. */ public class ComponentSelector { - /** Used for tracking who has answered. */ + /** + * Used for tracking who has answered. + */ protected final Set selectedComponents = new HashSet<>(); - public void selectComponent(MessageResponse response) throws UnexpectedResponseException { + public void selectComponent(MessageResponse response) throws UnexpectedResponseException { selectedComponents.add(new SelectedComponentInfo(response.getFrom(), response.getReplyTo())); } diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/conversation/selector/ContributorResponseStatus.java b/bitrepository-client/src/main/java/org/bitrepository/client/conversation/selector/ContributorResponseStatus.java index 9c3dc519b..88d3d825b 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/conversation/selector/ContributorResponseStatus.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/conversation/selector/ContributorResponseStatus.java @@ -1,40 +1,42 @@ /* * #%L * Bitrepository Protocol - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.client.conversation.selector; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; import org.bitrepository.bitrepositorymessages.MessageResponse; -import org.bitrepository.client.exceptions.UnexpectedResponseException; import org.bitrepository.protocol.utils.MessageUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** Models the response state for a given set of components */ +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +/** + * Models the response state for a given set of components + */ public class ContributorResponseStatus { private final Logger log = LoggerFactory.getLogger(this.getClass()); private final Set componentsWhichShouldRespond; @@ -42,7 +44,8 @@ public class ContributorResponseStatus { /** * Use for identify response bookkeeping. - * @param componentsWhichShouldRespond An array of componentIDs specifying which components are expected to respond + * + * @param componentsWhichShouldRespond An array of componentIDs specifying which components are expected to respond */ public ContributorResponseStatus(Collection componentsWhichShouldRespond) { this.componentsWhichShouldRespond = new HashSet<>(componentsWhichShouldRespond); @@ -51,6 +54,7 @@ public ContributorResponseStatus(Collection componentsWhichShouldRespond /** * Maintains the bookkeeping regarding which components have responded. + * * @param response the response that was received */ public final void responseReceived(MessageResponse response) { @@ -59,8 +63,7 @@ public final void responseReceived(MessageResponse response) { log.debug("Received response from: " + componentID); if (componentsWithOutstandingResponse.contains(componentID)) { componentsWithOutstandingResponse.remove(componentID); - } else if (!componentsWithOutstandingResponse.contains(componentID) && - componentsWhichShouldRespond.contains(componentID)) { + } else if (!componentsWithOutstandingResponse.contains(componentID) && componentsWhichShouldRespond.contains(componentID)) { log.debug("Received more than one response from component " + componentID); } else { log.debug("Received response from irrelevant component " + componentID); @@ -68,10 +71,12 @@ public final void responseReceived(MessageResponse response) { } } - /** Get components where a identify response hasn't been received. - * @return a list of components where a identify response hasn't been received. - * */ - public Collection getOutstandComponents() { + /** + * Get components where identify response hasn't been received. + * + * @return a list of components where identify response hasn't been received. + */ + public Collection getOutstandingComponents() { return Collections.unmodifiableCollection(componentsWithOutstandingResponse); } @@ -79,7 +84,8 @@ public Collection getOutstandComponents() { * @return true if all components have responded. False otherwise */ public final boolean haveAllComponentsResponded() { - log.debug("Expected contributors: " + componentsWhichShouldRespond + ", components that have not answered: " + componentsWithOutstandingResponse); + log.debug("Expected contributors: " + componentsWhichShouldRespond + ", components that have not answered: " + + componentsWithOutstandingResponse); return componentsWithOutstandingResponse.isEmpty(); } diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/conversation/selector/SelectedComponentInfo.java b/bitrepository-client/src/main/java/org/bitrepository/client/conversation/selector/SelectedComponentInfo.java index 45b6af24d..de61b6302 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/conversation/selector/SelectedComponentInfo.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/conversation/selector/SelectedComponentInfo.java @@ -1,23 +1,23 @@ /* * #%L * Bitrepository Protocol - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -28,13 +28,17 @@ * Container for information about a pillar which as been identified and are marked as selected for a request. */ public class SelectedComponentInfo { - /** The ID of the selected pillar */ + /** + * The ID of the selected pillar + */ protected final String componentID; - /** The topic for communication with the selected pillar */ - protected final String componentTopic; + /** + * The topic for communication with the selected pillar + */ + protected final String componentTopic; /** - * @param componentID The ID of the pillar + * @param componentID The ID of the pillar * @param componentTopic the topic for communication with the selected pillar */ public SelectedComponentInfo(String componentID, String componentTopic) { @@ -43,18 +47,20 @@ public SelectedComponentInfo(String componentID, String componentTopic) { this.componentTopic = componentTopic; } - /** @return The ID of the pillar chosen by this selector if finished. If unfinished null is returned */ + /** + * @return The ID of the pillar chosen by this selector if finished. If unfinished null is returned + */ public String getID() { return componentID; } - /** - * @return If finished return the topic for sending messages to the pillar chosen by this selector. - * If unfinished null is returned + /** + * @return If finished return the topic for sending messages to the pillar chosen by this selector. + * If unfinished null is returned */ public String getDestination() { return componentTopic; - } + } @Override public String toString() { diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/AbstractOperationEvent.java b/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/AbstractOperationEvent.java index 3287e976f..c4f89977b 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/AbstractOperationEvent.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/AbstractOperationEvent.java @@ -1,23 +1,23 @@ /* * #%L * Bitrepository Protocol - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -37,15 +37,15 @@ public abstract class AbstractOperationEvent implements OperationEvent { private String conversationID; private String collectionID; - @Override + @Override public String getCollectionID() { return collectionID; } - + public void setCollectionID(String collectionID) { this.collectionID = collectionID; } - + @Override public String getInfo() { return info; @@ -60,6 +60,7 @@ public OperationEventType getEventType() { public OperationType getOperationType() { return operationType; } + @Override public String getFileID() { return fileID; @@ -70,29 +71,33 @@ public String getConversationID() { return conversationID; } - /** @see #getEventType + /** * @param type The {@link OperationEventType} to set as the event type + * @see #getEventType */ public void setEventType(OperationEventType type) { this.type = type; } - /** @see #getOperationType - * @param operationType The {@link OperationType} to set as the operation type + /** + * @param operationType The {@link OperationType} to set as the operation type + * @see #getOperationType */ public void setOperationType(OperationType operationType) { this.operationType = operationType; } - /** @see #getFileID - * @param fileID The ID of the file + /** + * @param fileID The ID of the file + * @see #getFileID */ public void setFileID(String fileID) { this.fileID = fileID; } - /** @see #getInfo - * @param info The content of the info field + /** + * @param info The content of the info field + * @see #getInfo */ public void setInfo(String info) { this.info = info; @@ -108,21 +113,21 @@ public void setConversationID(String conversationID) { @Override public final String toString() { StringBuilder sb = new StringBuilder(); - sb.append(getConversationID() + ": "); + sb.append(getConversationID()).append(": "); sb.append(operationType); if (fileID != null) { - sb.append(" for file " + fileID); + sb.append(" for file ").append(fileID); } - sb.append(": " + getEventType() + ": "); + sb.append(": ").append(getEventType()).append(": "); if (additionalInfo() != null) { sb.append(additionalInfo()); } if (getInfo() != null) { - sb.append(", " + getInfo()); + sb.append(", ").append(getInfo()); } return sb.toString(); } - + /** * @return The additional information in a string form. The string returned will be appended to the toString value. */ diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/BlockingEventHandler.java b/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/BlockingEventHandler.java index 76d16fd49..1db4364fc 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/BlockingEventHandler.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/BlockingEventHandler.java @@ -1,21 +1,21 @@ package org.bitrepository.client.eventhandler; /* * #%L - * Bitrepository Client + * BitRepository Client * %% * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -25,20 +25,16 @@ import java.util.List; /** - * Eventhandler wrapper enabling blocking behavior for clients. Can pass events on to a supplied eventhandler. + * EventHandler wrapper enabling blocking behavior for clients. Can pass events on to a supplied EventHandler. */ public class BlockingEventHandler implements EventHandler { private final EventHandler eventHandler; private OperationEvent finishEvent; - private List componentCompleteEvents = new LinkedList<>(); - private List componentFailedEvents = new LinkedList<>(); - - public BlockingEventHandler() { - eventHandler = null; - } + private final List componentCompleteEvents = new LinkedList<>(); + private final List componentFailedEvents = new LinkedList<>(); /** - * @param eventHandler The eventhandler to pass event on to. + * @param eventHandler The EventHandler to pass event on to. */ public BlockingEventHandler(EventHandler eventHandler) { this.eventHandler = eventHandler; @@ -50,12 +46,12 @@ public synchronized void handleEvent(OperationEvent event) { eventHandler.handleEvent(event); } - if (event.getEventType() == OperationEvent.OperationEventType.COMPONENT_COMPLETE) { - componentCompleteEvents.add((ContributorEvent)event); + if (event.getEventType() == OperationEvent.OperationEventType.COMPONENT_COMPLETE) { + componentCompleteEvents.add((ContributorEvent) event); } else if (event.getEventType() == OperationEvent.OperationEventType.COMPONENT_FAILED) { - componentFailedEvents.add((ContributorFailedEvent)event); - } else if(event.getEventType() == OperationEvent.OperationEventType.COMPLETE || - event.getEventType() == OperationEvent.OperationEventType.FAILED ) { + componentFailedEvents.add((ContributorFailedEvent) event); + } else if (event.getEventType() == OperationEvent.OperationEventType.COMPLETE || + event.getEventType() == OperationEvent.OperationEventType.FAILED) { finishEvent = event; this.notify(); } @@ -63,6 +59,7 @@ public synchronized void handleEvent(OperationEvent event) { /** * Will block until a COMPLETE or FAILED event is received. + * * @return the operationEvent */ public synchronized OperationEvent awaitFinished() { @@ -73,13 +70,10 @@ public synchronized OperationEvent awaitFinished() { return finishEvent; } - public boolean hasFailed() { - return componentFailedEvents.size() > 0; - } - public List getFailures() { return componentFailedEvents; } + public List getResults() { return componentCompleteEvents; } diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/CompleteEvent.java b/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/CompleteEvent.java index 912a09abc..4989af39e 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/CompleteEvent.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/CompleteEvent.java @@ -1,23 +1,23 @@ /* * #%L * Bitrepository Protocol - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -28,17 +28,19 @@ import java.util.List; /** - * Indicates a operation has completed successfully. + * Indicates that an operation has completed successfully. */ public class CompleteEvent extends AbstractOperationEvent { - /** See {@link #getInfo()}*/ + /** + * See {@link #getInfo()} + */ private final List componentResults; /** - * @param collectionID the collection ID + * @param collectionID the collection ID * @param componentResults The aggregated list of COMPONENT_COMPLETE events generated during * the operation. - */ + */ public CompleteEvent(String collectionID, List componentResults) { super(); setCollectionID(collectionID); diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/ContributorCompleteEvent.java b/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/ContributorCompleteEvent.java index f8b1dc395..925d47703 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/ContributorCompleteEvent.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/ContributorCompleteEvent.java @@ -1,21 +1,21 @@ package org.bitrepository.client.eventhandler; /* * #%L - * Bitrepository Client + * BitRepository Client * %% * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/ContributorEvent.java b/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/ContributorEvent.java index fae45a051..b9db0305a 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/ContributorEvent.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/ContributorEvent.java @@ -1,23 +1,23 @@ /* * #%L * Bitrepository Protocol - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -29,10 +29,10 @@ */ public class ContributorEvent extends AbstractOperationEvent { private final String contributorID; - + /** * @param contributorID The contributorID for which this event concerns. - * @param collectionID the collectionID for which this event concerns. + * @param collectionID the collectionID for which this event concerns. */ public ContributorEvent(String contributorID, String collectionID) { super(); diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/ContributorFailedEvent.java b/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/ContributorFailedEvent.java index 6943975bb..44e02a977 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/ContributorFailedEvent.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/ContributorFailedEvent.java @@ -5,16 +5,16 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -30,9 +30,9 @@ public class ContributorFailedEvent extends ContributorEvent { /** * @param contributorID the contributor - * @param collectionID the collection - * @param responseCode The response code from any response indicating the failure. Might be null, if no relevant - * response exists. + * @param collectionID the collection + * @param responseCode The response code from any response indicating the failure. Might be null, if no relevant + * response exists. */ public ContributorFailedEvent(String contributorID, String collectionID, ResponseCode responseCode) { super(contributorID, collectionID); diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/DefaultEvent.java b/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/DefaultEvent.java index 7615265e1..d59e5a8c0 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/DefaultEvent.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/DefaultEvent.java @@ -1,37 +1,39 @@ /* * #%L * Bitrepository Protocol - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.client.eventhandler; -/** A general type of OperationEvent only containing a descriptive info message. */ +/** + * A general type of OperationEvent only containing a descriptive info message. + */ public class DefaultEvent extends AbstractOperationEvent { public DefaultEvent(String collectionID) { super(); setCollectionID(collectionID); } - + @Override public String additionalInfo() { return ""; diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/EventHandler.java b/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/EventHandler.java index 996f83ef0..13ea84aec 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/EventHandler.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/EventHandler.java @@ -1,23 +1,23 @@ /* * #%L * Bitrepository Protocol - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -25,15 +25,16 @@ package org.bitrepository.client.eventhandler; /** - * Defines the interface for clients to follow the sequence of events unfolding after a operation on the bitrepository + * Defines the interface for clients to follow the sequence of events unfolding after a operation on the BitRepository * has been requested. - * - * A user interested in following the status a of request should create an EventHandler and supply the + *

+ * To follow the status of a request, create an EventHandler and supply the * EventHandler when call the relevant method on the client. */ public interface EventHandler { /** * Called by the client each time a event is detected relevant for the active operation + * * @param event Contains information about the concrete event. */ void handleEvent(OperationEvent event); diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/IdentificationCompleteEvent.java b/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/IdentificationCompleteEvent.java index ef37cd50c..180cd4037 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/IdentificationCompleteEvent.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/IdentificationCompleteEvent.java @@ -1,23 +1,23 @@ /* * #%L * Bitrepository Protocol - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -33,7 +33,7 @@ public class IdentificationCompleteEvent extends AbstractOperationEvent { private final List contributorIDs; /** - * @param collectionID the collection ID for the event + * @param collectionID the collection ID for the event * @param contributorIDs The list of IDs of the contributor this event relates to. */ public IdentificationCompleteEvent(String collectionID, List contributorIDs) { @@ -44,12 +44,12 @@ public IdentificationCompleteEvent(String collectionID, List contributor } /** - * @return the ID of the pillar this event relates to. + * @return the ID of the pillar this event relates to. */ public List getContributorIDs() { return contributorIDs; } - + @Override public String additionalInfo() { return "Contributors: " + getContributorIDs(); diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/OperationEvent.java b/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/OperationEvent.java index adf120cea..baab40e6e 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/OperationEvent.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/OperationEvent.java @@ -1,23 +1,23 @@ /* * #%L * Bitrepository Protocol - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -33,10 +33,10 @@ public interface OperationEvent { /** * Defines the different types of events that can be received. These are:

    *
  1. PillarIdentified: An identify response has been received from a pillar. - *
  2. PillarSelected: Enough responses has now been received from pillar to select a pillar to perform the + *
  3. PillarSelected: Enough responses has now been received from pillar to select a pillar to perform the * operation on. - *
  4. RequestSent: A request for the operation has ben sent to the relevant pillar(s). - *
  5. Progress: In case of longer operations (e.g. requiring file transfers) progress information might be + *
  6. RequestSent: A request for the operation has ben sent to the relevant pillar(s). + *
  7. Progress: In case of longer operations (e.g. requiring file transfers) progress information might be * received from the pillars. *
  8. PartiallyComplete: The cases when part of the operation has been completed (e.g. when the operation has been * to be performed at several pillars, and it has been completed on one of them). @@ -45,42 +45,36 @@ public interface OperationEvent { * The following error types exist:
      *
    1. Failed: A general failure occurred during the operation *
    2. NoPillarFound: No relevant response was received before a timeout occurred. - *
    3. TimeOut: The operation did't finish before a timeout occurred. + *
    4. TimeOut: The operation didn't finish before a timeout occurred. *
    */ enum OperationEventType { - IDENTIFY_REQUEST_SENT, - COMPONENT_IDENTIFIED, - IDENTIFICATION_COMPLETE, - REQUEST_SENT, - PROGRESS, - COMPONENT_COMPLETE, - COMPLETE, - COMPONENT_FAILED, - FAILED, - IDENTIFY_TIMEOUT, - WARNING + IDENTIFY_REQUEST_SENT, COMPONENT_IDENTIFIED, IDENTIFICATION_COMPLETE, REQUEST_SENT, PROGRESS, COMPONENT_COMPLETE, COMPLETE, + COMPONENT_FAILED, FAILED, IDENTIFY_TIMEOUT, WARNING } - + /** * @return A string representation of what has happened */ String getInfo(); - + /** * Used to get the type of event. + * * @return A OperationEventType categorizing this event. */ OperationEventType getEventType(); /** * Used to get the type of operation. + * * @return A OperationEventType categorizing this event. */ OperationType getOperationType(); /** * Used to get the fileID this operation is performed on, if any. + * * @return A OperationEventType categorizing this event. */ String getFileID(); @@ -89,9 +83,9 @@ enum OperationEventType { * @return The conversation ID of the event. */ String getConversationID(); - + /** - * @return The ID of the collection that the + * @return The ID of the collection that the */ String getCollectionID(); } diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/OperationFailedEvent.java b/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/OperationFailedEvent.java index 522e42872..0e2f5f46a 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/OperationFailedEvent.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/eventhandler/OperationFailedEvent.java @@ -1,23 +1,23 @@ /* * #%L * Bitrepository Protocol - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -34,8 +34,8 @@ public class OperationFailedEvent extends AbstractOperationEvent { private final List componentResults; /** - * @param collectionID the collection ID - * @param info See {@link #getInfo()} + * @param collectionID the collection ID + * @param info See {@link #getInfo()} * @param componentResults The aggregated list of COMPONENT_COMPLETE events generated during * the operation. */ @@ -47,7 +47,7 @@ public OperationFailedEvent(String collectionID, String info, ListCOMPONENT_COMPLETE events generated during the operation. */ public List getComponentResults() { @@ -58,5 +58,5 @@ public List getComponentResults() { public String additionalInfo() { return ""; } - + } diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/exceptions/NegativeResponseException.java b/bitrepository-client/src/main/java/org/bitrepository/client/exceptions/NegativeResponseException.java index e91a695ed..3a310c19d 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/exceptions/NegativeResponseException.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/exceptions/NegativeResponseException.java @@ -1,23 +1,23 @@ /* * #%L * Bitrepository Protocol - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -32,22 +32,23 @@ */ @SuppressWarnings("serial") public class NegativeResponseException extends Exception { - private final ResponseCode errorcode; + private final ResponseCode errorCode; /** * Constructor with both message and cause exception - * @param message Human readable description of this exception - * @param errorcode The errorcode causing the exception. + * + * @param message Description of this exception in + * @param errorCode The error code causing the exception. */ - public NegativeResponseException(String message, ResponseCode errorcode) { + public NegativeResponseException(String message, ResponseCode errorCode) { super(message); - this.errorcode = errorcode; + this.errorCode = errorCode; } /** - * @return The errorcode causing the exception. + * @return The error code causing the exception. */ - public ResponseCode getErrorcode() { - return errorcode; - } + public ResponseCode getErrorCode() { + return errorCode; + } } diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/exceptions/UnexpectedResponseException.java b/bitrepository-client/src/main/java/org/bitrepository/client/exceptions/UnexpectedResponseException.java index 6a9972301..8981e1fd0 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/client/exceptions/UnexpectedResponseException.java +++ b/bitrepository-client/src/main/java/org/bitrepository/client/exceptions/UnexpectedResponseException.java @@ -1,23 +1,23 @@ /* * #%L * Bitrepository Protocol - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -25,21 +25,23 @@ package org.bitrepository.client.exceptions; /** - * Used to indicate that an negative reponse has been received. + * Used to indicate that a negative response has been received. */ @SuppressWarnings("serial") public class UnexpectedResponseException extends Exception { /** * Constructor with both message and cause exception + * * @param message of this exception - * @param cause The throwable causing of the exception + * @param cause The throwable causing of the exception */ public UnexpectedResponseException(String message, Throwable cause) { super(message, cause); } /** - * Constructor with only a message + * Constructor with only a message + * * @param message of this exception */ public UnexpectedResponseException(String message) { diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/CommandLineClient.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/CommandLineClient.java index 57aa537e8..adfa0a057 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/CommandLineClient.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/CommandLineClient.java @@ -5,16 +5,16 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -22,15 +22,6 @@ package org.bitrepository.commandline; -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import java.security.NoSuchAlgorithmException; -import java.util.Arrays; -import java.util.List; - -import javax.jms.JMSException; - import org.apache.commons.cli.Option; import org.apache.commons.cli.ParseException; import org.bitrepository.bitrepositoryelements.ChecksumDataForFileTYPE; @@ -40,26 +31,35 @@ import org.bitrepository.commandline.utils.ChecksumExtractionUtils; import org.bitrepository.commandline.utils.CommandLineArgumentsHandler; import org.bitrepository.common.settings.Settings; -import org.bitrepository.common.utils.Base16Utils; -import org.bitrepository.common.utils.CalendarUtils; -import org.bitrepository.common.utils.ChecksumUtils; -import org.bitrepository.common.utils.FileIDValidator; -import org.bitrepository.common.utils.SettingsUtils; +import org.bitrepository.common.utils.*; import org.bitrepository.protocol.FileExchange; import org.bitrepository.protocol.ProtocolComponentFactory; import org.bitrepository.protocol.messagebus.MessageBus; import org.bitrepository.protocol.messagebus.MessageBusManager; import org.bitrepository.protocol.security.SecurityManager; +import javax.jms.JMSException; +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.security.NoSuchAlgorithmException; +import java.util.List; + /** * Defines the common functionality for command-line-clients. */ public abstract class CommandLineClient { private final String componentID; + protected final OutputHandler output = new DefaultOutputHandler(getClass()); + protected final Settings settings; + protected final SecurityManager securityManager; + protected final CommandLineArgumentsHandler cmdHandler; + private final FileIDValidator fileIDValidator; /** - * Runs a specific command-line-client operation. + * Runs a specific command-line-client operation. * Handles also the closing of connections and deals with exceptions. + * * @throws Exception if an error occurs */ public void runCommand() throws Exception { @@ -75,31 +75,19 @@ public void runCommand() throws Exception { } } - /** For handling the output.*/ - protected final OutputHandler output = new DefaultOutputHandler(getClass()); - - /** The settings for the client.*/ - protected final Settings settings; - /** The security manager.*/ - protected final SecurityManager securityManager; - /** The handler for the command line arguments.*/ - protected final CommandLineArgumentsHandler cmdHandler; - private final FileIDValidator fileIDValidator; - /** * @param args The generic command line arguments for defining the operation. */ - protected CommandLineClient(String ... args) { + protected CommandLineClient(String... args) { cmdHandler = new CommandLineArgumentsHandler(); createOptionsForCmdArgumentHandler(); try { cmdHandler.parseArguments(args); } catch (ParseException pe) { - output.error(cmdHandler.listArguments() + - "Missing argument: " + pe.getMessage()); + output.error(cmdHandler.listArguments() + "Missing argument: " + pe.getMessage()); throw new IllegalArgumentException("Missing arguments", pe); } - if(cmdHandler.hasOption(Constants.VERBOSITY_ARG)) { + if (cmdHandler.hasOption(Constants.VERBOSITY_ARG)) { output.setVerbosity(true); } settings = cmdHandler.loadSettings(); @@ -124,6 +112,7 @@ protected CommandLineClient(String ... args) { /** * Defines the componentID of the concrete client. Must be specified by in the subclass. + * * @return The componentID of the concrete client. */ protected String getComponentID() { @@ -133,6 +122,7 @@ protected String getComponentID() { /** * Used for determining whether the fileID Argument is required for the concrete operation. * Must be specified by in the subclass. + * * @return Indicates whether the -f */ protected abstract boolean isFileIDArgumentRequired(); @@ -148,13 +138,12 @@ protected void createOptionsForCmdArgumentHandler() { collectionOption.setRequired(Constants.ARGUMENT_IS_REQUIRED); cmdHandler.addOption(collectionOption); - Option fileIDOption = new Option(Constants.FILE_ID_ARG, Constants.HAS_ARGUMENT, - "The id for the file to perform the operation on."); + Option fileIDOption = new Option(Constants.FILE_ID_ARG, Constants.HAS_ARGUMENT, "The id for the file to perform the operation on."); fileIDOption.setRequired(isFileIDArgumentRequired()); cmdHandler.addOption(fileIDOption); - Option pillarOption = new Option(Constants.PILLAR_ARG, Constants.HAS_ARGUMENT, "[OPTIONAL] The id of the " - + "pillar where the operation should be performed. If undefined the operation is performed on all pillars."); + Option pillarOption = new Option(Constants.PILLAR_ARG, Constants.HAS_ARGUMENT, "[OPTIONAL] The id of the " + + "pillar where the operation should be performed. If undefined the operation is performed on all pillars."); pillarOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); cmdHandler.addOption(pillarOption); } @@ -163,23 +152,23 @@ protected void createOptionsForCmdArgumentHandler() { * @throws IllegalArgumentException One of the arguments wasn't valid. */ protected void validateArguments() { - if(cmdHandler.hasOption(Constants.FILE_ID_ARG)) { + if (cmdHandler.hasOption(Constants.FILE_ID_ARG)) { fileIDValidator.checkFileID(cmdHandler.getOptionValue(Constants.FILE_ID_ARG)); } - if(cmdHandler.hasOption(Constants.COLLECTION_ID_ARG)) { + if (cmdHandler.hasOption(Constants.COLLECTION_ID_ARG)) { List collections = SettingsUtils.getAllCollectionsIDs(); String collectionArgument = cmdHandler.getOptionValue(Constants.COLLECTION_ID_ARG); if (!collections.contains(collectionArgument)) { - throw new IllegalArgumentException(collectionArgument + " is not a valid collection." + - "\nThe following collections are defined: " + collections); + throw new IllegalArgumentException( + collectionArgument + " is not a valid collection." + "\nThe following collections are defined: " + collections); } } - if(cmdHandler.hasOption(Constants.PILLAR_ARG)) { + if (cmdHandler.hasOption(Constants.PILLAR_ARG)) { String pillarArgument = cmdHandler.getOptionValue(Constants.PILLAR_ARG); List pillarsInCollection = SettingsUtils.getPillarIDsForCollection(getCollectionID()); if (!pillarsInCollection.contains(pillarArgument)) { - throw new IllegalArgumentException(pillarArgument + " is not a valid pillar for collection " + - getCollectionID() + "\nThe collection contains the following pillars: " + pillarsInCollection); + throw new IllegalArgumentException(pillarArgument + " is not a valid pillar for collection " + getCollectionID() + + "\nThe collection contains the following pillars: " + pillarsInCollection); } } } @@ -189,7 +178,7 @@ protected void validateArguments() { * otherwise all file ids will be requested. */ protected String getFileIDs() { - if(cmdHandler.hasOption(Constants.FILE_ID_ARG)) { + if (cmdHandler.hasOption(Constants.FILE_ID_ARG)) { return cmdHandler.getOptionValue(Constants.FILE_ID_ARG); } else { return null; @@ -206,11 +195,12 @@ protected String getCollectionID() { /** * Extract the pillar ids. If a specific pillar is given as argument, then it will be returned, but if no such * argument has been given, then the list of all pillar ids are given. + * * @return The list of pillars to request for the file ids. */ protected List getPillarIDs() { - if(cmdHandler.hasOption(Constants.PILLAR_ARG)) { - return Arrays.asList(cmdHandler.getOptionValue(Constants.PILLAR_ARG)); + if (cmdHandler.hasOption(Constants.PILLAR_ARG)) { + return List.of(cmdHandler.getOptionValue(Constants.PILLAR_ARG)); } else { return SettingsUtils.getPillarIDsForCollection(getCollectionID()); } @@ -220,8 +210,8 @@ protected List getPillarIDs() { * @return The timeout to use for performing the full operation. */ protected long getTimeout() { - return settings.getRepositorySettings().getClientSettings().getIdentificationTimeout().longValue() - + settings.getRepositorySettings().getClientSettings().getOperationTimeout().longValue(); + return settings.getRepositorySettings().getClientSettings().getIdentificationTimeout().longValue() + + settings.getRepositorySettings().getClientSettings().getOperationTimeout().longValue(); } /** @@ -235,7 +225,7 @@ protected ChecksumSpecTYPE getRequestChecksumSpecOrDefault() { * @return The requested checksum spec, or null. */ protected ChecksumSpecTYPE getRequestChecksumSpecOrNull() { - if(!cmdHandler.hasOption(Constants.REQUEST_CHECKSUM_TYPE_ARG)) { + if (!cmdHandler.hasOption(Constants.REQUEST_CHECKSUM_TYPE_ARG)) { return null; } @@ -246,22 +236,22 @@ protected ChecksumSpecTYPE getRequestChecksumSpecOrNull() { * Create the ChecksumSpecTYPE based on the cmd-line arguments. * Do not use directly. Use either 'getRequestChecksumSpecOrNull' or 'getRequestChecksumSpecOrDefault' to handle * the case, when no request arguments have been defined. + * * @return The requested checksum spec. */ private ChecksumSpecTYPE getRequestChecksumSpec() { ChecksumSpecTYPE res = new ChecksumSpecTYPE(); res.setChecksumType(ChecksumExtractionUtils.extractChecksumType(cmdHandler, settings, output)); - if(cmdHandler.hasOption(Constants.REQUEST_CHECKSUM_SALT_ARG)) { - res.setChecksumSalt(Base16Utils.encodeBase16(cmdHandler.getOptionValue( - Constants.REQUEST_CHECKSUM_SALT_ARG))); + if (cmdHandler.hasOption(Constants.REQUEST_CHECKSUM_SALT_ARG)) { + res.setChecksumSalt(Base16Utils.encodeBase16(cmdHandler.getOptionValue(Constants.REQUEST_CHECKSUM_SALT_ARG))); } try { ChecksumUtils.verifyAlgorithm(res); } catch (NoSuchAlgorithmException e) { output.error("Invalid checksum algorithm: " + e.getMessage()); - throw new IllegalStateException("Invalid checksumspec for '" + res + "'", e); + throw new IllegalStateException("Invalid checksumSpec for '" + res + "'", e); } return res; @@ -269,19 +259,19 @@ private ChecksumSpecTYPE getRequestChecksumSpec() { /** * Finds the file from the arguments. + * * @return The requested file, or null if no file argument was given. */ protected File findTheFile() { - if(!cmdHandler.hasOption(Constants.FILE_ARG)) { + if (!cmdHandler.hasOption(Constants.FILE_ARG)) { output.warn("No file argument was given, so no file can be found."); return null; } String filePath = cmdHandler.getOptionValue(Constants.FILE_ARG); File file = new File(filePath); - if(!file.isFile()) { - throw new IllegalArgumentException("The file '" + filePath + "' is invalid. It does not exists or it " - + "is a directory."); + if (!file.isFile()) { + throw new IllegalArgumentException("The file '" + filePath + "' is invalid. It does not exists or it " + "is a directory."); } return file; @@ -289,10 +279,11 @@ protected File findTheFile() { /** * Creates the data structure for encapsulating the validation checksums for validation on the pillars. + * * @return The ChecksumDataForFileTYPE for the pillars to validate the DeleteFile or ReplaceFile operations. */ protected ChecksumDataForFileTYPE getChecksumDataForDeleteValidation() { - if(!cmdHandler.hasOption(Constants.CHECKSUM_ARG)) { + if (!cmdHandler.hasOption(Constants.CHECKSUM_ARG)) { return null; } @@ -305,7 +296,8 @@ protected ChecksumDataForFileTYPE getChecksumDataForDeleteValidation() { } /** - * Removes the file at the webserver after the operation has finished.. + * Removes the file at the webserver after the operation has finished. + * * @param url The URL where the file should be removed from. */ protected void deleteFileAfterwards(URL url) { @@ -322,10 +314,11 @@ protected void deleteFileAfterwards(URL url) { * Retrieves the URL for the PutFile operation. * Either uploads the actual file to a webserver, or takes the URL argument. * Requires either the File argument or the URL argument. + * * @return The URL for the file. */ protected URL getURLOrUploadFile() { - if(cmdHandler.hasOption(Constants.FILE_ARG)) { + if (cmdHandler.hasOption(Constants.FILE_ARG)) { File f = findTheFile(); FileExchange fileexchange = ProtocolComponentFactory.getInstance().getFileExchange(settings); return fileexchange.putFile(f); @@ -333,8 +326,8 @@ protected URL getURLOrUploadFile() { try { return new URL(cmdHandler.getOptionValue(Constants.URL_ARG)); } catch (MalformedURLException e) { - throw new IllegalArgumentException("The URL argument is either empty or not a valid URL: " - + cmdHandler.getOptionValue(Constants.URL_ARG), e); + throw new IllegalArgumentException( + "The URL argument is either empty or not a valid URL: " + cmdHandler.getOptionValue(Constants.URL_ARG), e); } } } @@ -343,7 +336,7 @@ protected URL getURLOrUploadFile() { * @return The size of the actual file, or 0 if no file argument is given. */ protected long getSizeOfFileOrZero() { - if(cmdHandler.hasOption(Constants.FILE_ARG)) { + if (cmdHandler.hasOption(Constants.FILE_ARG)) { return findTheFile().length(); } else { return 0L; @@ -351,8 +344,9 @@ protected long getSizeOfFileOrZero() { } /** - * Creates the data structure for encapsulating the validation checksums for validation of the PutFile + * Creates the data structure for encapsulating the validation checksums for validation of the PutFile * or ReplaceFile operations. + * * @param file The file to have the checksum calculated. * @return The ChecksumDataForFileTYPE for the pillars to validate the operations. */ @@ -369,14 +363,15 @@ protected ChecksumDataForFileTYPE getValidationChecksumDataForFile(File file) { } /** - * Creates the data structure for encapsulating the validation checksums for validation of the PutFile + * Creates the data structure for encapsulating the validation checksums for validation of the PutFile * or ReplaceFile operations. - * @param arg The name of the argument to retrieve the checksum from - * (must likely Constants.CHECKSUM_ARG or Constants.REPLACE_CHECKSUM_ARG) + * + * @param arg The name of the argument to retrieve the checksum from + * (must likely Constants.CHECKSUM_ARG or Constants.REPLACE_CHECKSUM_ARG) * @return The ChecksumDataForFileTYPE for the pillars to validate the operations. */ protected ChecksumDataForFileTYPE getValidationChecksumDataFromArgument(String arg) { - if(!cmdHandler.hasOption(arg)) { + if (!cmdHandler.hasOption(arg)) { return null; } ChecksumSpecTYPE csSpec = ChecksumUtils.getDefault(settings); @@ -391,10 +386,11 @@ protected ChecksumDataForFileTYPE getValidationChecksumDataFromArgument(String a /** * Extracts the id of the file to be put. - * @return The either the value of the file id argument, or no such option, then the name of the file. + * + * @return Returns either the value of the file ID argument, or no such option, then the name of the file. */ protected String retrieveFileID() { - if(cmdHandler.hasOption(Constants.FILE_ID_ARG)) { + if (cmdHandler.hasOption(Constants.FILE_ID_ARG)) { return cmdHandler.getOptionValue(Constants.FILE_ID_ARG); } else { return findTheFile().getName(); @@ -403,11 +399,12 @@ protected String retrieveFileID() { /** * Closes the connections, e.g. to the message-bus. + * * @throws JMSException If the message-bus cannot be closed. */ public void shutdown() throws JMSException { MessageBus bus = MessageBusManager.getMessageBus(); - if(bus != null) { + if (bus != null) { bus.close(); } } diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/Constants.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/Constants.java index 55fe724fb..5b72d3f55 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/Constants.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/Constants.java @@ -5,16 +5,16 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -30,49 +30,70 @@ public class Constants { */ private Constants() {} - /** If an argument is required.*/ public static final Boolean ARGUMENT_IS_REQUIRED = true; - /** If an argument is not required.*/ public static final Boolean ARGUMENT_IS_NOT_REQUIRED = false; - /** If a given option has an argument.*/ public static final Boolean HAS_ARGUMENT = true; - /** If a given option dies not have an argument.*/ public static final Boolean NO_ARGUMENT = false; - /** For not allowing undefined arguments when parsing of arguments.*/ public static final Boolean NOT_ALLOWING_UNDEFINED_ARGUMENTS = false; - - /** The path to the settings.*/ + /** + * The path to the settings. + */ public static final String SETTINGS_ARG = "s"; - /** The path to the private key.*/ + /** + * The path to the private key. + */ public static final String PRIVATE_KEY_ARG = "k"; - /** */ + /** + * + */ public static final String VERBOSITY_ARG = "v"; - /** The collectionID argument */ + /** + * The collectionID argument + */ public static final String COLLECTION_ID_ARG = "c"; - /** The file argument.*/ + /** + * The file argument. + */ public static final String FILE_ARG = "f"; - /** The argument for the id of the file.*/ + /** + * The argument for the id of the file. + */ public static final String FILE_ID_ARG = "i"; - /** The pillar argument.*/ + /** + * The pillar argument. + */ public static final String PILLAR_ARG = "p"; - /** The checksum of the file.*/ + /** + * The checksum of the file. + */ public static final String CHECKSUM_ARG = "C"; - /** The checksum of the file to replace.*/ + /** + * The checksum of the file to replace. + */ public static final String REPLACE_CHECKSUM_ARG = "r"; - /** The argument for the type of checksum to request.*/ + /** + * The argument for the type of checksum to request. + */ public static final String REQUEST_CHECKSUM_TYPE_ARG = "R"; - /** The argument for the salt of the checksum to request.*/ + /** + * The argument for the salt of the checksum to request. + */ public static final String REQUEST_CHECKSUM_SALT_ARG = "S"; - /** The argument for deleting files afterwards.*/ + /** + * The argument for deleting files afterwards. + */ public static final String DELETE_FILE_ARG = "d"; - /** The argument for the URL of a file.*/ + /** + * The argument for the URL of a file. + */ public static final String URL_ARG = "u"; - /** The argument for the location of the results.*/ + /** + * The argument for the location of the results. + */ public static final String LOCATION = "l"; - public static final int EXIT_SUCCESS = 0; public static final int EXIT_ARGUMENT_FAILURE = 1; public static final int EXIT_OPERATION_FAILURE = -1; diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/DeleteFileCmd.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/DeleteFileCmd.java index de074b45d..d7f5929c5 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/DeleteFileCmd.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/DeleteFileCmd.java @@ -5,16 +5,16 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -35,7 +35,9 @@ * Deleting a file from the collection. */ public class DeleteFileCmd extends CommandLineClient { - /** The client for performing the DeleteFile operation.*/ + /** + * The client for performing the DeleteFile operation. + */ private final DeleteFileClient client; /** @@ -56,7 +58,7 @@ public static void main(String[] args) { /** * @param args The command line arguments for defining the operation. */ - protected DeleteFileCmd(String ... args) { + protected DeleteFileCmd(String... args) { super(args); client = ModifyComponentFactory.getInstance().retrieveDeleteFileClient(settings, securityManager, getComponentID()); @@ -88,7 +90,7 @@ protected void createOptionsForCmdArgumentHandler() { protected void validateArguments() { super.validateArguments(); - if(!cmdHandler.hasOption(Constants.PILLAR_ARG)) { + if (!cmdHandler.hasOption(Constants.PILLAR_ARG)) { throw new IllegalArgumentException("The pillar argument -p must defined for the delete operation, " + "only single pillar deletes are allowed"); } @@ -108,7 +110,7 @@ public void performOperation() { output.completeEvent("Results of the DeleteFile operation for the file '" + cmdHandler.getOptionValue(Constants.FILE_ID_ARG) + "'" + ": ", finalEvent); - if(finalEvent.getEventType() == OperationEventType.COMPLETE) { + if (finalEvent.getEventType() == OperationEventType.COMPLETE) { System.exit(Constants.EXIT_SUCCESS); } else { System.exit(Constants.EXIT_OPERATION_FAILURE); @@ -117,6 +119,7 @@ public void performOperation() { /** * Initiates the operation and waits for the results. + * * @return The final event for the results of the operation. Either 'FAILURE' or 'COMPLETE'. */ private OperationEvent deleteTheFile() { diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/GetChecksumsCmd.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/GetChecksumsCmd.java index cfbb05564..c9986d9f3 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/GetChecksumsCmd.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/GetChecksumsCmd.java @@ -5,16 +5,16 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -31,11 +31,7 @@ import org.bitrepository.commandline.outputformatter.GetChecksumsOutputFormatter; import org.bitrepository.common.utils.SettingsUtils; -/** - * Perform the GetChecksums operation. - */ public class GetChecksumsCmd extends CommandLineClient { - /** The client for performing the GetChecksums operation.*/ private final PagingGetChecksumsClient pagingClient; /** @@ -56,13 +52,13 @@ public static void main(String[] args) { /** * @param args The command line arguments for defining the operation. */ - protected GetChecksumsCmd(String ... args) { + protected GetChecksumsCmd(String... args) { super(args); - GetChecksumsClient client = AccessComponentFactory.getInstance().createGetChecksumsClient(settings, + GetChecksumsClient client = AccessComponentFactory.getInstance().createGetChecksumsClient(settings, securityManager, getComponentID()); GetChecksumsOutputFormatter outputFormatter = retrieveOutputFormatter(); int pageSize = SettingsUtils.getMaxClientPageSize(); - pagingClient = new PagingGetChecksumsClient(client, getTimeout(), pageSize, outputFormatter, output); + pagingClient = new PagingGetChecksumsClient(client, getTimeout(), pageSize, outputFormatter, output); } @Override @@ -76,13 +72,13 @@ protected boolean isFileIDArgumentRequired() { protected void createOptionsForCmdArgumentHandler() { super.createOptionsForCmdArgumentHandler(); - Option checksumTypeOption = new Option(Constants.REQUEST_CHECKSUM_TYPE_ARG, Constants.HAS_ARGUMENT, + Option checksumTypeOption = new Option(Constants.REQUEST_CHECKSUM_TYPE_ARG, Constants.HAS_ARGUMENT, "[OPTIONAL] The algorithm of checksum to request in the response from the pillars. " + "If no such argument is given, then the default from settings is retrieved."); checksumTypeOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); cmdHandler.addOption(checksumTypeOption); - Option checksumSaltOption = new Option(Constants.REQUEST_CHECKSUM_SALT_ARG, Constants.HAS_ARGUMENT, + Option checksumSaltOption = new Option(Constants.REQUEST_CHECKSUM_SALT_ARG, Constants.HAS_ARGUMENT, "[OPTIONAL] The salt of checksum to request in the response. Requires the ChecksumType argument."); checksumSaltOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); cmdHandler.addOption(checksumSaltOption); @@ -95,9 +91,9 @@ protected void createOptionsForCmdArgumentHandler() { protected void performOperation() { ChecksumSpecTYPE spec = getRequestChecksumSpecOrDefault(); output.startupInfo("Performing the GetChecksums operation."); - Boolean success = pagingClient.getChecksums(getCollectionID(), getFileIDs(), + boolean success = pagingClient.getChecksums(getCollectionID(), getFileIDs(), getPillarIDs(), spec); - if(success) { + if (success) { System.exit(Constants.EXIT_SUCCESS); } else { System.exit(Constants.EXIT_OPERATION_FAILURE); @@ -105,11 +101,12 @@ protected void performOperation() { } /** - * Retrieves the given output formatter depending on whether or not it requests a given file or all files. + * Retrieves the given output formatter depending on whether it requests a given file or all files. + * * @return The output formatter. */ private GetChecksumsOutputFormatter retrieveOutputFormatter() { - if(cmdHandler.hasOption(Constants.FILE_ID_ARG)) { + if (cmdHandler.hasOption(Constants.FILE_ID_ARG)) { return new GetChecksumDistributionFormatter(output); } else { return new GetChecksumsInfoFormatter(output); diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/GetFileCmd.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/GetFileCmd.java index 49a5d5d99..b5c92fe55 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/GetFileCmd.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/GetFileCmd.java @@ -5,16 +5,16 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -30,7 +30,6 @@ import org.bitrepository.commandline.eventhandler.GetFileEventHandler; import org.bitrepository.protocol.FileExchange; import org.bitrepository.protocol.ProtocolComponentFactory; -import org.bitrepository.protocol.http.HttpFileExchange; import java.io.File; import java.net.MalformedURLException; @@ -40,9 +39,7 @@ * Perform the GetFile operation. */ public class GetFileCmd extends CommandLineClient { - /** The client for performing the GetFile operation.*/ private final GetFileClient client; - /** The URL for where the file from the GetFile*/ private URL fileUrl = null; /** @@ -63,7 +60,7 @@ public static void main(String[] args) { /** * @param args The command line arguments for defining the operation. */ - protected GetFileCmd(String ... args) { + protected GetFileCmd(String... args) { super(args); client = AccessComponentFactory.getInstance().createGetFileClient(settings, securityManager, getComponentID()); @@ -94,7 +91,7 @@ public void performOperation() { output.debug("Results of the GetFile operation for the file '" + cmdHandler.getOptionValue(Constants.FILE_ID_ARG) + "'" + ": " + finalEvent); - if(finalEvent.getEventType() == OperationEventType.COMPLETE) { + if (finalEvent.getEventType() == OperationEventType.COMPLETE) { downloadFile(); output.resultLine(fileArg + " retrieved"); System.exit(Constants.EXIT_SUCCESS); @@ -105,6 +102,7 @@ public void performOperation() { /** * Initiates the operation and waits for the results. + * * @return The final event for the results of the operation. Either 'FAILURE' or 'COMPLETE'. */ private OperationEvent performConversation() { @@ -114,7 +112,7 @@ private OperationEvent performConversation() { CompleteEventAwaiter eventHandler = new GetFileEventHandler(settings, output); output.debug("Initiating the GetFile conversation."); - if(cmdHandler.hasOption(Constants.PILLAR_ARG)) { + if (cmdHandler.hasOption(Constants.PILLAR_ARG)) { String pillarID = cmdHandler.getOptionValue(Constants.PILLAR_ARG); client.getFileFromSpecificPillar(getCollectionID(), fileID, null, fileUrl, pillarID, eventHandler, null); } else { @@ -130,9 +128,9 @@ private OperationEvent performConversation() { private void downloadFile() { output.debug("Downloading the file."); File outputFile; - if(cmdHandler.hasOption(Constants.LOCATION)) { + if (cmdHandler.hasOption(Constants.LOCATION)) { File location = new File(cmdHandler.getOptionValue(Constants.LOCATION)); - if(location.isDirectory()) { + if (location.isDirectory()) { outputFile = new File(location, cmdHandler.getOptionValue(Constants.FILE_ID_ARG)); } else { outputFile = location; @@ -146,6 +144,7 @@ private void downloadFile() { /** * Extracts the URL for where the file should be delivered from the GetFile operation. + * * @param fileID The id of the file. * @return The URL where the file should be located. */ diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/GetFileIDsCmd.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/GetFileIDsCmd.java index ef95fd9a7..bb9b447c9 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/GetFileIDsCmd.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/GetFileIDsCmd.java @@ -5,16 +5,16 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -32,7 +32,6 @@ * Perform the GetFileIDs operation. */ public class GetFileIDsCmd extends CommandLineClient { - /** The client for performing the actual operation.*/ private final PagingGetFileIDsClient pagingClient; /** @@ -53,17 +52,17 @@ public static void main(String[] args) { /** * @param args The command line arguments for defining the operation. */ - protected GetFileIDsCmd(String ... args) { + protected GetFileIDsCmd(String... args) { super(args); output.debug("Instantiation GetFileIDClient."); - GetFileIDsClient client = AccessComponentFactory.getInstance().createGetFileIDsClient(settings, + GetFileIDsClient client = AccessComponentFactory.getInstance().createGetFileIDsClient(settings, securityManager, getComponentID()); output.debug("Instantiation GetFileID outputFormatter."); GetFileIDsOutputFormatter outputFormatter = new GetFileIDsInfoFormatter(output); output.debug("Instantiation GetFileID paging client."); int pageSize = SettingsUtils.getMaxClientPageSize(); - pagingClient = new PagingGetFileIDsClient(client, getTimeout(), pageSize, outputFormatter, output); + pagingClient = new PagingGetFileIDsClient(client, getTimeout(), pageSize, outputFormatter, output); } @Override @@ -76,8 +75,8 @@ protected boolean isFileIDArgumentRequired() { */ public void performOperation() { output.startupInfo("Performing the GetFileIDs operation."); - Boolean success = pagingClient.getFileIDs(getCollectionID(), getFileIDs(), getPillarIDs()); - if(success) { + boolean success = pagingClient.getFileIDs(getCollectionID(), getFileIDs(), getPillarIDs()); + if (success) { System.exit(Constants.EXIT_SUCCESS); } else { System.exit(Constants.EXIT_OPERATION_FAILURE); diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/PutFileCmd.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/PutFileCmd.java index 614879188..60353c0b3 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/PutFileCmd.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/PutFileCmd.java @@ -172,7 +172,6 @@ private OperationEvent putTheFile() { return finalEvent; } - /** * Retrieves the Checksum of the file, used by the pillars to validate. * This checksum is either taken from the actual file, or from the checksum argument. diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/ReplaceFileCmd.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/ReplaceFileCmd.java index daad363ad..02020e071 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/ReplaceFileCmd.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/ReplaceFileCmd.java @@ -5,24 +5,22 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.commandline; -import java.net.URL; - import org.apache.commons.cli.Option; import org.bitrepository.bitrepositoryelements.ChecksumDataForFileTYPE; import org.bitrepository.bitrepositoryelements.ChecksumSpecTYPE; @@ -33,14 +31,11 @@ import org.bitrepository.modify.ModifyComponentFactory; import org.bitrepository.modify.replacefile.ReplaceFileClient; +import java.net.URL; + import static org.bitrepository.commandline.Constants.*; -/** - * Replace a file from the collection. - * - */ public class ReplaceFileCmd extends CommandLineClient { - /** The client for performing the ReplaceFile operation.*/ private final ReplaceFileClient client; /** @@ -61,10 +56,9 @@ public static void main(String[] args) { /** * @param args The command line arguments for defining the operation. */ - protected ReplaceFileCmd(String ... args) { + protected ReplaceFileCmd(String... args) { super(args); - client = ModifyComponentFactory.getInstance().retrieveReplaceFileClient(settings, securityManager, - getComponentID()); + client = ModifyComponentFactory.getInstance().retrieveReplaceFileClient(settings, securityManager, getComponentID()); } @Override @@ -76,8 +70,7 @@ protected boolean isFileIDArgumentRequired() { protected void createOptionsForCmdArgumentHandler() { super.createOptionsForCmdArgumentHandler(); - Option checksumOption = new Option(CHECKSUM_ARG, HAS_ARGUMENT, - "[OPTIONAL] The checksum of the file to be replaced."); + Option checksumOption = new Option(CHECKSUM_ARG, HAS_ARGUMENT, "[OPTIONAL] The checksum of the file to be replaced."); checksumOption.setRequired(ARGUMENT_IS_NOT_REQUIRED); cmdHandler.addOption(checksumOption); Option fileOption = new Option(FILE_ARG, HAS_ARGUMENT, @@ -85,7 +78,7 @@ protected void createOptionsForCmdArgumentHandler() { fileOption.setRequired(ARGUMENT_IS_NOT_REQUIRED); cmdHandler.addOption(fileOption); Option urlOption = new Option(URL_ARG, HAS_ARGUMENT, - "The URL for the file to be retreived. Is required, unless the actual file is given."); + "The URL for the file to be retrieved. Is required, unless the actual file is given."); urlOption.setRequired(ARGUMENT_IS_NOT_REQUIRED); cmdHandler.addOption(urlOption); Option replaceChecksumOption = new Option(REPLACE_CHECKSUM_ARG, HAS_ARGUMENT, @@ -103,8 +96,7 @@ protected void createOptionsForCmdArgumentHandler() { cmdHandler.addOption(checksumSaltOption); Option deleteOption = new Option(DELETE_FILE_ARG, NO_ARGUMENT, - "If this argument is present, then the file will be removed from the server, " - + "when the operation is complete."); + "If this argument is present, then the file will be removed from the server, when the operation is complete."); deleteOption.setRequired(ARGUMENT_IS_NOT_REQUIRED); cmdHandler.addOption(deleteOption); } @@ -112,38 +104,37 @@ protected void createOptionsForCmdArgumentHandler() { /** * Run the default validation, and the following replace-file specific validations. * Requires the pillar argument, since the client only may replace at one pillar at the time. - * If settings require a checksum for "destructive requests" - like replace - then the checksum argument is + * If settings require a checksum for "destructive requests" - like replace - then the checksum argument is * also required. - * - * It must take either the actual file or an URL is given for the file to replace. - * Also, if it is an URL is given, then it must also be given the checksum and the file id. + *

    + * It must take either the actual file or a URL is given for the file to replace. + * Also, if it is a URL is given, then it must also be given the checksum and the file id. */ @Override protected void validateArguments() { super.validateArguments(); - if(!cmdHandler.hasOption(PILLAR_ARG)) { - throw new IllegalArgumentException("The pillar argument (-p) must defined for the Replace operation, " + - "only single pillar Replaces are allowed"); + if (!cmdHandler.hasOption(PILLAR_ARG)) { + throw new IllegalArgumentException( + "The pillar argument (-p) must defined for the Replace operation, " + "only single pillar Replaces are allowed"); } if (!cmdHandler.hasOption(CHECKSUM_ARG) && settings.getRepositorySettings().getProtocolSettings().isRequireChecksumForDestructiveRequests()) { - throw new IllegalArgumentException("Checksum argument (-C) are mandatory for Replace and replace " - + "operations as defined in RepositorySettings."); + throw new IllegalArgumentException( + "Checksum argument (-C) are mandatory for Replace and replace " + "operations as defined in RepositorySettings."); } - if(cmdHandler.hasOption(FILE_ARG) && cmdHandler.hasOption(URL_ARG)) { + if (cmdHandler.hasOption(FILE_ARG) && cmdHandler.hasOption(URL_ARG)) { throw new IllegalArgumentException("Cannot take both a file (-f) and an URL (-u) as argument."); } - if(!cmdHandler.hasOption(FILE_ARG) && !cmdHandler.hasOption(URL_ARG)) { + if (!cmdHandler.hasOption(FILE_ARG) && !cmdHandler.hasOption(URL_ARG)) { throw new IllegalArgumentException("Requires either the file argument (-f) or the URL argument (-u)."); } - if(cmdHandler.hasOption(URL_ARG) && !cmdHandler.hasOption(REPLACE_CHECKSUM_ARG)) { - throw new IllegalArgumentException("The URL argument requires also the checksum argument for the file " - + "to replace with (-r)."); + if (cmdHandler.hasOption(URL_ARG) && !cmdHandler.hasOption(REPLACE_CHECKSUM_ARG)) { + throw new IllegalArgumentException( + "The URL argument requires also the checksum argument for the file " + "to replace with (-r)."); } - if(cmdHandler.hasOption(URL_ARG) && !cmdHandler.hasOption(FILE_ID_ARG)) { - throw new IllegalArgumentException("The URL argument requires also the argument for the ID of the " - + "file (-i)."); + if (cmdHandler.hasOption(URL_ARG) && !cmdHandler.hasOption(FILE_ID_ARG)) { + throw new IllegalArgumentException("The URL argument requires also the argument for the ID of the " + "file (-i)."); } } @@ -151,10 +142,9 @@ protected void validateArguments() { public void performOperation() { output.debug("Performing the ReplaceFile operation."); OperationEvent finalEvent = replaceTheFile(); - output.completeEvent("Results of the ReplaceFile operation for the file '" - + cmdHandler.getOptionValue(FILE_ID_ARG) + "'" - + ": ", finalEvent); - if(finalEvent.getEventType() == OperationEventType.COMPLETE) { + output.completeEvent("Results of the ReplaceFile operation for the file '" + cmdHandler.getOptionValue(FILE_ID_ARG) + "'" + ": ", + finalEvent); + if (finalEvent.getEventType() == OperationEventType.COMPLETE) { System.exit(EXIT_SUCCESS); } else { System.exit(EXIT_OPERATION_FAILURE); @@ -163,6 +153,7 @@ public void performOperation() { /** * Initiates the operation and waits for the results. + * * @return The final event for the results of the operation. Either 'FAILURE' or 'COMPLETE'. */ private OperationEvent replaceTheFile() { @@ -181,29 +172,28 @@ private OperationEvent replaceTheFile() { output.resultHeader("PillarId results"); } - client.replaceFile(getCollectionID(), fileID, pillarID, replaceValidationChecksum, - requestChecksum, url, getSizeOfFileOrZero(), newValidationChecksum, - requestChecksum, eventHandler, null); + client.replaceFile(getCollectionID(), fileID, pillarID, replaceValidationChecksum, requestChecksum, url, getSizeOfFileOrZero(), + newValidationChecksum, requestChecksum, eventHandler, null); - OperationEvent finalEvent = eventHandler.getFinish(); + OperationEvent finalEvent = eventHandler.getFinish(); - if(cmdHandler.hasOption(DELETE_FILE_ARG)) { + if (cmdHandler.hasOption(DELETE_FILE_ARG)) { deleteFileAfterwards(url); } return finalEvent; } - /** - * Retrieves the Checksum for the pillars to validate, either taken from the actual file, + * Retrieves the Checksum for the pillars to validate, either taken from the actual file, * or from the checksum argument. * It will be in the default checksum spec type from settings. + * * @return The checksum validation type. */ protected ChecksumDataForFileTYPE getValidationChecksum() { - if(cmdHandler.hasOption(FILE_ARG)) { - return getValidationChecksumDataForFile(findTheFile()); + if (cmdHandler.hasOption(FILE_ARG)) { + return getValidationChecksumDataForFile(findTheFile()); } else { return getValidationChecksumDataFromArgument(REPLACE_CHECKSUM_ARG); } diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/clients/PagingGetChecksumsClient.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/clients/PagingGetChecksumsClient.java index 5cc246689..6609c5d12 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/clients/PagingGetChecksumsClient.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/clients/PagingGetChecksumsClient.java @@ -5,16 +5,16 @@ * Copyright (C) 2010 - 2013 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -35,38 +35,36 @@ import java.util.List; /** - * Wrapper class for GetChecksumClient to handle paging through large result sets + * Wrapper class for GetChecksumClient to handle paging through large result sets */ public class PagingGetChecksumsClient { - private final GetChecksumsClient client; private GetChecksumsResultModel model; - private GetChecksumsEventHandler eventHandler; private final GetChecksumsOutputFormatter outputFormatter; private final OutputHandler outputHandler; - private long timeout; + private final long timeout; private final int pageSize; - + public PagingGetChecksumsClient(GetChecksumsClient client, long timeout, int pageSize, GetChecksumsOutputFormatter outputFormatter, - OutputHandler outputHandler) { + OutputHandler outputHandler) { this.client = client; this.timeout = timeout; this.pageSize = pageSize; this.outputFormatter = outputFormatter; this.outputHandler = outputHandler; } - + public boolean getChecksums(String collectionID, String fileID, List pillarIDs, ChecksumSpecTYPE checksumSpec) { model = new GetChecksumsResultModel(pillarIDs); List pillarsToGetFrom = pillarIDs; outputFormatter.formatHeader(); - - while(!pillarsToGetFrom.isEmpty()) { - eventHandler = new GetChecksumsEventHandler(model, timeout, outputHandler); + + while (!pillarsToGetFrom.isEmpty()) { + GetChecksumsEventHandler eventHandler = new GetChecksumsEventHandler(model, timeout, outputHandler); ContributorQuery[] queries = makeQuery(pillarsToGetFrom); client.getChecksums(collectionID, queries, fileID, checksumSpec, null, eventHandler, null); OperationEvent event = eventHandler.getFinish(); - if(event.getEventType().equals(OperationEvent.OperationEventType.FAILED)) { + if (event.getEventType().equals(OperationEvent.OperationEventType.FAILED)) { outputFormatter.formatResult(model.getUncompletedResults()); return false; } @@ -76,11 +74,11 @@ public boolean getChecksums(String collectionID, String fileID, List pil outputFormatter.formatResult(model.getUncompletedResults()); return true; } - - + + private ContributorQuery[] makeQuery(List pillars) { List res = new ArrayList<>(); - for(String pillar : pillars) { + for (String pillar : pillars) { Date latestResult = model.getLatestContribution(pillar); res.add(new ContributorQuery(pillar, latestResult, null, pageSize)); } diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/clients/PagingGetFileIDsClient.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/clients/PagingGetFileIDsClient.java index f13604d08..eca451cc5 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/clients/PagingGetFileIDsClient.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/clients/PagingGetFileIDsClient.java @@ -5,26 +5,22 @@ * Copyright (C) 2010 - 2013 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.commandline.clients; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - import org.bitrepository.access.ContributorQuery; import org.bitrepository.access.getfileids.GetFileIDsClient; import org.bitrepository.client.eventhandler.OperationEvent; @@ -33,39 +29,41 @@ import org.bitrepository.commandline.outputformatter.GetFileIDsOutputFormatter; import org.bitrepository.commandline.resultmodel.GetFileIDsResultModel; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + /** - * Wrapper class for GetFileIDsClient to handle paging through large result sets + * Wrapper class for GetFileIDsClient to handle paging through large result sets */ public class PagingGetFileIDsClient { - private final GetFileIDsClient client; private GetFileIDsResultModel model; - private GetFileIDsEventHandler eventHandler; - private GetFileIDsOutputFormatter outputFormatter; + private final GetFileIDsOutputFormatter outputFormatter; private final OutputHandler outputHandler; - private long timeout; + private final long timeout; private final int pageSize; - + public PagingGetFileIDsClient(GetFileIDsClient client, long timeout, int pageSize, GetFileIDsOutputFormatter outputFormatter, - OutputHandler outputHandler) { + OutputHandler outputHandler) { this.client = client; this.timeout = timeout; this.pageSize = pageSize; this.outputFormatter = outputFormatter; this.outputHandler = outputHandler; } - + public boolean getFileIDs(String collectionID, String fileID, List pillarIDs) { model = new GetFileIDsResultModel(pillarIDs); List pillarsToGetFrom = pillarIDs; outputFormatter.formatHeader(); - - while(!pillarsToGetFrom.isEmpty()) { - eventHandler = new GetFileIDsEventHandler(model, timeout, outputHandler); + + while (!pillarsToGetFrom.isEmpty()) { + GetFileIDsEventHandler eventHandler = new GetFileIDsEventHandler(model, timeout, outputHandler); ContributorQuery[] queries = makeQuery(pillarsToGetFrom); client.getFileIDs(collectionID, queries, fileID, null, eventHandler); OperationEvent event = eventHandler.getFinish(); - if(event.getEventType().equals(OperationEvent.OperationEventType.FAILED)) { + if (event.getEventType().equals(OperationEvent.OperationEventType.FAILED)) { outputFormatter.formatResult(model.getUncompletedResults()); return false; } @@ -75,10 +73,10 @@ public boolean getFileIDs(String collectionID, String fileID, List pilla outputFormatter.formatResult(model.getUncompletedResults()); return true; } - + private ContributorQuery[] makeQuery(List pillars) { List res = new ArrayList<>(); - for(String pillar : pillars) { + for (String pillar : pillars) { Date latestResult = model.getLatestContribution(pillar); res.add(new ContributorQuery(pillar, latestResult, null, pageSize)); } diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/CompleteEventAwaiter.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/CompleteEventAwaiter.java index 76329fd37..1e40dabfd 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/CompleteEventAwaiter.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/CompleteEventAwaiter.java @@ -5,48 +5,53 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.commandline.eventhandler; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.TimeUnit; - import org.bitrepository.client.eventhandler.EventHandler; import org.bitrepository.client.eventhandler.OperationEvent; import org.bitrepository.client.eventhandler.OperationEvent.OperationEventType; import org.bitrepository.commandline.output.OutputHandler; import org.bitrepository.common.settings.Settings; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; + /** * EventHandler for awaiting an operation to be complete. * Just use the 'getFinish()' for awaiting the final event (either FAILURE or COMPLETE). */ public abstract class CompleteEventAwaiter implements EventHandler { - /** The amount of milliseconds before the results are required.*/ + /** + * The amount of milliseconds before the results are required. + */ private final Long timeout; - /** The handler of the output for this event handler.*/ + /** + * The handler of the output for this event handler. + */ protected final OutputHandler output; - - /** The queue used to store the received operation events. */ + + /** + * The queue used to store the received operation events. + */ private final BlockingQueue finalEventQueue = new LinkedBlockingQueue<>(1); /** - * Constructor. - * @param settings The settings. + * @param settings The settings. * @param outputHandler The {@link OutputHandler} for handling outputting results */ public CompleteEventAwaiter(Settings settings, OutputHandler outputHandler) { @@ -54,27 +59,28 @@ public CompleteEventAwaiter(Settings settings, OutputHandler outputHandler) { + settings.getRepositorySettings().getClientSettings().getOperationTimeout().longValue(); this.output = outputHandler; } - + @Override public void handleEvent(OperationEvent event) { - if(event.getEventType() == OperationEventType.COMPLETE) { - output.debug("Complete: " + event.toString()); + if (event.getEventType() == OperationEventType.COMPLETE) { + output.debug("Complete: " + event); finalEventQueue.add(event); - } else if(event.getEventType() == OperationEventType.FAILED) { - output.warn("Failure: " + event.toString()); + } else if (event.getEventType() == OperationEventType.FAILED) { + output.warn("Failure: " + event); finalEventQueue.add(event); - } else if(event.getEventType() == OperationEventType.COMPONENT_COMPLETE) { + } else if (event.getEventType() == OperationEventType.COMPONENT_COMPLETE) { handleComponentComplete(event); } else { - output.debug("Received event: " + event.toString()); + output.debug("Received event: " + event); } } - + public abstract void handleComponentComplete(OperationEvent event); - + /** - * Retrieves the final event when the operation finishes. The final event is awaited for 'timeout' amount + * Retrieves the final event when the operation finishes. The final event is awaited for 'timeout' amount * of milliseconds. If no final events has occurred, then an InterruptedException is thrown. + * * @return The final event. */ public OperationEvent getFinish() { diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/DeleteFileEventHandler.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/DeleteFileEventHandler.java index d53714446..98d79b113 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/DeleteFileEventHandler.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/DeleteFileEventHandler.java @@ -8,12 +8,12 @@ * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * + * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . @@ -28,14 +28,15 @@ import org.bitrepository.modify.deletefile.conversation.DeleteFileCompletePillarEvent; /** - * Complete event awaiter for Getfile. + * Complete event awaiter for GetFile. * Prints out checksum results, if any. */ public class DeleteFileEventHandler extends CompleteEventAwaiter { /** * Constructor. - * @param settings The {@link Settings} + * + * @param settings The {@link Settings} * @param outputHandler The {@link OutputHandler} for handling output */ public DeleteFileEventHandler(Settings settings, OutputHandler outputHandler) { @@ -44,14 +45,16 @@ public DeleteFileEventHandler(Settings settings, OutputHandler outputHandler) { @Override public void handleComponentComplete(OperationEvent event) { - if(!(event instanceof DeleteFileCompletePillarEvent)) { + if (!(event instanceof DeleteFileCompletePillarEvent)) { output.warn("DeleteFileEventHandler received a component complete, which is not a " + DeleteFileCompletePillarEvent.class.getName()); } - + + assert event instanceof DeleteFileCompletePillarEvent; DeleteFileCompletePillarEvent pillarEvent = (DeleteFileCompletePillarEvent) event; - if(pillarEvent.getChecksums() != null) { - output.resultLine(pillarEvent.getContributorID() + " \t " + Base16Utils.decodeBase16(pillarEvent.getChecksums().getChecksumValue())); + if (pillarEvent.getChecksums() != null) { + output.resultLine( + pillarEvent.getContributorID() + " \t " + Base16Utils.decodeBase16(pillarEvent.getChecksums().getChecksumValue())); } } diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/GetChecksumsEventHandler.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/GetChecksumsEventHandler.java index 558a4a100..4b2808976 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/GetChecksumsEventHandler.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/GetChecksumsEventHandler.java @@ -5,16 +5,16 @@ * Copyright (C) 2010 - 2013 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -27,24 +27,24 @@ import org.bitrepository.commandline.resultmodel.GetChecksumsResultModel; /** - * Event handler for paging through GetChecksums results + * Event handler for paging through GetChecksums results */ public class GetChecksumsEventHandler extends PagingEventHandler { - private GetChecksumsResultModel model; - + private final GetChecksumsResultModel model; + public GetChecksumsEventHandler(GetChecksumsResultModel model, Long timeout, OutputHandler outputHandler) { super(timeout, outputHandler); this.model = model; } protected void handleResult(OperationEvent event) { - if(event instanceof ChecksumsCompletePillarEvent) { + if (event instanceof ChecksumsCompletePillarEvent) { ChecksumsCompletePillarEvent pillarEvent = (ChecksumsCompletePillarEvent) event; - if(pillarEvent.isPartialResult()) { + if (pillarEvent.isPartialResult()) { pillarsWithPartialResults.add(pillarEvent.getContributorID()); } model.addResults(pillarEvent.getContributorID(), pillarEvent.getChecksums()); - } + } } } diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/GetFileEventHandler.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/GetFileEventHandler.java index 8ee8a88cd..307368203 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/GetFileEventHandler.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/GetFileEventHandler.java @@ -8,12 +8,12 @@ * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * + * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . @@ -26,14 +26,15 @@ import org.bitrepository.common.settings.Settings; /** - * Complete event awaiter for Getfile. - * Nothing to add. + * Complete event awaiter for GetFile. + * Nothing to add. */ public class GetFileEventHandler extends CompleteEventAwaiter { /** * Constructor. - * @param settings The {@link Settings} + * + * @param settings The {@link Settings} * @param outputHandler The {@link OutputHandler} for handling output */ public GetFileEventHandler(Settings settings, OutputHandler outputHandler) { @@ -41,5 +42,5 @@ public GetFileEventHandler(Settings settings, OutputHandler outputHandler) { } @Override - public void handleComponentComplete(OperationEvent event) { } + public void handleComponentComplete(OperationEvent event) {} } diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/GetFileIDsEventHandler.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/GetFileIDsEventHandler.java index bad3e8eac..58927d1ca 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/GetFileIDsEventHandler.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/GetFileIDsEventHandler.java @@ -5,16 +5,16 @@ * Copyright (C) 2010 - 2013 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -27,20 +27,20 @@ import org.bitrepository.commandline.resultmodel.GetFileIDsResultModel; /** - * Event handler for paging through GetFileIDs results + * Event handler for paging through GetFileIDs results */ public class GetFileIDsEventHandler extends PagingEventHandler { - private GetFileIDsResultModel model; - + private final GetFileIDsResultModel model; + public GetFileIDsEventHandler(GetFileIDsResultModel model, Long timeout, OutputHandler outputHandler) { super(timeout, outputHandler); this.model = model; } - + protected void handleResult(OperationEvent event) { - if(event instanceof FileIDsCompletePillarEvent) { + if (event instanceof FileIDsCompletePillarEvent) { FileIDsCompletePillarEvent pillarEvent = (FileIDsCompletePillarEvent) event; - if(pillarEvent.isPartialResult()) { + if (pillarEvent.isPartialResult()) { pillarsWithPartialResults.add(pillarEvent.getContributorID()); } model.addResults(pillarEvent.getContributorID(), pillarEvent.getFileIDs()); diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/PagingEventHandler.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/PagingEventHandler.java index 1591ad692..e8d31a170 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/PagingEventHandler.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/PagingEventHandler.java @@ -5,68 +5,66 @@ * Copyright (C) 2010 - 2013 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.commandline.eventhandler; +import org.bitrepository.client.eventhandler.EventHandler; +import org.bitrepository.client.eventhandler.OperationEvent; +import org.bitrepository.client.eventhandler.OperationEvent.OperationEventType; +import org.bitrepository.commandline.output.OutputHandler; + import java.util.ArrayList; import java.util.List; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; -import org.bitrepository.client.eventhandler.EventHandler; -import org.bitrepository.client.eventhandler.OperationEvent; -import org.bitrepository.client.eventhandler.OperationEvent.OperationEventType; -import org.bitrepository.commandline.output.OutputHandler; - /** - * Event handler for operations that need paging functionality. + * Event handler for operations that need paging functionality. */ public abstract class PagingEventHandler implements EventHandler { - - /** The amount of milliseconds before the results are required.*/ private final Long timeout; - /** The queue used to store the received operation events. */ private final BlockingQueue finalEventQueue = new LinkedBlockingQueue<>(1); - + protected List pillarsWithPartialResults = new ArrayList<>(); - + private final OutputHandler outputHandler; public PagingEventHandler(Long timeout, OutputHandler outputHandler) { this.timeout = timeout; this.outputHandler = outputHandler; } - + @Override public void handleEvent(OperationEvent event) { - if(event.getEventType() == OperationEventType.COMPONENT_COMPLETE) { + if (event.getEventType() == OperationEventType.COMPONENT_COMPLETE) { handleResult(event); - } else if(event.getEventType() == OperationEventType.COMPLETE) { + } else if (event.getEventType() == OperationEventType.COMPLETE) { finalEventQueue.add(event); - } else if(event.getEventType() == OperationEventType.FAILED) { + } else if (event.getEventType() == OperationEventType.FAILED) { finalEventQueue.add(event); } else { - outputHandler.debug("Received event: " + event.toString()); + outputHandler.debug("Received event: " + event); } } - + /** - * Retrieves the final event when the operation finishes. The final event is awaited for 'timeout' amount + * Retrieves the final event when the operation finishes. The final event is awaited for 'timeout' amount * of milliseconds. If no final events has occurred, then an IllegalStateException is thrown. + * * @return The final event. */ public OperationEvent getFinish() { @@ -76,14 +74,15 @@ public OperationEvent getFinish() { throw new IllegalStateException("Interrupted while waiting for the final response.", e); } } - + /** - * Gets the list of pillars who's latest result was partial, i.e. the pillars that needs to deliver more results - * @return the list of pillarIDs. + * Gets the list of pillars who most recently gave a partial result, i.e. the pillars that need to deliver more results. + * + * @return the list of pillarIDs. */ public List getPillarsWithPartialResults() { return pillarsWithPartialResults; } - + protected abstract void handleResult(OperationEvent event); } diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/PutFileEventHandler.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/PutFileEventHandler.java index 9be4e724f..3afe45335 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/PutFileEventHandler.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/PutFileEventHandler.java @@ -8,12 +8,12 @@ * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * + * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . @@ -28,38 +28,41 @@ import org.bitrepository.modify.putfile.conversation.PutFileCompletePillarEvent; /** - * Complete event awaiter for Getfile. + * Complete event awaiter for GetFile. * Prints out checksum results, if any. */ public class PutFileEventHandler extends CompleteEventAwaiter { private final Boolean printOutput; - + /** * Constructor. - * @param settings The {@link Settings} + * + * @param settings The {@link Settings} * @param outputHandler The {@link OutputHandler} for handling output - * @param printOutput Setting for determining if output should be printet + * @param printOutput Setting for determining if output should be printed. */ public PutFileEventHandler(Settings settings, OutputHandler outputHandler, boolean printOutput) { super(settings, outputHandler); this.printOutput = printOutput; - - if(printOutput) { + + if (printOutput) { output.resultHeader("PillarId \t Checksum"); } } @Override public void handleComponentComplete(OperationEvent event) { - if(!(event instanceof PutFileCompletePillarEvent)) { + if (!(event instanceof PutFileCompletePillarEvent)) { output.warn("PutFileEventHandler received a component complete, which is not a " + PutFileCompletePillarEvent.class.getName()); } - + + assert event instanceof PutFileCompletePillarEvent; PutFileCompletePillarEvent pillarEvent = (PutFileCompletePillarEvent) event; - if(printOutput && pillarEvent.getChecksums() != null) { - output.resultLine(pillarEvent.getContributorID() + " \t " + Base16Utils.decodeBase16(pillarEvent.getChecksums().getChecksumValue())); + if (printOutput && pillarEvent.getChecksums() != null) { + output.resultLine( + pillarEvent.getContributorID() + " \t " + Base16Utils.decodeBase16(pillarEvent.getChecksums().getChecksumValue())); } } diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/ReplaceFileEventHandler.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/ReplaceFileEventHandler.java index 950e84bb1..c6e9d4e6a 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/ReplaceFileEventHandler.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/eventhandler/ReplaceFileEventHandler.java @@ -8,12 +8,12 @@ * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * + * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . @@ -35,7 +35,8 @@ public class ReplaceFileEventHandler extends CompleteEventAwaiter { /** * Constructor. - * @param settings The settings. + * + * @param settings The settings. * @param outputHandler The output handler. */ public ReplaceFileEventHandler(Settings settings, OutputHandler outputHandler) { @@ -44,25 +45,26 @@ public ReplaceFileEventHandler(Settings settings, OutputHandler outputHandler) { @Override public void handleComponentComplete(OperationEvent event) { - if(!(event instanceof ReplaceFileCompletePillarEvent)) { - output.warn("ReplaceFileEventHandler received a component complete, which is not a " - + ReplaceFileCompletePillarEvent.class.getName()); + if (!(event instanceof ReplaceFileCompletePillarEvent)) { + output.warn("ReplaceFileEventHandler received a component complete, which is not a " + + ReplaceFileCompletePillarEvent.class.getName()); } - + + assert event instanceof ReplaceFileCompletePillarEvent; ReplaceFileCompletePillarEvent pillarEvent = (ReplaceFileCompletePillarEvent) event; StringBuilder componentText = new StringBuilder(); - if(pillarEvent.getChecksumForReplacedFile() != null) { - componentText.append("Checksum for replaced file: " - + Base16Utils.decodeBase16(pillarEvent.getChecksumForReplacedFile().getChecksumValue()) + "\t"); + if (pillarEvent.getChecksumForReplacedFile() != null) { + componentText.append("Checksum for replaced file: ") + .append(Base16Utils.decodeBase16(pillarEvent.getChecksumForReplacedFile().getChecksumValue())).append("\t"); } - - if(pillarEvent.getChecksumForNewFile() != null) { - componentText.append("Checksum for new file: " - + Base16Utils.decodeBase16(pillarEvent.getChecksumForNewFile().getChecksumValue()) + "\t"); + + if (pillarEvent.getChecksumForNewFile() != null) { + componentText.append("Checksum for new file: ") + .append(Base16Utils.decodeBase16(pillarEvent.getChecksumForNewFile().getChecksumValue())).append("\t"); } - - if(componentText.length() != 0) { - output.resultLine(pillarEvent.getContributorID() + " : \t" + componentText.toString()); + + if (componentText.length() != 0) { + output.resultLine(pillarEvent.getContributorID() + " : \t" + componentText); } } } diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/output/DefaultOutputHandler.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/output/DefaultOutputHandler.java index aafe9ab2b..839319137 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/output/DefaultOutputHandler.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/output/DefaultOutputHandler.java @@ -5,16 +5,16 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -31,7 +31,7 @@ public class DefaultOutputHandler implements OutputHandler { private final Logger log; private boolean verbose = false; - + /** * @param c The class for whom to handle the output. */ @@ -39,7 +39,7 @@ public class DefaultOutputHandler implements OutputHandler { public DefaultOutputHandler(Class c) { log = LoggerFactory.getLogger(c); } - + @Override public void debug(String debug) { log.debug(debug); @@ -47,7 +47,7 @@ public void debug(String debug) { @Override public void startupInfo(String s) { - if(verbose) { + if (verbose) { System.err.println(s); } } @@ -57,7 +57,7 @@ public void warn(String warning) { System.err.println(warning); log.warn(warning); } - + @Override public void error(String error, Throwable e) { System.err.println(error); @@ -72,7 +72,7 @@ public void error(String error) { @Override public void completeEvent(String msg, OperationEvent event) { - if(verbose) { + if (verbose) { System.err.println("Final Result: " + event.getEventType()); } log.info(msg); @@ -88,7 +88,7 @@ public void resultLine(String line) { public void resultHeader(String header) { System.out.println(header); } - + public void setVerbosity(boolean verbose) { this.verbose = verbose; } diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/output/OutputHandler.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/output/OutputHandler.java index 2008ec0ce..b73494427 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/output/OutputHandler.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/output/OutputHandler.java @@ -5,16 +5,16 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -29,56 +29,65 @@ public interface OutputHandler { /** * Handles the debug information for the commandline client. + * * @param debug The debug information to be handled. */ void debug(String debug); - + /** - * Handles the startup information for the commandline client. + * Handles the startup information for the commandline client. + * * @param info The information to be handled. */ void startupInfo(String info); - + /** * Handles the complete events. - * @param msg The message regarding the complete event. + * + * @param msg The message regarding the complete event. * @param event The final event to handle. */ void completeEvent(String msg, OperationEvent event); - + /** * Handles a warning for the commandline client. + * * @param warning The warning to be handled. */ void warn(String warning); - - /** + + /** * Handles an error. + * * @param error The message for the error. */ void error(String error); /** * Handles an error. + * * @param error The message for the error. - * @param e The throwable for the error. + * @param e The throwable for the error. */ void error(String error, Throwable e); - + /** - * Handles the outputting of a line of results + * Handles the outputting of a line of results + * * @param line the line to output */ void resultLine(String line); - + /** - * Handles the outputting of the header (or ledgend) of the following lines + * Handles the outputting of the header of the following lines + * * @param header the header to output */ void resultHeader(String header); - + /** - * To set or unset if the output handler should behave verbosely or not. + * To set or unset if the output handler should behave verbosely or not. + * * @param verbose The verbosity setting */ void setVerbosity(boolean verbose); diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/outputformatter/GetChecksumDistributionFormatter.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/outputformatter/GetChecksumDistributionFormatter.java index 1aec1e8b4..4bfe0dbde 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/outputformatter/GetChecksumDistributionFormatter.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/outputformatter/GetChecksumDistributionFormatter.java @@ -5,16 +5,16 @@ * Copyright (C) 2010 - 2013 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -24,69 +24,67 @@ import org.bitrepository.commandline.output.OutputHandler; import org.bitrepository.commandline.resultmodel.ChecksumResult; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * Class to deliver GetChecksums client output in a format showing the distribution of the checksum between the pillars. * Output format 'style' is 'info' i.e. - * Tab separated columns with the columns: + * Tab separated columns with the columns: * Count FileID Checksum Pillars - * + *

    * If all pillars agree, then the 'pillars' will just say 'All'. */ public class GetChecksumDistributionFormatter implements GetChecksumsOutputFormatter { private final OutputHandler outputHandler; final static String header = "Count: \tChecksum: \tPillars: \tFileID: "; - + public GetChecksumDistributionFormatter(OutputHandler outputHandler) { this.outputHandler = outputHandler; } - + @Override public void formatHeader() { outputHandler.resultHeader(header); } - + @Override public void formatResult(Collection results) { - for(ChecksumResult result : results) { - if(result.isDirty()) { + for (ChecksumResult result : results) { + if (result.isDirty()) { printInconsistency(result); } else { - outputHandler.resultLine(result.getContributors().size() + " \t" + outputHandler.resultLine(result.getContributors().size() + " \t" + result.getChecksum(result.getContributors().get(0)) + " \tAll \t" + result.getID()); } } } - + /** - * Prints the different checksums along with the pillar distribution amongst these checksums. + * Prints the different checksums along with the pillar distribution amongst these checksums. + * * @param result The checksum results to format the inconsistency distribution upon. */ private void printInconsistency(ChecksumResult result) { - for(Map.Entry> checksumsDistribution : retrieveChecksumDistribution(result).entrySet()) { - outputHandler.resultLine(checksumsDistribution.getValue().size() + " \t" - + checksumsDistribution.getKey() + " \t" + checksumsDistribution.getValue()+ " \t" + result.getID()); + for (Map.Entry> checksumsDistribution : retrieveChecksumDistribution(result).entrySet()) { + outputHandler.resultLine(checksumsDistribution.getValue().size() + " \t" + + checksumsDistribution.getKey() + " \t" + checksumsDistribution.getValue() + " \t" + result.getID()); } } - + /** * Creates the map between a checksum and the list of pillars having the checksum. + * * @param result The checksum results. * @return The map between checksum and pillars. */ private Map> retrieveChecksumDistribution(ChecksumResult result) { Map> res = new HashMap<>(); - - for(String pillarID : result.getContributors()){ + + for (String pillarID : result.getContributors()) { String checksum = result.getChecksum(pillarID); List pillarIDs; - if(res.containsKey(checksum)) { + if (res.containsKey(checksum)) { pillarIDs = res.get(checksum); } else { pillarIDs = new ArrayList<>(); @@ -94,7 +92,7 @@ private Map> retrieveChecksumDistribution(ChecksumResult re pillarIDs.add(pillarID); res.put(checksum, pillarIDs); } - + return res; } } diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/outputformatter/GetChecksumsInfoFormatter.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/outputformatter/GetChecksumsInfoFormatter.java index 014b4dd5c..e8630e39c 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/outputformatter/GetChecksumsInfoFormatter.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/outputformatter/GetChecksumsInfoFormatter.java @@ -5,16 +5,16 @@ * Copyright (C) 2010 - 2013 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -27,32 +27,32 @@ import java.util.Collection; /** - * Class to format GetChecksums client output. + * Class to format GetChecksums client output. * Output format 'style' is 'info' i.e. - * Tab separated columns with the columns: - * Count Checksum FileID + * Tab separated columns with the columns: + * Count Checksum FileID */ public class GetChecksumsInfoFormatter implements GetChecksumsOutputFormatter { private final OutputHandler outputHandler; final static String header = "Checksum: \tCount: \tFileID:"; - + public GetChecksumsInfoFormatter(OutputHandler outputHandler) { this.outputHandler = outputHandler; } - + @Override public void formatHeader() { outputHandler.resultHeader(header); } - + @Override public void formatResult(Collection results) { String firstContributor; String checksum; - for(ChecksumResult result : results) { + for (ChecksumResult result : results) { firstContributor = result.getContributors().get(0); - if(result.isDirty()) { + if (result.isDirty()) { checksum = "disagreed"; } else { checksum = result.getChecksum(firstContributor); diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/outputformatter/GetChecksumsOutputFormatter.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/outputformatter/GetChecksumsOutputFormatter.java index 26f29bb2b..8fea71638 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/outputformatter/GetChecksumsOutputFormatter.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/outputformatter/GetChecksumsOutputFormatter.java @@ -5,39 +5,40 @@ * Copyright (C) 2010 - 2013 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.commandline.outputformatter; -import java.util.Collection; - import org.bitrepository.commandline.resultmodel.ChecksumResult; +import java.util.Collection; + /** - * Classes for formatting and outputting results from the GetFileIDs client + * Classes for formatting and outputting results from the GetFileIDs client */ public interface GetChecksumsOutputFormatter { /** - * Format and output the result header + * Format and output the result header */ void formatHeader(); - + /** - * Format and output a result line - * @param results The results to outout + * Format and output a result line + * + * @param results The results to output. */ void formatResult(Collection results); } diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/outputformatter/GetFileIDsInfoFormatter.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/outputformatter/GetFileIDsInfoFormatter.java index 763e46378..d3ed05def 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/outputformatter/GetFileIDsInfoFormatter.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/outputformatter/GetFileIDsInfoFormatter.java @@ -5,52 +5,52 @@ * Copyright (C) 2010 - 2013 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.commandline.outputformatter; -import java.util.Collection; - import org.bitrepository.commandline.output.OutputHandler; import org.bitrepository.commandline.resultmodel.FileIDsResult; +import java.util.Collection; + /** - * Class to format GetFileIDs client output. + * Class to format GetFileIDs client output. * Output format 'style' is 'info' i.e. - * Tab separated columns with the columns: - * Count Size FileID + * Tab separated columns with the columns: + * Count Size FileID */ public class GetFileIDsInfoFormatter implements GetFileIDsOutputFormatter { private final OutputHandler outputHandler; final static String header = "Count: \tSize: \tFileID:"; - + public GetFileIDsInfoFormatter(OutputHandler outputHandler) { this.outputHandler = outputHandler; } - + public void formatHeader() { outputHandler.resultHeader(header); } - + public void formatResult(Collection results) { - for(FileIDsResult result : results) { + for (FileIDsResult result : results) { String filesize; - if(result.getSize() == null) { + if (result.getSize() == null) { filesize = "???"; - } else if(result.getSize().intValue() == -1) { + } else if (result.getSize().intValue() == -1) { filesize = "disagreed"; } else { filesize = result.getSize().toString(); diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/outputformatter/GetFileIDsOutputFormatter.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/outputformatter/GetFileIDsOutputFormatter.java index 8cb75539b..e7b47b096 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/outputformatter/GetFileIDsOutputFormatter.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/outputformatter/GetFileIDsOutputFormatter.java @@ -5,39 +5,40 @@ * Copyright (C) 2010 - 2013 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.commandline.outputformatter; -import java.util.Collection; - import org.bitrepository.commandline.resultmodel.FileIDsResult; +import java.util.Collection; + /** - * Classes for formatting and outputting results from the GetFileIDs client + * Classes for formatting and outputting results from the GetFileIDs client */ public interface GetFileIDsOutputFormatter { /** - * Format and output the result header + * Format and output the result header */ void formatHeader(); - + /** * Format and output a result line - * @param results The results to format + * + * @param results The results to format */ void formatResult(Collection results); } diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/resultmodel/ChecksumResult.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/resultmodel/ChecksumResult.java index 162616226..9424e358c 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/resultmodel/ChecksumResult.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/resultmodel/ChecksumResult.java @@ -5,16 +5,16 @@ * Copyright (C) 2010 - 2013 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -28,48 +28,57 @@ public class ChecksumResult { - /** FileID */ + /** + * FileID + */ private final String id; - /** Mapping from pillar/contributorid to returned checksum */ + /** + * Mapping from pillar/contributorID to returned checksum + */ private final Map pillarChecksumMap; - /** Indication if there's checksum disagreement */ + /** + * Indication if there's checksum disagreement + */ private boolean dirty; - + public ChecksumResult(String id, String contributor, String checksum) { pillarChecksumMap = new HashMap<>(); this.id = id; dirty = false; pillarChecksumMap.put(contributor, checksum); } - + /** - * Add a contributor with it's checksum to the result + * Add a contributor with its checksum to the result + * * @param contributor the ID of the contributor - * @param checksum the checksum that the contributor delivered + * @param checksum the checksum that the contributor delivered */ public void addContributor(String contributor, String checksum) { - if(!dirty && !pillarChecksumMap.containsValue(checksum)) { + if (!dirty && !pillarChecksumMap.containsValue(checksum)) { dirty = true; } pillarChecksumMap.put(contributor, checksum); } - + /** * Is the result 'dirty', i.e. is there checksum disagreement among the answered contributors. - * @return false if all contributors have agreed on the checksum. + * + * @return false if all contributors have agreed on the checksum. */ public boolean isDirty() { return dirty; } - + /** - * Get the list of contributors. - * @return the set of contributors which have delivered a checksum + * Get the list of contributors. + * + * @return the set of contributors which have delivered a checksum */ public List getContributors() { return new ArrayList<>(pillarChecksumMap.keySet()); } - + /** * @param contributor The contributor to get the checksum for * @return the checksum from a given contributor @@ -77,19 +86,21 @@ public List getContributors() { public String getChecksum(String contributor) { return pillarChecksumMap.get(contributor); } - + /** * Get the fileID of the file for which the checksum is for. - * @return String, the fileID + * + * @return String, the fileID */ public String getID() { return id; } - + /** * Determine if we have enough answers to consider the result complete + * * @param expectedNumberOfContributors the expected number of contributors. - * @return true, if there's registered expectedNumberOfContributors of contributors. + * @return true, if there's registered expectedNumberOfContributors of contributors. */ public boolean isComplete(int expectedNumberOfContributors) { return (pillarChecksumMap.size() == expectedNumberOfContributors); diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/resultmodel/FileIDsResult.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/resultmodel/FileIDsResult.java index 935621552..e986b6978 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/resultmodel/FileIDsResult.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/resultmodel/FileIDsResult.java @@ -5,16 +5,16 @@ * Copyright (C) 2010 - 2013 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -26,72 +26,83 @@ import java.util.List; /** - * Class for temporary storage of FileIDs result information + * Class for temporary storage of FileIDs result information */ public class FileIDsResult { - /** FileID */ + /** + * FileID + */ private final String id; - /** Size of the file */ + /** + * Size of the file + */ private BigInteger size; - /** List of contributors reported to have the file. */ - private List contributors; - + /** + * List of contributors reported to have the file. + */ + private final List contributors; + public FileIDsResult(String id, BigInteger size, String contributor) { this.id = id; this.size = size; contributors = new ArrayList<>(); contributors.add(contributor); } - + /** - * Updates the filesize of the file, if the filesize does not match, mark it as a unknown + * Updates the filesize of the file, if the filesize does not match, mark it as an unknown + * * @param updateSize The file size to update with */ public void updateSize(BigInteger updateSize) { - if(updateSize != null) { - if(size == null) { - size = updateSize; - } else if(!updateSize.equals(size)) { + if (updateSize != null) { + if (size == null) { + size = updateSize; + } else if (!updateSize.equals(size)) { size = new BigInteger("-1"); - } - } + } + } } - + /** - * Gets the size of the file. - * @return the size of the file, or null if unknown or -1 if there are filesize confilicts between contributors + * Gets the size of the file. + * + * @return the size of the file, or null if unknown or -1 if there are filesize conflicts between contributors */ public BigInteger getSize() { return size; } - + /** - * Add a contributor to the list of contributors + * Add a contributor to the list of contributors + * * @param contributor The contributor to add */ public void addContributor(String contributor) { - if(!contributors.contains(contributor)) { + if (!contributors.contains(contributor)) { contributors.add(contributor); } } - + /** * Get the list of contributors - * @return the list of contributors + * + * @return the list of contributors */ public List getContributors() { return contributors; } - + /** * Get the id of the file - * @return the fileID + * + * @return the fileID */ public String getID() { return id; } - + public boolean isComplete(int numberOfExpectedContributors) { return (contributors.size() == numberOfExpectedContributors); } diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/resultmodel/GetChecksumsResultModel.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/resultmodel/GetChecksumsResultModel.java index cb697c5ea..7a9d25fb3 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/resultmodel/GetChecksumsResultModel.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/resultmodel/GetChecksumsResultModel.java @@ -5,120 +5,117 @@ * Copyright (C) 2010 - 2013 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.commandline.resultmodel; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - import org.bitrepository.bitrepositoryelements.ChecksumDataForChecksumSpecTYPE; import org.bitrepository.bitrepositoryelements.ResultingChecksums; import org.bitrepository.common.utils.Base16Utils; import org.bitrepository.common.utils.CalendarUtils; +import java.util.*; + /** * Model for keeping results from a GetFileIDs call. The model is intended to act as a buffer for * completed and uncompleted data. The intention is that completed data can be fetched while the - * remaining data is still being fetched - this should serve to keep memory use down. + * remaining data is still being fetched - this should serve to keep memory use down. */ public class GetChecksumsResultModel { - + private List completeResults; private Set lastCompletedIDs; - private Map uncompleteResults; - private Map latestContributorDate; - + private final Map incompleteResults; + private final Map latestContributorDate; + public GetChecksumsResultModel(Collection expectedContributors) { latestContributorDate = new HashMap<>(); - for(String contributor : expectedContributors) { + for (String contributor : expectedContributors) { latestContributorDate.put(contributor, new Date(0)); } completeResults = new ArrayList<>(); lastCompletedIDs = new HashSet<>(); - uncompleteResults = new HashMap<>(); + incompleteResults = new HashMap<>(); } - + /** * Add a set of results from a contributor + * * @param contributor the contributor from which the results are from - * @param results the results from the contributor. + * @param results the results from the contributor. */ public void addResults(String contributor, ResultingChecksums results) { Date latestContribution = latestContributorDate.get(contributor); - for(ChecksumDataForChecksumSpecTYPE item : results.getChecksumDataItems()) { - if(lastCompletedIDs.contains(item.getFileID())) { + for (ChecksumDataForChecksumSpecTYPE item : results.getChecksumDataItems()) { + if (lastCompletedIDs.contains(item.getFileID())) { continue; } String checksum = Base16Utils.decodeBase16(item.getChecksumValue()); ChecksumResult result; - if(uncompleteResults.containsKey(item.getFileID())) { - result = uncompleteResults.get(item.getFileID()); + if (incompleteResults.containsKey(item.getFileID())) { + result = incompleteResults.get(item.getFileID()); result.addContributor(contributor, checksum); } else { result = new ChecksumResult(item.getFileID(), contributor, checksum); } - - Date resultDate = CalendarUtils.convertFromXMLGregorianCalendar(item.getCalculationTimestamp()); - if(resultDate.after(latestContribution)) { + + Date resultDate = CalendarUtils.convertFromXMLGregorianCalendar(item.getCalculationTimestamp()); + if (resultDate.after(latestContribution)) { latestContribution = resultDate; } - - if(result.isComplete(latestContributorDate.size())) { + + if (result.isComplete(latestContributorDate.size())) { completeResults.add(result); - uncompleteResults.remove(item.getFileID()); + incompleteResults.remove(item.getFileID()); } else { - uncompleteResults.put(item.getFileID(), result); + incompleteResults.put(item.getFileID(), result); } - } + } latestContributorDate.put(contributor, latestContribution); } - + /** - * Get the collection of completed results (results from which all expected contributors - * delivered their part), the call is NOT idempotent. - * @return The collection of {@link ChecksumResult}s - */ + * Get the collection of completed results (results from which all expected contributors + * delivered their part), the call is NOT idempotent. + * + * @return The collection of {@link ChecksumResult}s + */ public Collection getCompletedResults() { List completed = completeResults; completeResults = null; completeResults = new ArrayList<>(); lastCompletedIDs = new HashSet<>(); - for(ChecksumResult result : completed) { + for (ChecksumResult result : completed) { lastCompletedIDs.add(result.getID()); } return completed; } /** - * Get the collection of uncompleted results (the results which does not have had contributions + * Get the collection of uncompleted results (the results which does not have had contributions * from all expected contributors) - * @return The collection of {@link ChecksumResult}s - */ + * + * @return The collection of {@link ChecksumResult}s + */ public Collection getUncompletedResults() { - return uncompleteResults.values(); + return incompleteResults.values(); } - + /** * Get the Date of the latest checksum by the contributor + * * @param contributor the contributor to get the Date of the latest contribution. * @return Date the date of the latest contribution by the given contributor */ diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/resultmodel/GetFileIDsResultModel.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/resultmodel/GetFileIDsResultModel.java index d2a2310b7..9ffe08f79 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/resultmodel/GetFileIDsResultModel.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/resultmodel/GetFileIDsResultModel.java @@ -5,119 +5,116 @@ * Copyright (C) 2010 - 2013 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.commandline.resultmodel; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - import org.bitrepository.bitrepositoryelements.FileIDsDataItem; import org.bitrepository.bitrepositoryelements.ResultingFileIDs; import org.bitrepository.common.utils.CalendarUtils; +import java.util.*; + /** * Model for keeping results from a GetFileIDs call. The model is intended to act as a buffer for - * completed and uncompleted data. The intension is that completed data can be fetched while the - * remaining data is still being fetched - this should serve to keep memory use down. + * completed and uncompleted data. The intention is that completed data can be fetched while the + * remaining data is still being fetched - this should serve to keep memory use down. */ public class GetFileIDsResultModel { private List completeResults; private Set lastCompletedIDs; - private Map uncompleteResults; - private Map latestContributorDate; - + private final Map incompleteResults; + private final Map latestContributorDate; + public GetFileIDsResultModel(Collection expectedContributors) { latestContributorDate = new HashMap<>(); - for(String contributor : expectedContributors) { + for (String contributor : expectedContributors) { latestContributorDate.put(contributor, new Date(0)); } completeResults = new ArrayList<>(); lastCompletedIDs = new HashSet<>(); - uncompleteResults = new HashMap<>(); + incompleteResults = new HashMap<>(); } - + /** * Add a set of results from a contributor + * * @param contributor the contributor from which the results are from - * @param results the results from the contributor. + * @param results the results from the contributor. */ public void addResults(String contributor, ResultingFileIDs results) { Date latestContribution = latestContributorDate.get(contributor); - for(FileIDsDataItem item : results.getFileIDsData().getFileIDsDataItems().getFileIDsDataItem()) { - if(lastCompletedIDs.contains(item.getFileID())) { + for (FileIDsDataItem item : results.getFileIDsData().getFileIDsDataItems().getFileIDsDataItem()) { + if (lastCompletedIDs.contains(item.getFileID())) { continue; } FileIDsResult result; - if(uncompleteResults.containsKey(item.getFileID())) { - result = uncompleteResults.get(item.getFileID()); + if (incompleteResults.containsKey(item.getFileID())) { + result = incompleteResults.get(item.getFileID()); result.updateSize(item.getFileSize()); result.addContributor(contributor); } else { result = new FileIDsResult(item.getFileID(), item.getFileSize(), contributor); } - - Date resultDate = CalendarUtils.convertFromXMLGregorianCalendar(item.getLastModificationTime()); - if(resultDate.after(latestContribution)) { + + Date resultDate = CalendarUtils.convertFromXMLGregorianCalendar(item.getLastModificationTime()); + if (resultDate.after(latestContribution)) { latestContribution = resultDate; } - - if(result.isComplete(latestContributorDate.size())) { + + if (result.isComplete(latestContributorDate.size())) { completeResults.add(result); - uncompleteResults.remove(item.getFileID()); + incompleteResults.remove(item.getFileID()); } else { - uncompleteResults.put(item.getFileID(), result); + incompleteResults.put(item.getFileID(), result); } - } + } latestContributorDate.put(contributor, latestContribution); } - + /** - * Get the collection of completed results (results from which all expected contributors - * delivered their part), the call is NOT idempotent. - * @return the collection of {@link FileIDsResult}s - */ + * Get the collection of completed results (results from which all expected contributors + * delivered their part), the call is NOT idempotent. + * + * @return the collection of {@link FileIDsResult}s + */ public Collection getCompletedResults() { List completed = completeResults; completeResults = null; completeResults = new ArrayList<>(); lastCompletedIDs = new HashSet<>(); - for(FileIDsResult result : completed) { + for (FileIDsResult result : completed) { lastCompletedIDs.add(result.getID()); } return completed; } /** - * Get the collection of uncompleted results (the results which does not have had contributions + * Get the collection of uncompleted results (the results which does not have had contributions * from all expected contributors) - * @return the collection of {@link FileIDsResult} - */ + * + * @return the collection of {@link FileIDsResult} + */ public Collection getUncompletedResults() { - return uncompleteResults.values(); + return incompleteResults.values(); } - + /** * Get the Date of the latest fileID by the contributor + * * @param contributor the contributor to get the Date of the latest contribution. * @return Date the date of the latest contribution by the given contributor */ diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/utils/ChecksumExtractionUtils.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/utils/ChecksumExtractionUtils.java index 8af8fc3f0..1e2035eaf 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/utils/ChecksumExtractionUtils.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/utils/ChecksumExtractionUtils.java @@ -5,16 +5,16 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -35,35 +35,36 @@ public class ChecksumExtractionUtils { /** * Extracts the checksum type from the commandline arguments. - * Ensures, that the HMAC checksum types is used, when a salt is given, + * Ensures, that the HMAC checksum types is used, when a salt is given, * and also that it is not the HMAC checksum type, which is used, when no salt is given. - * Also, ignores cases for the checksum types. - * @param cmdHandler Contains the arguments from the commansline. - * @param settings The settings, containing the default checksum type (if no checksum type is given). - * @param output The OutputHandler, where output and logging information is delivered. + * Also, ignores cases for the checksum types. + * + * @param cmdHandler Contains the arguments from the commandline. + * @param settings The settings, containing the default checksum type (if no checksum type is given). + * @param output The OutputHandler, where output and logging information is delivered. * @return The checksum type. */ public static ChecksumType extractChecksumType(CommandLineArgumentsHandler cmdHandler, Settings settings, - OutputHandler output) { + OutputHandler output) { String type; - if(cmdHandler.hasOption(Constants.REQUEST_CHECKSUM_TYPE_ARG)) { + if (cmdHandler.hasOption(Constants.REQUEST_CHECKSUM_TYPE_ARG)) { type = cmdHandler.getOptionValue(Constants.REQUEST_CHECKSUM_TYPE_ARG).toUpperCase(Locale.ROOT); - } else { + } else { type = ChecksumUtils.getDefault(settings).getChecksumType().name(); } - - if(cmdHandler.hasOption(Constants.REQUEST_CHECKSUM_SALT_ARG)) { - if(!type.startsWith("HMAC_")) { + + if (cmdHandler.hasOption(Constants.REQUEST_CHECKSUM_SALT_ARG)) { + if (!type.startsWith("HMAC_")) { type = "HMAC_" + type; output.debug("Non-HMAC checksum spec given, but also salt. Thus using '" + type + "' instead."); } } else { - if(type.startsWith("HMAC_")) { + if (type.startsWith("HMAC_")) { type = type.replace("HMAC_", ""); output.warn("HMAC checksum spec given, but no salt given. Using '" + type + "' instead."); } } - + return ChecksumType.fromValue(type); } } diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/utils/CommandLineArgumentsHandler.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/utils/CommandLineArgumentsHandler.java index 8d7888cc6..66f119da4 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/utils/CommandLineArgumentsHandler.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/utils/CommandLineArgumentsHandler.java @@ -5,31 +5,23 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.commandline.utils; -import java.nio.file.Paths; -import java.util.Collection; - -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.CommandLineParser; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.ParseException; +import org.apache.commons.cli.*; import org.bitrepository.client.CommandLineSettingsProvider; import org.bitrepository.commandline.Constants; import org.bitrepository.common.ArgumentValidator; @@ -40,43 +32,39 @@ import org.bitrepository.protocol.security.SecurityManager; import org.bitrepository.protocol.security.SecurityManagerUtil; +import java.nio.file.Paths; + /** * Interface for handling the command line arguments. */ public class CommandLineArgumentsHandler { - /** The parser of the command line arguments.*/ protected final CommandLineParser parser; - /** The options for the command line arguments*/ protected final Options options; - /** The command line. */ protected CommandLine cmd = null; - /** The settings.*/ protected Settings settings = null; - - /** - * Constructor. - */ + public CommandLineArgumentsHandler() { parser = new DefaultParser(); options = new Options(); } - + /** * Parses the commandline arguments. + * * @param args The command line arguments to pass. * @throws ParseException If the arguments does not parse. E.g. arguments missing or too many arguments. */ - public void parseArguments(String ... args) throws ParseException { + public void parseArguments(String... args) throws ParseException { cmd = parser.parse(options, args, Constants.NOT_ALLOWING_UNDEFINED_ARGUMENTS); } - + /** * For validating that the command line has been instantiated. */ private void ensureThatCmdHasBeenInitialised() { ArgumentValidator.checkNotNull(cmd, "No argument has been parsed from the command line."); } - + /** * Creates the default options for the command line arguments for the clients. */ @@ -85,24 +73,24 @@ public void createDefaultOptions() { + "files for the client"); settingsOption.setRequired(Constants.ARGUMENT_IS_REQUIRED); options.addOption(settingsOption); - + Option privateKeyOption = new Option(Constants.PRIVATE_KEY_ARG, true, "The path to the file containing " + "the private key."); - privateKeyOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); + privateKeyOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); options.addOption(privateKeyOption); - + Option verbosity = new Option(Constants.VERBOSITY_ARG, false, "Makes the client more verbose"); verbosity.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); options.addOption(verbosity); } - + /** * @param option The option to add to the command line. */ public void addOption(Option option) { options.addOption(option); } - + /** * @param optionName The name of the option to extract the value for. * @return The value corresponding to the given option name. @@ -111,7 +99,7 @@ public String getOptionValue(String optionName) { ensureThatCmdHasBeenInitialised(); return cmd.getOptionValue(optionName); } - + /** * @param optionName The name of the option to validate whether exists. * @return Whether any arguments for the options have been given. @@ -120,37 +108,39 @@ public boolean hasOption(String optionName) { ensureThatCmdHasBeenInitialised(); return cmd.hasOption(optionName); } - + /** - * @return Lists the possible arguments in a human readable format. + * @return Lists the possible arguments in a human-readable format. */ public String listArguments() { StringBuilder res = new StringBuilder(); res.append("Takes the following arguments:\n"); - for(Option option : (Collection

    - * IdentifyPillarsRequestSent, PillarIdentified, PillarSelected, RequestSent, Progress, PillarComplete, Complete - * @param auditTrailInformation The audit information for the given operation. E.g. who is behind the operation - * call. + * + * @param collectionID The collection to delete the file in. + * @param fileID The id of the file to delete. + * @param pillarID The id of the pillar, where the file should be deleted. + * @param checksumForPillar The specifications for the checksum of the file. + * @param checksumRequested Checksum request for the pillar where the file is deleted + * @param eventHandler [OPTIONAL] The handler which should receive notifications of the events occurring in + * connection with the pillar communication. This is allowed to be null. + * In a good case scenario this will give the events:

    + * IdentifyPillarsRequestSent, PillarIdentified, PillarSelected, RequestSent, Progress, PillarComplete, + * Complete + * @param auditTrailInformation The audit information for the given operation. E.g. who is behind the operation + * call. */ void deleteFile(String collectionID, String fileID, String pillarID, ChecksumDataForFileTYPE checksumForPillar, - ChecksumSpecTYPE checksumRequested, EventHandler eventHandler, String auditTrailInformation); + ChecksumSpecTYPE checksumRequested, EventHandler eventHandler, String auditTrailInformation); } diff --git a/bitrepository-client/src/main/java/org/bitrepository/modify/deletefile/conversation/DeleteFileCompletePillarEvent.java b/bitrepository-client/src/main/java/org/bitrepository/modify/deletefile/conversation/DeleteFileCompletePillarEvent.java index 2d15a5512..c7fd50c82 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/modify/deletefile/conversation/DeleteFileCompletePillarEvent.java +++ b/bitrepository-client/src/main/java/org/bitrepository/modify/deletefile/conversation/DeleteFileCompletePillarEvent.java @@ -1,23 +1,24 @@ /* * #%L - * Bitrepository Access - * + * BitRepository Access + * * $Id: ChecksumsCompletePillarEvent.java 548 2011-11-21 16:43:43Z jolf $ - * $HeadURL: https://sbforge.org/svn/bitrepository/bitrepository-reference/trunk/bitrepository-access-client/src/main/java/org/bitrepository/access/getchecksums/conversation/ChecksumsCompletePillarEvent.java $ + * $HeadURL: https://sbforge.org/svn/bitrepository/bitrepository-reference/trunk/bitrepository-access-client/src/main/java/org + * /bitrepository/access/getchecksums/conversation/ChecksumsCompletePillarEvent.java $ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -28,29 +29,31 @@ import org.bitrepository.client.eventhandler.ContributorCompleteEvent; /** -* Contains the result of a delete request sent to a single pillar. -*/ + * Contains the result of a delete request sent to a single pillar. + */ public class DeleteFileCompletePillarEvent extends ContributorCompleteEvent { - /** @see #getChecksums(). */ + /** + * @see #getChecksums(). + */ private final ChecksumDataForFileTYPE result; - + /** - * @param pillarID The pillar which generated the result + * @param pillarID The pillar which generated the result * @param collectionID The ID of the collection - * @param result The result returned by the pillar. + * @param result The result returned by the pillar. */ public DeleteFileCompletePillarEvent(String pillarID, String collectionID, ChecksumDataForFileTYPE result) { super(pillarID, collectionID); this.result = result; } - /** - * @return The checksum result from a single pillar. + /** + * @return The checksum result from a single pillar. */ public ChecksumDataForFileTYPE getChecksums() { return result; } - + @Override public String additionalInfo() { return super.additionalInfo() + ", DeleteFileResult=" + result; diff --git a/bitrepository-client/src/main/java/org/bitrepository/modify/deletefile/conversation/DeleteFileConversationContext.java b/bitrepository-client/src/main/java/org/bitrepository/modify/deletefile/conversation/DeleteFileConversationContext.java index f113c2cc0..e95c070a6 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/modify/deletefile/conversation/DeleteFileConversationContext.java +++ b/bitrepository-client/src/main/java/org/bitrepository/modify/deletefile/conversation/DeleteFileConversationContext.java @@ -5,23 +5,22 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.modify.deletefile.conversation; -import java.util.Collection; import org.bitrepository.bitrepositoryelements.ChecksumDataForFileTYPE; import org.bitrepository.bitrepositoryelements.ChecksumSpecTYPE; import org.bitrepository.client.conversation.ConversationContext; @@ -30,23 +29,26 @@ import org.bitrepository.protocol.OperationType; import org.bitrepository.protocol.messagebus.MessageSender; +import java.util.Collection; + public class DeleteFileConversationContext extends ConversationContext { private final ChecksumDataForFileTYPE checksumForValidationAtPillar; private final ChecksumSpecTYPE checksumRequestsForValidation; - + public DeleteFileConversationContext( String collectionID, String fileID, ChecksumDataForFileTYPE checksumForValidationAtPillar, ChecksumSpecTYPE checksumRequestsForValidation, Settings settings, MessageSender messageSender, - String clientID, Collection contributors, EventHandler eventHandler, String auditTrailInformation) { - super(collectionID, OperationType.DELETE_FILE, settings, messageSender, clientID, fileID, contributors, eventHandler, auditTrailInformation); + String clientID, Collection contributors, EventHandler eventHandler, String auditTrailInformation) { + super(collectionID, OperationType.DELETE_FILE, settings, messageSender, clientID, fileID, contributors, eventHandler, + auditTrailInformation); this.checksumForValidationAtPillar = checksumForValidationAtPillar; this.checksumRequestsForValidation = checksumRequestsForValidation; } - + public ChecksumDataForFileTYPE getChecksumForValidationAtPillar() { return checksumForValidationAtPillar; } - + public ChecksumSpecTYPE getChecksumRequestForValidation() { return checksumRequestsForValidation; } diff --git a/bitrepository-client/src/main/java/org/bitrepository/modify/deletefile/conversation/DeletingFile.java b/bitrepository-client/src/main/java/org/bitrepository/modify/deletefile/conversation/DeletingFile.java index f50298867..f17969180 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/modify/deletefile/conversation/DeletingFile.java +++ b/bitrepository-client/src/main/java/org/bitrepository/modify/deletefile/conversation/DeletingFile.java @@ -1,52 +1,52 @@ /* * #%L * Bitrepository Modifying Client - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.modify.deletefile.conversation; -import java.util.Collection; import org.bitrepository.bitrepositorymessages.DeleteFileFinalResponse; import org.bitrepository.bitrepositorymessages.DeleteFileRequest; import org.bitrepository.bitrepositorymessages.MessageResponse; import org.bitrepository.client.conversation.ConversationContext; import org.bitrepository.client.conversation.PerformingOperationState; import org.bitrepository.client.conversation.selector.SelectedComponentInfo; -import org.bitrepository.client.exceptions.UnexpectedResponseException; import org.bitrepository.common.utils.ChecksumUtils; +import java.util.Collection; + /** * Models the behavior of a DeleteFile conversation during the operation phase. That is, it begins with the sending of * DeleteFileRequest messages and finishes with the reception of the DeleteFileFinalResponse - * messages from all responding pillars. - * - * Note that this is only used by the DeleteFileConversation in the same package, therefore the visibility is package + * messages from all responding pillars. + *

    + * Note that this is only used by the DeleteFileConversation in the same package, therefore the visibility is package * protected. */ public class DeletingFile extends PerformingOperationState { private final DeleteFileConversationContext context; - /* - * @param context The conversation context. + /** + * @param context The conversation context. * @param contributors The list of components the fileIDs should be collected from. */ public DeletingFile(DeleteFileConversationContext context, Collection contributors) { @@ -55,7 +55,7 @@ public DeletingFile(DeleteFileConversationContext context, Collection. * #L% @@ -50,26 +50,25 @@ public GeneralConversationState getOperationState() { } /** - * Extends the default behaviour with a idempotent aspects. This assumes that the delete on a pillar is successful if - * if the file is already absent. - * + * Extends the default behaviour with an idempotent aspects. This assumes that the delete operation on a pillar is + * successful if the file is already absent. + *

    * Any other none-positive response is handled as a fatal problem. */ @Override protected void handleFailureResponse(MessageResponse msg) throws UnableToFinishException { IdentifyPillarsForDeleteFileResponse response = (IdentifyPillarsForDeleteFileResponse) msg; ResponseCode responseCode = response.getResponseInfo().getResponseCode(); - if(responseCode.equals(ResponseCode.FILE_NOT_FOUND_FAILURE)) { + if (responseCode.equals(ResponseCode.FILE_NOT_FOUND_FAILURE)) { //Idempotent getContext().getMonitor().contributorIdentified(response); - getContext().getMonitor().contributorComplete(new DeleteFileCompletePillarEvent( - response.getFrom(), response.getCollectionID(), null )); + getContext().getMonitor() + .contributorComplete(new DeleteFileCompletePillarEvent(response.getFrom(), response.getCollectionID(), null)); } else { - getContext().getMonitor().contributorFailed( - msg.getResponseInfo().getResponseText(), msg.getFrom(), - msg.getResponseInfo().getResponseCode()); - throw new UnableToFinishException("Can not continue with delete operation, as " + msg.getFrom() + - " is unable to perform the deletion."); + getContext().getMonitor() + .contributorFailed(msg.getResponseInfo().getResponseText(), msg.getFrom(), msg.getResponseInfo().getResponseCode()); + throw new UnableToFinishException( + "Can not continue with delete operation, as " + msg.getFrom() + " is unable to perform the deletion."); } } diff --git a/bitrepository-client/src/main/java/org/bitrepository/modify/package-info.java b/bitrepository-client/src/main/java/org/bitrepository/modify/package-info.java index 5d010b74e..9a003d01f 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/modify/package-info.java +++ b/bitrepository-client/src/main/java/org/bitrepository/modify/package-info.java @@ -1,30 +1,30 @@ /* * #%L - * Bitrepository Modifying Client - * + * BitRepository Modifying Client + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ /** - * All functionality for writing to the Bitrepository is located here. - * + * All functionality for writing to the Bitrepository is located here. + *

    * This includes Put File, Delete File and Replace File. */ package org.bitrepository.modify; \ No newline at end of file diff --git a/bitrepository-client/src/main/java/org/bitrepository/modify/putfile/BlockingPutFileClient.java b/bitrepository-client/src/main/java/org/bitrepository/modify/putfile/BlockingPutFileClient.java index d1f13d508..46549d9f4 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/modify/putfile/BlockingPutFileClient.java +++ b/bitrepository-client/src/main/java/org/bitrepository/modify/putfile/BlockingPutFileClient.java @@ -1,31 +1,29 @@ /* * #%L * Bitmagasin modify client - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.modify.putfile; -import java.net.URL; -import java.util.List; import org.bitrepository.bitrepositoryelements.ChecksumDataForFileTYPE; import org.bitrepository.bitrepositoryelements.ChecksumSpecTYPE; import org.bitrepository.client.eventhandler.BlockingEventHandler; @@ -34,8 +32,11 @@ import org.bitrepository.client.eventhandler.OperationEvent; import org.bitrepository.common.exceptions.OperationFailedException; +import java.net.URL; +import java.util.List; + /** - * Wrappes a PutFileClient to provide a blocking client. The client will block until the PutFileOperation + * Wraps a PutFileClient to provide a blocking client. The client will block until the PutFileOperation * has finished. */ public class BlockingPutFileClient { @@ -44,20 +45,21 @@ public class BlockingPutFileClient { public BlockingPutFileClient(PutFileClient client) { this.client = client; } + /** * Method for performing a blocking put file operation. Wraps the asynchronous {@link PutFileClient#putFile * (String, java.net.URL, String, long, org.bitrepository.bitrepositoryelements.ChecksumDataForFileTYPE, * org.bitrepository.bitrepositoryelements.ChecksumSpecTYPE, org.bitrepository.client.eventhandler.EventHandler, * String)} method. * - * @param collectionID The ID of the collection - * @param url The url to where the file being put can be retrieved - * @param fileID The ID of the file - * @param sizeOfFile [OPTIONAL] the size of the file + * @param collectionID The ID of the collection + * @param url The url to where the file being put can be retrieved + * @param fileID The ID of the file + * @param sizeOfFile [OPTIONAL] the size of the file * @param checksumForValidationAtPillar The checksum data of the file for pillar side validation * @param checksumRequestsForValidation The checksum request for the pillar to deliver - * @param eventHandler The {@link EventHandler} to handle incoming events - * @param auditTrailInformation The audittrail information for the pillars + * @param eventHandler The {@link EventHandler} to handle incoming events + * @param auditTrailInformation The auditTrail information for the pillars * @return The list of {@link ContributorEvent}s received during the operation * @throws OperationFailedException The operation didn't complete successfully. */ @@ -76,7 +78,7 @@ public List putFile( checksumRequestsForValidation, blocker, auditTrailInformation); OperationEvent finishEvent = blocker.awaitFinished(); - if(finishEvent.getEventType() == OperationEvent.OperationEventType.COMPLETE) { + if (finishEvent.getEventType() == OperationEvent.OperationEventType.COMPLETE) { return blocker.getResults(); } else if (finishEvent.getEventType() == OperationEvent.OperationEventType.FAILED) { throw new OperationFailedException(finishEvent.getInfo()); diff --git a/bitrepository-client/src/main/java/org/bitrepository/modify/putfile/ConversationBasedPutFileClient.java b/bitrepository-client/src/main/java/org/bitrepository/modify/putfile/ConversationBasedPutFileClient.java index 942a3b7bd..cd1b6050f 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/modify/putfile/ConversationBasedPutFileClient.java +++ b/bitrepository-client/src/main/java/org/bitrepository/modify/putfile/ConversationBasedPutFileClient.java @@ -8,16 +8,16 @@ * Copyright (C) 2010 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -41,28 +41,24 @@ import java.net.URL; -/** - * A simple implementation of the PutClient. - */ public class ConversationBasedPutFileClient extends AbstractClient implements PutFileClient { private final Logger log = LoggerFactory.getLogger(getClass()); /** - * @see AbstractClient - * @param messageBus The {@link MessageBus} for handling communication + * @param messageBus The {@link MessageBus} for handling communication * @param conversationMediator The {@link ConversationMediator} for keeping track of conversations - * @param settings The {@link Settings} for the client - * @param clientID The ID of the client + * @param settings The {@link Settings} for the client + * @param clientID The ID of the client + * @see AbstractClient */ - public ConversationBasedPutFileClient(MessageBus messageBus, ConversationMediator conversationMediator, - Settings settings, String clientID) { + public ConversationBasedPutFileClient(MessageBus messageBus, ConversationMediator conversationMediator, Settings settings, + String clientID) { super(settings, conversationMediator, messageBus, clientID); } - + @Override - public void putFile(String collectionID, URL url, String fileID, long sizeOfFile, - ChecksumDataForFileTYPE checksumForValidationAtPillar, - ChecksumSpecTYPE checksumRequestsForValidation, EventHandler eventHandler, String auditTrailInformation) { + public void putFile(String collectionID, URL url, String fileID, long sizeOfFile, ChecksumDataForFileTYPE checksumForValidationAtPillar, + ChecksumSpecTYPE checksumRequestsForValidation, EventHandler eventHandler, String auditTrailInformation) { ArgumentValidator.checkNotNullOrEmpty(collectionID, "collectionID"); ArgumentValidator.checkNotNullOrEmpty(fileID, "fileID"); validateFileID(fileID); @@ -72,13 +68,13 @@ public void putFile(String collectionID, URL url, String fileID, long sizeOfFile MessageDataTypeValidator.validate(checksumRequestsForValidation, "checksumRequestsForValidation"); log.info("Starting putFile of " + fileID + " for client " + clientID + ". " + auditTrailInformation); - if(settings.getRepositorySettings().getProtocolSettings().isRequireChecksumForNewFileRequests()) { + if (settings.getRepositorySettings().getProtocolSettings().isRequireChecksumForNewFileRequests()) { ArgumentValidator.checkNotNull(checksumForValidationAtPillar, "ChecksumDataForFileTYPE checksumForValidationAtPillar"); } - + PutFileConversationContext context = new PutFileConversationContext(collectionID, fileID, url, sizeOfFile, - checksumForValidationAtPillar, checksumRequestsForValidation, settings, messageBus, - clientID, SettingsUtils.getPillarIDsForCollection(collectionID), eventHandler, auditTrailInformation); + checksumForValidationAtPillar, checksumRequestsForValidation, settings, messageBus, clientID, + SettingsUtils.getPillarIDsForCollection(collectionID), eventHandler, auditTrailInformation); startConversation(context, new IdentifyPillarsForPutFile(context)); } } diff --git a/bitrepository-client/src/main/java/org/bitrepository/modify/putfile/PutFileClient.java b/bitrepository-client/src/main/java/org/bitrepository/modify/putfile/PutFileClient.java index 04503ebf9..b8ed69cfc 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/modify/putfile/PutFileClient.java +++ b/bitrepository-client/src/main/java/org/bitrepository/modify/putfile/PutFileClient.java @@ -28,13 +28,13 @@ import org.bitrepository.bitrepositoryelements.ChecksumDataForFileTYPE; import org.bitrepository.bitrepositoryelements.ChecksumSpecTYPE; -import org.bitrepository.client.BitrepositoryClient; +import org.bitrepository.client.BitRepositoryClient; import org.bitrepository.client.eventhandler.EventHandler; /** * Interface for the put client. */ -public interface PutFileClient extends BitrepositoryClient { +public interface PutFileClient extends BitRepositoryClient { /** * Places a copy of the file located at the given url on each of the pillars defined for the indicated collection. * diff --git a/bitrepository-client/src/main/java/org/bitrepository/modify/putfile/conversation/IdentifyPillarsForPutFile.java b/bitrepository-client/src/main/java/org/bitrepository/modify/putfile/conversation/IdentifyPillarsForPutFile.java index 7ab93f484..df9970324 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/modify/putfile/conversation/IdentifyPillarsForPutFile.java +++ b/bitrepository-client/src/main/java/org/bitrepository/modify/putfile/conversation/IdentifyPillarsForPutFile.java @@ -1,23 +1,23 @@ /* * #%L * Bitrepository Access - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -51,41 +51,39 @@ public IdentifyPillarsForPutFile(PutFileConversationContext context) { /** * Extends the default behaviour with an idempotent aspect. This assumes that the put to a pillar is successful if * the same file already exists. - * + *

    * The existence of a different file on the other hand is a fatal problem. */ @Override protected void handleFailureResponse(MessageResponse msg) throws UnableToFinishException { IdentifyPillarsForPutFileResponse response = (IdentifyPillarsForPutFileResponse) msg; ResponseCode responseCode = response.getResponseInfo().getResponseCode(); - switch (responseCode) { - case DUPLICATE_FILE_FAILURE: - if(response.isSetChecksumDataForExistingFile()) { - if(ChecksumUtils.areEqual( - response.getChecksumDataForExistingFile(),context.getChecksumForValidationAtPillar())) { - PutFileCompletePillarEvent event = new PutFileCompletePillarEvent( - response.getPillarID(), response.getCollectionID(), response.getChecksumDataForExistingFile()); - event.setInfo("File already existed on " + response.getPillarID()); - getContext().getMonitor().contributorComplete(event); - } else { - getContext().getMonitor().contributorFailed( - "Received negative response from component " + response.getFrom() + - ": " + response.getResponseInfo() + " (existing file checksum does not match)", - response.getFrom(), response.getResponseInfo().getResponseCode()); - throw new UnableToFinishException("Can not put file " + context.getFileID() + - ", as an different file already exists on pillar " + response.getPillarID()); - } + if (responseCode == ResponseCode.DUPLICATE_FILE_FAILURE) { + if (response.isSetChecksumDataForExistingFile()) { + if (ChecksumUtils.areEqual( + response.getChecksumDataForExistingFile(), context.getChecksumForValidationAtPillar())) { + PutFileCompletePillarEvent event = new PutFileCompletePillarEvent( + response.getPillarID(), response.getCollectionID(), response.getChecksumDataForExistingFile()); + event.setInfo("File already existed on " + response.getPillarID()); + getContext().getMonitor().contributorComplete(event); } else { getContext().getMonitor().contributorFailed( - "Received negative response from component " + response.getFrom() + ": " + - response.getResponseInfo(), response.getFrom(), - response.getResponseInfo().getResponseCode()); + "Received negative response from component " + response.getFrom() + + ": " + response.getResponseInfo() + " (existing file checksum does not match)", + response.getFrom(), response.getResponseInfo().getResponseCode()); throw new UnableToFinishException("Can not put file " + context.getFileID() + - ", as an file already exists on pillar " + response.getPillarID()); + ", as an different file already exists on pillar " + response.getPillarID()); } - break; - default: - super.handleFailureResponse(msg); + } else { + getContext().getMonitor().contributorFailed( + "Received negative response from component " + response.getFrom() + ": " + + response.getResponseInfo(), response.getFrom(), + response.getResponseInfo().getResponseCode()); + throw new UnableToFinishException("Can not put file " + context.getFileID() + + ", as an file already exists on pillar " + response.getPillarID()); + } + } else { + super.handleFailureResponse(msg); } } @@ -116,9 +114,9 @@ protected String getPrimitiveName() { } /** - * Extends the default behaviour with the possiblity of putting to a subset of pillars, if the + * Extends the default behaviour with the possibility of putting to a subset of pillars, if the * isSetPartialPutsAllow settings is true. - * */ + */ @Override protected boolean canFinish() { return (isPartialPutsAllowed() && getSelector().getSelectedComponents().size() > 0 || diff --git a/bitrepository-client/src/main/java/org/bitrepository/modify/putfile/conversation/PutFileCompletePillarEvent.java b/bitrepository-client/src/main/java/org/bitrepository/modify/putfile/conversation/PutFileCompletePillarEvent.java index 28a183500..53bfad60c 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/modify/putfile/conversation/PutFileCompletePillarEvent.java +++ b/bitrepository-client/src/main/java/org/bitrepository/modify/putfile/conversation/PutFileCompletePillarEvent.java @@ -1,23 +1,24 @@ /* * #%L - * Bitrepository Access - * + * BitRepository Access + * * $Id: ChecksumsCompletePillarEvent.java 548 2011-11-21 16:43:43Z jolf $ - * $HeadURL: https://sbforge.org/svn/bitrepository/bitrepository-reference/trunk/bitrepository-access-client/src/main/java/org/bitrepository/access/getchecksums/conversation/ChecksumsCompletePillarEvent.java $ + * $HeadURL: https://sbforge.org/svn/bitrepository/bitrepository-reference/trunk/bitrepository-access-client/src/main/java/org + * /bitrepository/access/getchecksums/conversation/ChecksumsCompletePillarEvent.java $ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -28,29 +29,31 @@ import org.bitrepository.client.eventhandler.ContributorCompleteEvent; /** -* Contains the result of a put file request sent to a single pillar. -*/ + * Contains the result of a put file request sent to a single pillar. + */ public class PutFileCompletePillarEvent extends ContributorCompleteEvent { - /** @see #getChecksums(). */ + /** + * @see #getChecksums(). + */ private final ChecksumDataForFileTYPE result; - + /** - * @param pillarID The pillar which generated the result + * @param pillarID The pillar which generated the result * @param collectionID The ID of the collection - * @param result The result returned by the pillar. + * @param result The result returned by the pillar. */ public PutFileCompletePillarEvent(String pillarID, String collectionID, ChecksumDataForFileTYPE result) { super(pillarID, collectionID); this.result = result; } - /** - * @return The checksum result from a single pillar. + /** + * @return The checksum result from a single pillar. */ public ChecksumDataForFileTYPE getChecksums() { return result; } - + @Override public String additionalInfo() { return super.additionalInfo() + ", requestedChecksumResult=" + result; diff --git a/bitrepository-client/src/main/java/org/bitrepository/modify/putfile/conversation/PutFileConversationContext.java b/bitrepository-client/src/main/java/org/bitrepository/modify/putfile/conversation/PutFileConversationContext.java index b278ba7af..10238f29e 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/modify/putfile/conversation/PutFileConversationContext.java +++ b/bitrepository-client/src/main/java/org/bitrepository/modify/putfile/conversation/PutFileConversationContext.java @@ -5,25 +5,22 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.modify.putfile.conversation; -import java.math.BigInteger; -import java.net.URL; -import java.util.Collection; import org.bitrepository.bitrepositoryelements.ChecksumDataForFileTYPE; import org.bitrepository.bitrepositoryelements.ChecksumSpecTYPE; import org.bitrepository.client.conversation.ConversationContext; @@ -32,19 +29,23 @@ import org.bitrepository.protocol.OperationType; import org.bitrepository.protocol.messagebus.MessageSender; +import java.math.BigInteger; +import java.net.URL; +import java.util.Collection; + public class PutFileConversationContext extends ConversationContext { private final URL urlForFile; private final BigInteger fileSize; private final ChecksumDataForFileTYPE checksumForValidationAtPillar; private final ChecksumSpecTYPE checksumRequestsForValidation; - + public PutFileConversationContext(String collectionID, String fileID, URL urlForFile, long fileSize, - ChecksumDataForFileTYPE checksumForValidationAtPillar, ChecksumSpecTYPE checksumRequestsForValidation, - Settings settings, MessageSender messageSender, String clientID, Collection contributors, - EventHandler eventHandler, String auditTrailInformation) { + ChecksumDataForFileTYPE checksumForValidationAtPillar, ChecksumSpecTYPE checksumRequestsForValidation, + Settings settings, MessageSender messageSender, String clientID, Collection contributors, + EventHandler eventHandler, String auditTrailInformation) { super(collectionID, OperationType.PUT_FILE, settings, messageSender, clientID, fileID, contributors, eventHandler, auditTrailInformation); - this.urlForFile = urlForFile; + this.urlForFile = urlForFile; this.fileSize = new BigInteger(Long.toString(fileSize)); this.checksumForValidationAtPillar = checksumForValidationAtPillar; this.checksumRequestsForValidation = checksumRequestsForValidation; @@ -53,23 +54,17 @@ public PutFileConversationContext(String collectionID, String fileID, URL urlFor public URL getUrlForFile() { return urlForFile; } - + public BigInteger getFileSize() { return fileSize; } - + public ChecksumDataForFileTYPE getChecksumForValidationAtPillar() { return checksumForValidationAtPillar; } - + public ChecksumSpecTYPE getChecksumRequestForValidation() { return checksumRequestsForValidation; } - /** The checksum for the file being put. Used to verify the file on the pillar when downloaded. - * @return The checksum request for validation - */ - public ChecksumSpecTYPE getChecksumRequestsForValidation() { - return checksumRequestsForValidation; - } } diff --git a/bitrepository-client/src/main/java/org/bitrepository/modify/putfile/conversation/PuttingFile.java b/bitrepository-client/src/main/java/org/bitrepository/modify/putfile/conversation/PuttingFile.java index d166a20d2..80c8742c2 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/modify/putfile/conversation/PuttingFile.java +++ b/bitrepository-client/src/main/java/org/bitrepository/modify/putfile/conversation/PuttingFile.java @@ -48,8 +48,8 @@ public class PuttingFile extends PerformingOperationState { private final PutFileConversationContext context; private final Map componentRequestCount = new HashMap<>(); - /* - * @param context The conversation context. + /** + * @param context The conversation context. * @param contributors The list of components the fileIDs should be collected from. */ public PuttingFile(PutFileConversationContext context, Collection contributors) { diff --git a/bitrepository-client/src/main/java/org/bitrepository/modify/replacefile/BlockingReplaceFileClient.java b/bitrepository-client/src/main/java/org/bitrepository/modify/replacefile/BlockingReplaceFileClient.java index 913ecfeed..7bd07d886 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/modify/replacefile/BlockingReplaceFileClient.java +++ b/bitrepository-client/src/main/java/org/bitrepository/modify/replacefile/BlockingReplaceFileClient.java @@ -1,32 +1,29 @@ /* * #%L * Bitmagasin modify client - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2010 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.modify.replacefile; -import java.net.URL; -import java.util.List; - import org.bitrepository.bitrepositoryelements.ChecksumDataForFileTYPE; import org.bitrepository.bitrepositoryelements.ChecksumSpecTYPE; import org.bitrepository.client.eventhandler.BlockingEventHandler; @@ -35,8 +32,11 @@ import org.bitrepository.client.eventhandler.OperationEvent; import org.bitrepository.common.exceptions.OperationFailedException; +import java.net.URL; +import java.util.List; + /** - * Wrappes a ReplaceFileClient to provide a blocking client. The client will block until the ReplaceFileOperation + * Wraps a ReplaceFileClient to provide a blocking client. The client will block until the ReplaceFileOperation * has finished. */ public class BlockingReplaceFileClient { @@ -45,30 +45,32 @@ public class BlockingReplaceFileClient { public BlockingReplaceFileClient(ReplaceFileClient client) { this.client = client; } + /** * Method for performing a blocking replace file operation. Wraps the asynchronous * {@link org.bitrepository.modify.replacefile.ReplaceFileClient#replaceFile * (String, String, String, ChecksumDataForFileTYPE, ChecksumSpecTYPE, URL, long, ChecksumDataForFileTYPE, * ChecksumSpecTYPE, EventHandler, String)} method. - * @param collectionID The ID of the collection - * @param fileID The ID of the file - * @param pillarID The ID of the pillar - * @param checksumForDeleteAtPillar The checksum data for pillar side verification of the existing file - * @param checksumRequestedForDeletedFile The checksum request for the existing file - * @param url The url of where to find the replacement file - * @param sizeOfNewFile The size of the new file [OPTIONAL] + * + * @param collectionID The ID of the collection + * @param fileID The ID of the file + * @param pillarID The ID of the pillar + * @param checksumForDeleteAtPillar The checksum data for pillar side verification of the existing file + * @param checksumRequestedForDeletedFile The checksum request for the existing file + * @param url The url of where to find the replacement file + * @param sizeOfNewFile The size of the new file [OPTIONAL] * @param checksumForNewFileValidationAtPillar The checksum data for pillar side verification of the new file - * @param checksumRequestsForNewFile The checksum request for the new file - * @param eventHandler The {@link EventHandler} to handle incoming events - * @param auditTrailInformation The audit trail information for the pillar + * @param checksumRequestsForNewFile The checksum request for the new file + * @param eventHandler The {@link EventHandler} to handle incoming events + * @param auditTrailInformation The audit trail information for the pillar * @return The list of received {@link ContributorEvent}'s * @throws OperationFailedException The operation didn't complete successfully. */ public List replaceFile( String collectionID, String fileID, String pillarID, ChecksumDataForFileTYPE checksumForDeleteAtPillar, - ChecksumSpecTYPE checksumRequestedForDeletedFile, URL url, long sizeOfNewFile, - ChecksumDataForFileTYPE checksumForNewFileValidationAtPillar, ChecksumSpecTYPE checksumRequestsForNewFile, - EventHandler eventHandler, String auditTrailInformation) + ChecksumSpecTYPE checksumRequestedForDeletedFile, URL url, long sizeOfNewFile, + ChecksumDataForFileTYPE checksumForNewFileValidationAtPillar, ChecksumSpecTYPE checksumRequestsForNewFile, + EventHandler eventHandler, String auditTrailInformation) throws OperationFailedException { BlockingEventHandler blocker = new BlockingEventHandler(eventHandler); client.replaceFile(collectionID, fileID, pillarID, checksumForDeleteAtPillar, @@ -76,7 +78,7 @@ public List replaceFile( checksumRequestsForNewFile, blocker, auditTrailInformation); OperationEvent finishEvent = blocker.awaitFinished(); - if(finishEvent.getEventType() == OperationEvent.OperationEventType.COMPLETE) { + if (finishEvent.getEventType() == OperationEvent.OperationEventType.COMPLETE) { return blocker.getResults(); } else if (finishEvent.getEventType() == OperationEvent.OperationEventType.FAILED) { throw new OperationFailedException(finishEvent.getInfo()); diff --git a/bitrepository-client/src/main/java/org/bitrepository/modify/replacefile/ConversationBasedReplaceFileClient.java b/bitrepository-client/src/main/java/org/bitrepository/modify/replacefile/ConversationBasedReplaceFileClient.java index 2b5678c4e..c70f02630 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/modify/replacefile/ConversationBasedReplaceFileClient.java +++ b/bitrepository-client/src/main/java/org/bitrepository/modify/replacefile/ConversationBasedReplaceFileClient.java @@ -1,31 +1,30 @@ /* * #%L * Bitrepository Modifying Client - * + * * $Id: ConversationBasedDeleteFileClient.java 639 2011-12-15 10:24:45Z jolf $ - * $HeadURL: https://sbforge.org/svn/bitrepository/bitrepository-reference/trunk/bitrepository-modifying-client/src/main/java/org/bitrepository/modify/deletefile/ConversationBasedDeleteFileClient.java $ + * $HeadURL: https://sbforge.org/svn/bitrepository/bitrepository-reference/trunk/bitrepository-modifying-client/src/main/java/org + * /bitrepository/modify/deletefile/ConversationBasedDeleteFileClient.java $ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.modify.replacefile; -import java.net.URL; -import java.util.Arrays; import org.bitrepository.bitrepositoryelements.ChecksumDataForFileTYPE; import org.bitrepository.bitrepositoryelements.ChecksumSpecTYPE; import org.bitrepository.client.AbstractClient; @@ -40,6 +39,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.net.URL; +import java.util.List; + /** * A conversation based implementation of the ReplaceFileClient. */ @@ -47,49 +49,49 @@ public class ConversationBasedReplaceFileClient extends AbstractClient implement private final Logger log = LoggerFactory.getLogger(this.getClass()); /** - * @see AbstractClient - * @param messageBus The {@link MessageBus} used for communication + * @param messageBus The {@link MessageBus} used for communication * @param conversationMediator The {@link ConversationMediator} for keeping track of conversations - * @param settings The {@link Settings} for the client - * @param clientID The ID of the client + * @param settings The {@link Settings} for the client + * @param clientID The ID of the client + * @see AbstractClient */ - public ConversationBasedReplaceFileClient(MessageBus messageBus, ConversationMediator conversationMediator, - Settings settings, String clientID) { + public ConversationBasedReplaceFileClient(MessageBus messageBus, ConversationMediator conversationMediator, + Settings settings, String clientID) { super(settings, conversationMediator, messageBus, clientID); } - + @Override public void replaceFile(String collectionID, String fileID, String pillarID, ChecksumDataForFileTYPE checksumForDeleteAtPillar, - ChecksumSpecTYPE checksumRequestedForDeletedFile, URL url, long sizeOfNewFile, - ChecksumDataForFileTYPE checksumForNewFileValidationAtPillar, ChecksumSpecTYPE checksumRequestsForNewFile, - EventHandler eventHandler, String auditTrailInformation) { + ChecksumSpecTYPE checksumRequestedForDeletedFile, URL url, long sizeOfNewFile, + ChecksumDataForFileTYPE checksumForNewFileValidationAtPillar, ChecksumSpecTYPE checksumRequestsForNewFile, + EventHandler eventHandler, String auditTrailInformation) { ArgumentValidator.checkNotNullOrEmpty(collectionID, "collectionID"); ArgumentValidator.checkNotNullOrEmpty(fileID, "fileID"); validateFileID(fileID); ArgumentValidator.checkNotNullOrEmpty(fileID, "String fileID"); ArgumentValidator.checkNotNullOrEmpty(pillarID, "String pillarID"); - if(settings.getRepositorySettings().getProtocolSettings().isRequireChecksumForDestructiveRequests()) { + if (settings.getRepositorySettings().getProtocolSettings().isRequireChecksumForDestructiveRequests()) { ArgumentValidator.checkNotNull(checksumForDeleteAtPillar, "ChecksumDataForFileTYPE checksumForDeleteAtPillar"); MessageDataTypeValidator.validate(checksumForDeleteAtPillar, "checksumForDeleteAtPillar"); } - if(settings.getRepositorySettings().getProtocolSettings().isRequireChecksumForNewFileRequests()) { + if (settings.getRepositorySettings().getProtocolSettings().isRequireChecksumForNewFileRequests()) { ArgumentValidator.checkNotNull(checksumForNewFileValidationAtPillar, "ChecksumDataForFileTYPE checksumForNewFileValidationAtPillar"); MessageDataTypeValidator.validate(checksumForNewFileValidationAtPillar, "checksumForNewFileValidationAtPillar"); } MessageDataTypeValidator.validate(checksumRequestedForDeletedFile, "checksumRequestedForDeletedFile"); MessageDataTypeValidator.validate(checksumRequestsForNewFile, "checksumRequestsForNewFile"); - + log.info("Requesting the replacement of the file '" + fileID + "' at the pillar '" + pillarID + "' from the " - + "URL '" + url + "' and with the size '" + sizeOfNewFile + "', where the old file has the checksum '" - + checksumForDeleteAtPillar + "' and is requested the checksum '" + checksumRequestedForDeletedFile + + "URL '" + url + "' and with the size '" + sizeOfNewFile + "', where the old file has the checksum '" + + checksumForDeleteAtPillar + "' and is requested the checksum '" + checksumRequestedForDeletedFile + "', and the new file has the checksum '" + checksumForNewFileValidationAtPillar + "' and requesting " - + "the checksum '" + checksumRequestsForNewFile + "'. With the audittrail '" + auditTrailInformation + + "the checksum '" + checksumRequestsForNewFile + "'. With the auditTrail '" + auditTrailInformation + "'"); ReplaceFileConversationContext context = new ReplaceFileConversationContext(collectionID, fileID, - sizeOfNewFile, url, checksumForDeleteAtPillar, checksumRequestedForDeletedFile, - checksumForNewFileValidationAtPillar, checksumRequestsForNewFile, settings, messageBus, - clientID, Arrays.asList(pillarID), eventHandler, auditTrailInformation); + sizeOfNewFile, url, checksumForDeleteAtPillar, checksumRequestedForDeletedFile, + checksumForNewFileValidationAtPillar, checksumRequestsForNewFile, settings, messageBus, + clientID, List.of(pillarID), eventHandler, auditTrailInformation); startConversation(context, new IdentifyPillarsForReplaceFile(context)); } } diff --git a/bitrepository-client/src/main/java/org/bitrepository/modify/replacefile/ReplaceFileClient.java b/bitrepository-client/src/main/java/org/bitrepository/modify/replacefile/ReplaceFileClient.java index afc933470..71ccb7771 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/modify/replacefile/ReplaceFileClient.java +++ b/bitrepository-client/src/main/java/org/bitrepository/modify/replacefile/ReplaceFileClient.java @@ -1,66 +1,69 @@ /* * #%L * Bitmagasin modify client - * + * * $Id: DeleteFileClient.java 631 2011-12-13 17:56:54Z jolf $ - * $HeadURL: https://sbforge.org/svn/bitrepository/bitrepository-reference/trunk/bitrepository-modifying-client/src/main/java/org/bitrepository/modify/deletefile/DeleteFileClient.java $ + * $HeadURL: https://sbforge.org/svn/bitrepository/bitrepository-reference/trunk/bitrepository-modifying-client/src/main/java/org + * /bitrepository/modify/deletefile/DeleteFileClient.java $ * %% * Copyright (C) 2010 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.modify.replacefile; -import java.net.URL; - import org.bitrepository.bitrepositoryelements.ChecksumDataForFileTYPE; import org.bitrepository.bitrepositoryelements.ChecksumSpecTYPE; -import org.bitrepository.client.BitrepositoryClient; +import org.bitrepository.client.BitRepositoryClient; import org.bitrepository.client.eventhandler.EventHandler; +import java.net.URL; + /** * Interface for the delete client. */ -public interface ReplaceFileClient extends BitrepositoryClient { +public interface ReplaceFileClient extends BitRepositoryClient { /** * Starts the conversation for replacing a file on a given pillar. * It is similar to performing the DeleteFile followed by the PutFile operations. * Since both of these takes two checksum arguments each, then this takes four! - * @param collectionID The collection to replace the file in. - * @param fileID The id of the file to replace. - * @param pillarID The id of the pillar, where the file should be replaced. - * @param checksumForDeleteAtPillar The checksum of the file on the pillar which should be replaced. Used for - * validating at pillar-side. - * @param checksumRequestedForDeletedFile [OPTIONAL] Request for calculation of the checksum of the file which - * should be replaced at the pillar. Used for client-side validation. - * @param url The URL of the new file to replaced the old one. - * @param sizeOfNewFile The size of the new file. - * @param checksumForNewFileValidationAtPillar [OPTIONAL] The checksum of the new file. Used for pillar-side - * validation. - * @param checksumRequestsForNewFile [OPTIONAL] Request for a checksum calculation of the new file. Used for - * client-side validation. - * @param eventHandler [OPTIONAL] The handler which should receive notifications of the events occurring in - * connection with the pillar communication. This is allowed to be null. - * In a good case scenario this will give the events:

    - * IdentifyPillarsRequestSent, PillarIdentified, PillarSelected, RequestSent, Progress, PillarComplete, Complete - * @param auditTrailInformation The audit information for the given operation. E.g. who is behind the operation - * call. + * + * @param collectionID The collection to replace the file in. + * @param fileID The id of the file to replace. + * @param pillarID The id of the pillar, where the file should be replaced. + * @param checksumForDeleteAtPillar The checksum of the file on the pillar which should be replaced. Used for + * validating at pillar-side. + * @param checksumRequestedForDeletedFile [OPTIONAL] Request for calculation of the checksum of the file which + * should be replaced at the pillar. Used for client-side validation. + * @param url The URL of the new file to replace the old one. + * @param sizeOfNewFile The size of the new file. + * @param checksumForNewFileValidationAtPillar [OPTIONAL] The checksum of the new file. Used for pillar-side + * validation. + * @param checksumRequestsForNewFile [OPTIONAL] Request for a checksum calculation of the new file. Used for + * client-side validation. + * @param eventHandler [OPTIONAL] The handler which should receive notifications of the events occurring in + * connection with the pillar communication. This is allowed to be null. + * In a good case scenario this will give the events:

    + * IdentifyPillarsRequestSent, PillarIdentified, PillarSelected, RequestSent, Progress, + * PillarComplete, Complete + * @param auditTrailInformation The audit information for the given operation. E.g. who is behind the operation + * call. */ void replaceFile(String collectionID, String fileID, String pillarID, ChecksumDataForFileTYPE checksumForDeleteAtPillar, - ChecksumSpecTYPE checksumRequestedForDeletedFile, URL url, long sizeOfNewFile, - ChecksumDataForFileTYPE checksumForNewFileValidationAtPillar, ChecksumSpecTYPE checksumRequestsForNewFile, - EventHandler eventHandler, String auditTrailInformation); + ChecksumSpecTYPE checksumRequestedForDeletedFile, URL url, long sizeOfNewFile, + ChecksumDataForFileTYPE checksumForNewFileValidationAtPillar, ChecksumSpecTYPE checksumRequestsForNewFile, + EventHandler eventHandler, String auditTrailInformation); } diff --git a/bitrepository-client/src/main/java/org/bitrepository/modify/replacefile/conversation/IdentifyPillarsForReplaceFile.java b/bitrepository-client/src/main/java/org/bitrepository/modify/replacefile/conversation/IdentifyPillarsForReplaceFile.java index f1a2daab4..0cc160cf1 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/modify/replacefile/conversation/IdentifyPillarsForReplaceFile.java +++ b/bitrepository-client/src/main/java/org/bitrepository/modify/replacefile/conversation/IdentifyPillarsForReplaceFile.java @@ -1,23 +1,24 @@ /* * #%L * Bitrepository Access - * + * * $Id: IdentifyPillarsForDeleteFile.java 639 2011-12-15 10:24:45Z jolf $ - * $HeadURL: https://sbforge.org/svn/bitrepository/bitrepository-reference/trunk/bitrepository-modifying-client/src/main/java/org/bitrepository/modify/deletefile/conversation/IdentifyPillarsForDeleteFile.java $ + * $HeadURL: https://sbforge.org/svn/bitrepository/bitrepository-reference/trunk/bitrepository-modifying-client/src/main/java/org + * /bitrepository/modify/deletefile/conversation/IdentifyPillarsForDeleteFile.java $ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -49,8 +50,8 @@ public IdentifyPillarsForReplaceFile(ReplaceFileConversationContext context) { /** * Extends the default behaviour with a idempotent aspects. This assumes that the replace on a pillar is successful if - * if new file is the one already present on the pillar. - * + * new file is the one already present on the pillar. + *

    * Any other none-positive response is handled as a fatal problem. */ @Override diff --git a/bitrepository-client/src/main/java/org/bitrepository/modify/replacefile/conversation/ReplaceFileCompletePillarEvent.java b/bitrepository-client/src/main/java/org/bitrepository/modify/replacefile/conversation/ReplaceFileCompletePillarEvent.java index ca54a74ca..8e432942a 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/modify/replacefile/conversation/ReplaceFileCompletePillarEvent.java +++ b/bitrepository-client/src/main/java/org/bitrepository/modify/replacefile/conversation/ReplaceFileCompletePillarEvent.java @@ -1,23 +1,24 @@ /* * #%L * Bitrepository Access - * + * * $Id: ChecksumsCompletePillarEvent.java 548 2011-11-21 16:43:43Z jolf $ - * $HeadURL: https://sbforge.org/svn/bitrepository/bitrepository-reference/trunk/bitrepository-access-client/src/main/java/org/bitrepository/access/getchecksums/conversation/ChecksumsCompletePillarEvent.java $ + * $HeadURL: https://sbforge.org/svn/bitrepository/bitrepository-reference/trunk/bitrepository-access-client/src/main/java/org + * /bitrepository/access/getchecksums/conversation/ChecksumsCompletePillarEvent.java $ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -28,19 +29,17 @@ import org.bitrepository.client.eventhandler.ContributorCompleteEvent; /** -* Contains the result of a ReplaceFile request sent to a single pillar. -*/ + * Contains the result of a ReplaceFile request sent to a single pillar. + */ public class ReplaceFileCompletePillarEvent extends ContributorCompleteEvent { - /** @see #getChecksumForDeletedFile(). */ private final ChecksumDataForFileTYPE replacedFileChecksum; - /** @see #getChecksumForNewFile(). */ private final ChecksumDataForFileTYPE newFileChecksum; - + /** - * @param pillarID The pillar which generated the result + * @param pillarID The pillar which generated the result * @param collectionID The ID of the collection - * @param deletedFile The results of the checksum request for the deleted file from the pillar. - * @param newFile The results of the checksum request for the new file from the pillar. + * @param deletedFile The results of the checksum request for the deleted file from the pillar. + * @param newFile The results of the checksum request for the new file from the pillar. */ public ReplaceFileCompletePillarEvent( String pillarID, String collectionID, ChecksumDataForFileTYPE deletedFile, ChecksumDataForFileTYPE newFile) { @@ -49,21 +48,21 @@ public ReplaceFileCompletePillarEvent( this.replacedFileChecksum = deletedFile; } - /** - * @return The checksum result for the deleted file from a single pillar. + /** + * @return The checksum result for the deleted file from a single pillar. */ public ChecksumDataForFileTYPE getChecksumForReplacedFile() { return replacedFileChecksum; } - - /** - * @return The checksum result for the new file from a single pillar. + + /** + * @return The checksum result for the new file from a single pillar. */ public ChecksumDataForFileTYPE getChecksumForNewFile() { return newFileChecksum; } - - @Override + + @Override public String additionalInfo() { return super.additionalInfo() + ", checksum for new file: '" + newFileChecksum + "'," + "checksum for replaced file: '" + replacedFileChecksum + "' "; diff --git a/bitrepository-client/src/main/java/org/bitrepository/modify/replacefile/conversation/ReplaceFileConversationContext.java b/bitrepository-client/src/main/java/org/bitrepository/modify/replacefile/conversation/ReplaceFileConversationContext.java index 0a3998843..5d53b170f 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/modify/replacefile/conversation/ReplaceFileConversationContext.java +++ b/bitrepository-client/src/main/java/org/bitrepository/modify/replacefile/conversation/ReplaceFileConversationContext.java @@ -5,25 +5,22 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.modify.replacefile.conversation; -import java.math.BigInteger; -import java.net.URL; -import java.util.Collection; import org.bitrepository.bitrepositoryelements.ChecksumDataForFileTYPE; import org.bitrepository.bitrepositoryelements.ChecksumSpecTYPE; import org.bitrepository.client.conversation.ConversationContext; @@ -32,19 +29,25 @@ import org.bitrepository.protocol.OperationType; import org.bitrepository.protocol.messagebus.MessageSender; +import java.math.BigInteger; +import java.net.URL; +import java.util.Collection; + public class ReplaceFileConversationContext extends ConversationContext { private final BigInteger sizeOfNewFile; private final URL urlForFile; private final ChecksumDataForFileTYPE checksumForNewFileValidationAtPillar; private final ChecksumSpecTYPE checksumRequestsForNewFile; - private final ChecksumDataForFileTYPE checksumForDeleteAtPillar; + private final ChecksumDataForFileTYPE checksumForDeleteAtPillar; private final ChecksumSpecTYPE checksumRequestedForDeletedFile; - + public ReplaceFileConversationContext(String collectionID, String fileID, long sizeOfNewFile, URL urlForFile, - ChecksumDataForFileTYPE checksumForDeleteAtPillar, ChecksumSpecTYPE checksumRequestedForDeletedFile, - ChecksumDataForFileTYPE checksumForNewFileValidationAtPillar, ChecksumSpecTYPE checksumRequestsForNewFile, - Settings settings, MessageSender messageSender, String clientID, Collection contributors, - EventHandler eventHandler,String auditTrailInformation) { + ChecksumDataForFileTYPE checksumForDeleteAtPillar, + ChecksumSpecTYPE checksumRequestedForDeletedFile, + ChecksumDataForFileTYPE checksumForNewFileValidationAtPillar, + ChecksumSpecTYPE checksumRequestsForNewFile, + Settings settings, MessageSender messageSender, String clientID, Collection contributors, + EventHandler eventHandler, String auditTrailInformation) { super(collectionID, OperationType.REPLACE_FILE, settings, messageSender, clientID, fileID, contributors, eventHandler, auditTrailInformation); this.urlForFile = urlForFile; @@ -58,23 +61,23 @@ public ReplaceFileConversationContext(String collectionID, String fileID, long s public ChecksumDataForFileTYPE getChecksumForNewFileValidationAtPillar() { return checksumForNewFileValidationAtPillar; } - + public ChecksumSpecTYPE getChecksumRequestsForNewFile() { return checksumRequestsForNewFile; } - + public ChecksumDataForFileTYPE getChecksumForDeleteAtPillar() { return checksumForDeleteAtPillar; } - + public ChecksumSpecTYPE getChecksumRequestedForDeletedFile() { return checksumRequestedForDeletedFile; } - + public BigInteger getSizeOfNewFile() { return sizeOfNewFile; } - + public URL getUrlForFile() { return urlForFile; } diff --git a/bitrepository-client/src/main/java/org/bitrepository/modify/replacefile/conversation/ReplacingFile.java b/bitrepository-client/src/main/java/org/bitrepository/modify/replacefile/conversation/ReplacingFile.java index 5ba6b26db..026cebb77 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/modify/replacefile/conversation/ReplacingFile.java +++ b/bitrepository-client/src/main/java/org/bitrepository/modify/replacefile/conversation/ReplacingFile.java @@ -1,30 +1,30 @@ /* * #%L * Bitrepository Modifying Client - * + * * $Id: DeletingFile.java 631 2011-12-13 17:56:54Z jolf $ - * $HeadURL: https://sbforge.org/svn/bitrepository/bitrepository-reference/trunk/bitrepository-modifying-client/src/main/java/org/bitrepository/modify/deletefile/conversation/DeletingFile.java $ + * $HeadURL: https://sbforge.org/svn/bitrepository/bitrepository-reference/trunk/bitrepository-modifying-client/src/main/java/org + * /bitrepository/modify/deletefile/conversation/DeletingFile.java $ * %% * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ package org.bitrepository.modify.replacefile.conversation; -import java.util.Collection; import org.bitrepository.bitrepositorymessages.MessageResponse; import org.bitrepository.bitrepositorymessages.ReplaceFileFinalResponse; import org.bitrepository.bitrepositorymessages.ReplaceFileRequest; @@ -34,19 +34,21 @@ import org.bitrepository.client.exceptions.UnexpectedResponseException; import org.bitrepository.common.utils.ChecksumUtils; +import java.util.Collection; + /** * Models the behavior of a ReplaceFile conversation during the operation phase. That is, it begins with the sending of - * ReplaceFileRequest messages and finishes with the reception of the - * ReplaceFileFinalResponse messages from all responding pillars. - * - * Note that this is only used by the ReplaceFileConversation in the same package, therefore the visibility is package + * ReplaceFileRequest messages and finishes with the reception of the + * ReplaceFileFinalResponse messages from all responding pillars. + *

    + * Note that this is only used by the ReplaceFileConversation in the same package, therefore the visibility is package * protected. */ public class ReplacingFile extends PerformingOperationState { private final ReplaceFileConversationContext context; - /* - * @param context The conversation context. + /** + * @param context The conversation context. * @param contributors The list of components the fileIDs should be collected from. */ public ReplacingFile(ReplaceFileConversationContext context, Collection contributors) { @@ -62,13 +64,13 @@ protected void generateContributorCompleteEvent(MessageResponse msg) throws Unex response.getCollectionID(), response.getChecksumDataForExistingFile(), response.getChecksumDataForNewFile() - )); + )); } @Override protected void sendRequest() { context.getMonitor().requestSent("Sending request for replace file", activeContributors.keySet().toString()); - for(String pillar : activeContributors.keySet()) { + for (String pillar : activeContributors.keySet()) { ReplaceFileRequest msg = createRequest(pillar); if (context.getChecksumRequestsForNewFile() != null) { if (!context.isChecksumPillar(pillar) || diff --git a/bitrepository-client/src/test/java/org/bitrepository/access/getfile/GetFileClientComponentTest.java b/bitrepository-client/src/test/java/org/bitrepository/access/getfile/GetFileClientComponentTest.java index 01bcb77a3..6cac88eb7 100644 --- a/bitrepository-client/src/test/java/org/bitrepository/access/getfile/GetFileClientComponentTest.java +++ b/bitrepository-client/src/test/java/org/bitrepository/access/getfile/GetFileClientComponentTest.java @@ -57,7 +57,7 @@ public class GetFileClientComponentTest extends AbstractGetFileClientTest { private static FilePart NO_FILE_PART = null; @Test(groups = {"regressiontest"}) - public void verifyGetFileClientFromFactory() throws Exception { + public void verifyGetFileClientFromFactory() { Assert.assertTrue(AccessComponentFactory.getInstance().createGetFileClient( settingsForCUT, securityManager, settingsForTestClient.getComponentID()) instanceof ConversationBasedGetFileClient, diff --git a/bitrepository-client/src/test/java/org/bitrepository/client/exception/NegativeResponseExceptionTest.java b/bitrepository-client/src/test/java/org/bitrepository/client/exception/NegativeResponseExceptionTest.java index 8c05b008d..b99f6ec45 100644 --- a/bitrepository-client/src/test/java/org/bitrepository/client/exception/NegativeResponseExceptionTest.java +++ b/bitrepository-client/src/test/java/org/bitrepository/client/exception/NegativeResponseExceptionTest.java @@ -5,16 +5,16 @@ * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. - * + * * 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% @@ -28,22 +28,22 @@ import org.testng.annotations.Test; public class NegativeResponseExceptionTest extends ExtendedTestCase { - - @Test(groups = { "regressiontest" }) - public void testNegativeResponse() throws Exception { + + @Test(groups = {"regressiontest"}) + public void testNegativeResponse() { addDescription("Test the instantiation of the exception"); addStep("Setup", ""); String errMsg = "TEST-EXCEPTION"; ResponseCode responseCode = ResponseCode.FAILURE; - - addStep("Try to throw such an exception with the response code", + + addStep("Try to throw such an exception with the response code", "Should be able to be caught and validated"); try { throw new NegativeResponseException(errMsg, responseCode); - } catch(Exception e) { + } catch (Exception e) { Assert.assertTrue(e instanceof NegativeResponseException); Assert.assertEquals(e.getMessage(), errMsg); - Assert.assertEquals(((NegativeResponseException) e).getErrorcode(), responseCode); + Assert.assertEquals(((NegativeResponseException) e).getErrorCode(), responseCode); Assert.assertNull(e.getCause()); } } From 418826e4ffcb6fa7a8a87ee132effcbcccb49399 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20S=C3=B8by?= Date: Mon, 21 Mar 2022 15:23:17 +0100 Subject: [PATCH 04/18] Small typo fix. --- .../src/main/webapp/WEB-INF/web.xml | 6 +++--- bitrepository-webclient/src/main/webapp/WEB-INF/web.xml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bitrepository-integrity-service/src/main/webapp/WEB-INF/web.xml b/bitrepository-integrity-service/src/main/webapp/WEB-INF/web.xml index 03c15bcc8..4a1a630bf 100644 --- a/bitrepository-integrity-service/src/main/webapp/WEB-INF/web.xml +++ b/bitrepository-integrity-service/src/main/webapp/WEB-INF/web.xml @@ -1,7 +1,7 @@ + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> Bitrepository integrityservice Bitrepository-integrityservice @@ -33,7 +33,7 @@ javax.ws.rs.Application org.bitrepository.integrityservice.web.IntegrityServiceRestApplication - 1 + 1 Bitrepository-integrityservice diff --git a/bitrepository-webclient/src/main/webapp/WEB-INF/web.xml b/bitrepository-webclient/src/main/webapp/WEB-INF/web.xml index 8b9ad243f..3954fafe6 100644 --- a/bitrepository-webclient/src/main/webapp/WEB-INF/web.xml +++ b/bitrepository-webclient/src/main/webapp/WEB-INF/web.xml @@ -1,7 +1,7 @@