|
| 1 | +package people |
| 2 | + |
| 3 | +import ( |
| 4 | + "encoding/json" |
| 5 | + "log" |
| 6 | + "net/http" |
| 7 | + "strings" |
| 8 | + |
| 9 | + "github.com/aborroy/alfresco-cli/cmd" |
| 10 | + "github.com/aborroy/alfresco-cli/httpclient" |
| 11 | + "github.com/spf13/cobra" |
| 12 | +) |
| 13 | + |
| 14 | +const CreatePeopleCmdId string = "[PEOPLE CREATE]" |
| 15 | + |
| 16 | +var password string |
| 17 | +var firstName string |
| 18 | +var lastName string |
| 19 | +var email string |
| 20 | +var properties []string |
| 21 | +var peopleCreateCmd = &cobra.Command{ |
| 22 | + Use: "create", |
| 23 | + Short: "Create new Person in ACS Repository", |
| 24 | + Long: `Creates a new person in the repository. |
| 25 | +The person can be created setting only required properties.`, |
| 26 | + Run: func(command *cobra.Command, args []string) { |
| 27 | + |
| 28 | + var personCreate PersonUpdate |
| 29 | + personCreate.ID = personId |
| 30 | + personCreate.Password = password |
| 31 | + personCreate.FirstName = firstName |
| 32 | + personCreate.LastName = lastName |
| 33 | + personCreate.Email = email |
| 34 | + personCreate.Enabled = true |
| 35 | + PopulatePersonUpdate(properties, &personCreate) |
| 36 | + jsonPersonCreate, _ := json.Marshal(personCreate) |
| 37 | + |
| 38 | + execution := &httpclient.HttpExecution{ |
| 39 | + Method: http.MethodPost, |
| 40 | + Data: string(jsonPersonCreate), |
| 41 | + Format: httpclient.Json, |
| 42 | + Url: strings.TrimSuffix(peopleUrlPath, "/"), |
| 43 | + ResponseBodyOutput: &responseBody, |
| 44 | + } |
| 45 | + |
| 46 | + _error := httpclient.Execute(execution) |
| 47 | + if _error != nil { |
| 48 | + cmd.ExitWithError(CreatePeopleCmdId, _error) |
| 49 | + } |
| 50 | + }, |
| 51 | + PostRun: func(command *cobra.Command, args []string) { |
| 52 | + log.Println(CreatePeopleCmdId, "Person "+personId+" has been created") |
| 53 | + }, |
| 54 | +} |
| 55 | + |
| 56 | +func init() { |
| 57 | + peopleCmd.AddCommand(peopleCreateCmd) |
| 58 | + peopleCreateCmd.Flags().StringVarP(&personId, "personId", "i", "", "Username of the user in Alfresco Repository.") |
| 59 | + peopleCreateCmd.Flags().StringVarP(&password, "password", "s", "", "Password of the user in Alfresco Repository.") |
| 60 | + peopleCreateCmd.Flags().StringVarP(&firstName, "firstName", "f", "", "First Name of the user in Alfresco Repository.") |
| 61 | + peopleCreateCmd.Flags().StringVarP(&lastName, "lastName", "l", "", "Last Name of the user in Alfresco Repository.") |
| 62 | + peopleCreateCmd.Flags().StringVarP(&email, "email", "e", "", "Email of the user in Alfresco Repository.") |
| 63 | + peopleCreateCmd.Flags().StringArrayVarP(&properties, "properties", "p", nil, |
| 64 | + "Property=Value list containing properties to be created. Property strings accepted: "+ |
| 65 | + "description, skypeID, googleID, instantMessageID, jobTitle, location, mobile, telephone, "+ |
| 66 | + "company.organization, company.address1, company.address2, company.address3, company.postcode, "+ |
| 67 | + "company.telephone, company.fax, company.email") |
| 68 | + peopleCreateCmd.Flags().SortFlags = false |
| 69 | + peopleCreateCmd.MarkFlagRequired("personId") |
| 70 | + peopleCreateCmd.MarkFlagRequired("password") |
| 71 | + peopleCreateCmd.MarkFlagRequired("firstName") |
| 72 | + peopleCreateCmd.MarkFlagRequired("lastName") |
| 73 | + peopleCreateCmd.MarkFlagRequired("email") |
| 74 | + |
| 75 | +} |
0 commit comments