Source:
public CollectionDataset updateDatasetInCollection(String collectionID, String datasetID, CollectionDataset updatedDataset) throws ZebedeeException, IOException, DatasetAPIException { Collection collection = zebedeeCms.getCollection(collectionID); CollectionDataset collectionDataset; Optional<CollectionDataset> existingDataset = collection.getDescription().getDataset(datasetID); if (existingDataset.isPresent()) { collectionDataset = existingDataset.get(); } else { collectionDataset = new CollectionDataset(); collectionDataset.setId(datasetID); } if (updatedDataset != null && updatedDataset.getState() != null) { collectionDataset.setState(updatedDataset.getState()); } Dataset dataset = datasetClient.getDataset(datasetID); if (dataset != null) { collectionDataset.setTitle(dataset.getTitle()); if (dataset.getLinks() != null && dataset.getLinks().getSelf() != null) { collectionDataset.setUri(dataset.getLinks().getSelf().getHref()); } else { logInfo("The dataset URL has not been set on the dataset response.") .addParameter("collectionID", collectionID) .addParameter("datasetID", datasetID) .log(); } if (State.CREATED.equals(dataset.getState())) { Dataset datasetUpdate = new Dataset(); datasetUpdate.setCollection_id(collectionID); datasetUpdate.setState(State.ASSOCIATED); datasetClient.updateDataset(datasetID, datasetUpdate); } if (dataset.getState().equals(State.ASSOCIATED) && !dataset.getCollection_id().equals(collectionID)) { throw new ConflictException("cannot add dataset " + datasetID + " to collection " + collectionID + " it is already in collection " + dataset.getCollection_id()); } collection.getDescription().addDataset(collectionDataset); collection.save(); } return collectionDataset; }

Target:
public CollectionDataset updateDatasetInCollection(String collectionID, String datasetID, CollectionDataset updatedDataset) throws ZebedeeException, IOException, DatasetAPIException { Collection collection = zebedeeCms.getCollection(collectionID); CollectionDataset collectionDataset; Optional<CollectionDataset> existingDataset = collection.getDescription().getDataset(datasetID); if (existingDataset.isPresent()) { collectionDataset = existingDataset.get(); } else { collectionDataset = new CollectionDataset(); collectionDataset.setId(datasetID); } if (updatedDataset != null && updatedDataset.getState() != null) { collectionDataset.setState(updatedDataset.getState()); } Dataset dataset = datasetClient.getDataset(datasetID); if (dataset != null) { collectionDataset.setTitle(dataset.getTitle()); if (dataset.getLinks() != null && dataset.getLinks().getSelf() != null) { collectionDataset.setUri(dataset.getLinks().getSelf().getHref()); } else { logInfo("The dataset URL has not been set on the dataset response.") .addParameter("collectionID", collectionID) .addParameter("datasetID", datasetID) .log(); throw new UnexpectedResponseException("The dataset URL has not been set on the dataset response."); } if (State.CREATED.equals(dataset.getState())) { Dataset datasetUpdate = new Dataset(); datasetUpdate.setCollection_id(collectionID); datasetUpdate.setState(State.ASSOCIATED); datasetClient.updateDataset(datasetID, datasetUpdate); } if (dataset.getState().equals(State.ASSOCIATED) && !dataset.getCollection_id().equals(collectionID)) { throw new ConflictException("cannot add dataset " + datasetID + " to collection " + collectionID + " it is already in collection " + dataset.getCollection_id()); } collection.getDescription().addDataset(collectionDataset); collection.save(); } return collectionDataset; }