Created
October 21, 2014 13:30
-
-
Save anonymous/469be08cc2610e727517 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2013 JBoss Inc | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
package com.dmgmori.overlord.srampAdapter; | |
import java.io.OutputStream; | |
import java.util.HashMap; | |
import java.util.Map; | |
import javax.servlet.http.HttpServletRequest; | |
import javax.ws.rs.PUT; | |
import javax.ws.rs.Path; | |
import javax.ws.rs.PathParam; | |
import javax.ws.rs.Produces; | |
import javax.ws.rs.core.Context; | |
import org.apache.commons.io.IOUtils; | |
import org.oasis_open.docs.s_ramp.ns.s_ramp_v1.BaseArtifactType; | |
import org.oasis_open.docs.s_ramp.ns.s_ramp_v1.Property; | |
import org.overlord.sramp.atom.err.SrampAtomException; | |
import org.overlord.sramp.client.SrampAtomApiClient; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
/*import org.overlord.sramp.governance.SrampAtomApiClientFactory;*/ | |
/*import org.overlord.sramp.client.SrampAtomApiClient;*/ | |
/** | |
* The JAX-RS resource that handles deployment specific tasks. | |
* | |
* | |
*/ | |
@Path("/update") | |
public class UpdateMetaDataResource { | |
private static Logger logger = LoggerFactory.getLogger(UpdateMetaDataResource.class); | |
private static final String ENDPOINT = "http://localhost:8080/s-ramp-server"; | |
private static final String USERNAME = "admin"; | |
private static final String PASSWORD = "password."; | |
/** Constructor. | |
*/ | |
public UpdateMetaDataResource() { | |
} | |
/** | |
* Governance PUT add a classification. | |
* @param uuid | |
* @param classification value | |
* @throws SrampAtomException | |
*/ | |
@PUT | |
@Path("property/{key}/{value}/{uuid}") | |
@Produces("application/xml") | |
public Map<String,ValueEntity> updateProperty(@Context HttpServletRequest request, | |
@PathParam("key") String key, | |
@PathParam("value") String value, | |
@PathParam("uuid") String uuid) throws Exception { | |
Map<String,ValueEntity> results = new HashMap<String, ValueEntity>(); | |
OutputStream os = null; | |
try { | |
// 0. run the decoder on the argument | |
key = SlashDecoder.decode(key); | |
value = SlashDecoder.decode(value); | |
uuid = SlashDecoder.decode(uuid); | |
// 1. get the artifact from the repo | |
/*SrampAtomApiClient client = SrampAtomApiClientFactory.createAtomApiClient();*/ | |
SrampAtomApiClient client = new SrampAtomApiClient(ENDPOINT, USERNAME, PASSWORD, true); | |
BaseArtifactType artifact = client.getArtifactMetaData(uuid); | |
boolean newProp = true; | |
for(Property p:artifact.getProperty()){ | |
if(p.getPropertyName().equals(key)){ | |
p.setPropertyValue(value); | |
newProp = false; | |
} | |
} | |
if(newProp){ | |
Property p = new Property(); | |
p.setPropertyName(key); | |
p.setPropertyValue(value); | |
artifact.getProperty().add(p); | |
} | |
client.updateArtifactMetaData(artifact); | |
// 3. build the response | |
results.put("STATUS", new ValueEntity("success")); //$NON-NLS-1$ | |
results.put("ARTIFACT_NAME", new ValueEntity(artifact.getName())); | |
results.put("ARTIFACT_CREATED_BY", new ValueEntity(artifact.getCreatedBy())); | |
results.put("ARTIFACT_DESCRIPTION", new ValueEntity(artifact.getDescription())); | |
} catch (Exception e) { | |
logger.error("UpdateMetaDataResource.ErrorUpdating"+ e.getMessage(), e); //$NON-NLS-1$ | |
results.put("STATUS", new ValueEntity("fail")); //$NON-NLS-1$ | |
results.put("MESSAGE", new ValueEntity("UpdateMetaDataResource.ArtifactNotFound")); //$NON-NLS-1$ | |
} finally { | |
IOUtils.closeQuietly(os); | |
} | |
return results; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment