| .. | .. |
|---|
| 1 | 1 | package net.curisit.securis.services; |
|---|
| 2 | 2 | |
|---|
| 3 | +import java.io.IOException; |
|---|
| 3 | 4 | import java.util.Date; |
|---|
| 4 | 5 | import java.util.List; |
|---|
| 5 | 6 | |
|---|
| .. | .. |
|---|
| 21 | 22 | import javax.ws.rs.core.Response; |
|---|
| 22 | 23 | import javax.ws.rs.core.Response.Status; |
|---|
| 23 | 24 | |
|---|
| 25 | +import net.curisit.integrity.commons.JsonUtils; |
|---|
| 24 | 26 | import net.curisit.integrity.commons.Utils; |
|---|
| 25 | 27 | import net.curisit.integrity.exception.CurisException; |
|---|
| 26 | 28 | import net.curisit.securis.DefaultExceptionHandler; |
|---|
| .. | .. |
|---|
| 31 | 33 | import net.curisit.securis.security.Securable; |
|---|
| 32 | 34 | import net.curisit.securis.utils.TokenHelper; |
|---|
| 33 | 35 | |
|---|
| 36 | +import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; |
|---|
| 34 | 37 | import org.slf4j.Logger; |
|---|
| 35 | 38 | import org.slf4j.LoggerFactory; |
|---|
| 36 | 39 | |
|---|
| .. | .. |
|---|
| 124 | 127 | { MediaType.APPLICATION_JSON }) |
|---|
| 125 | 128 | @Transactional |
|---|
| 126 | 129 | public Response create(License lic, @Context BasicSecurityContext bsc) { |
|---|
| 127 | | - log.info("Creating new organization"); |
|---|
| 130 | + log.info("Creating new license from create()"); |
|---|
| 128 | 131 | EntityManager em = emProvider.get(); |
|---|
| 129 | 132 | Pack pack = null; |
|---|
| 130 | 133 | if (lic.getPackId() != null) { |
|---|
| .. | .. |
|---|
| 143 | 146 | } |
|---|
| 144 | 147 | |
|---|
| 145 | 148 | try { |
|---|
| 146 | | - User createdBy = getUser(lic.getCreatedById(), em); |
|---|
| 149 | + User createdBy = getUser(bsc.getUserPrincipal().getName(), em); |
|---|
| 147 | 150 | lic.setCreatedBy(createdBy); |
|---|
| 148 | 151 | } catch (CurisException ex) { |
|---|
| 149 | 152 | String createdByUsername = lic.getCreatedById(); |
|---|
| .. | .. |
|---|
| 161 | 164 | return Response.ok(lic).build(); |
|---|
| 162 | 165 | } |
|---|
| 163 | 166 | |
|---|
| 167 | + @POST |
|---|
| 168 | + @Path("/") |
|---|
| 169 | + @Consumes(MediaType.MULTIPART_FORM_DATA) |
|---|
| 170 | + @Securable |
|---|
| 171 | + @Produces( |
|---|
| 172 | + { MediaType.APPLICATION_JSON }) |
|---|
| 173 | + @Transactional |
|---|
| 174 | + public Response createWithFile(MultipartFormDataInput mpfdi, @Context BasicSecurityContext bsc) throws IOException { |
|---|
| 175 | + License lic = new License(); |
|---|
| 176 | + lic.setCode(mpfdi.getFormDataPart("code", String.class, null)); |
|---|
| 177 | + lic.setRequestData(mpfdi.getFormDataPart("request_data", String.class, null)); |
|---|
| 178 | + lic.setPackId(mpfdi.getFormDataPart("pack_id", Integer.class, null)); |
|---|
| 179 | + lic.setFullName(mpfdi.getFormDataPart("full_name", String.class, null)); |
|---|
| 180 | + lic.setEmail(mpfdi.getFormDataPart("email", String.class, null)); |
|---|
| 181 | + lic.setComments(mpfdi.getFormDataPart("comments", String.class, null)); |
|---|
| 182 | + try { |
|---|
| 183 | + log.info("File content: {}", lic.getRequestData()); |
|---|
| 184 | + log.info("License read from multipart: {}", JsonUtils.toJSON(lic)); |
|---|
| 185 | + } catch (CurisException e) { |
|---|
| 186 | + // TODO Auto-generated catch block |
|---|
| 187 | + e.printStackTrace(); |
|---|
| 188 | + } |
|---|
| 189 | + return create(lic, bsc); |
|---|
| 190 | + } |
|---|
| 191 | + |
|---|
| 164 | 192 | private User getUser(String username, EntityManager em) throws CurisException { |
|---|
| 165 | 193 | User user = null; |
|---|
| 166 | 194 | if (username != null) { |
|---|